<commit_before>import { expect } from "chai";
import { Frame, FrameArg, FrameArray, FrameExpr, FrameName, FrameString, FrameLazy } from "../../src/frames";

describe("FrameLazy", () => {
  const sloth = new FrameString("sloth");
  const turtle = new FrameString("turtle");
  const in_lazy = new FrameString("in_lazy");
  const lazy = new FrameLazy([sloth, FrameArg.here()], {in_lazy: in_lazy});
  const context = new FrameString("context", {nil: Frame.nil});
  const expr = lazy.in(context);

  it("takes an Array<Frame>", () => {
    expect(lazy).to.be.instanceof(FrameLazy);
  });

  it("stringifies to { expr, meta }", () => {
    const result = lazy.toString();
    expect(result).to.include(`{ ${sloth.toString()} _, `);
  });

  it("evalutes to an Expr", () => {
    const result = expr.toString();
    expect(expr).to.be.instanceof(FrameExpr);
    expect(result).to.equal(`(${sloth.toString()} _, `);
  });

  it("evalutes to an Expr", () => {
    expect(expr).to.be.instanceof(FrameExpr);
  });

  it("evaluates expr to inside self and context", () => {
    const evaluated = expr.call(turtle);
    expect(evaluated.get("in_lazy")).to.equal(in_lazy);
    expect(evaluated.get("nil")).to.equal(Frame.nil);
  });


  describe("Codify", () => {
    const codify = new FrameLazy([Frame.nil]);

    it("returns itself when Frame is nil", () => {
      expect(codify.in(Frame.nil)).to.equal(codify);
    });

    it("converts Array to Expr when called", () => {
      const array = new FrameArray([context, new FrameName("nil")]);
      expect(array.toString()).to.equal("[“context”, .nil]");

      const expr = codify.call(array);
      expect(expr.toString()).to.equal("{ “context” .nil }");
      expect(expr).to.be.instanceof(FrameExpr);
      expect(expr.at(0)).to.equal(context);
      expect(expr.in()).to.equal(Frame.nil);
    });

    it("wraps other Frames in Expr when called", () => {
      const wrap = codify.call(sloth);

      expect(wrap).to.be.instanceof(FrameExpr);
      expect(wrap.at(0)).to.equal(sloth);
      expect(wrap.in()).to.equal(sloth);
    });
  });
});<commit_msg>Spec lazy -> expr to have proper meta<commit_after>import { expect } from "chai";
import { Frame, FrameArg, FrameArray, FrameExpr, FrameName, FrameString, FrameSymbol, FrameLazy } from "../../src/frames";

describe("FrameLazy", () => {
  const slow = new FrameString("slow");
  const space = new FrameString(" ");
  const turtle = new FrameString("turtle");

  const lazy_array = [new FrameSymbol("speed"), new FrameSymbol("gap"), FrameArg.here()];

  const lazy = new FrameLazy(lazy_array, {speed: slow});
  const context = new FrameString("context", {gap: space});
  const expr = lazy.in(context);

  it("takes an Array<Frame>", () => {
    expect(lazy).to.be.instanceof(FrameLazy);
  });

  it("stringifies to { expr, meta }", () => {
    const result = lazy.toString();
    expect(result).to.include(`{ speed gap _, `);
  });

  it("evalutes to an Expr with merged context", () => {
    expect(expr).to.be.instanceof(FrameExpr);
    expect(expr.toString()).to.equal(`(speed gap _, .speed “slow”; .gap “ ”;`);
    expect(expr.get("speed")).to.equal(slow);
    expect(expr.get("gap")).to.equal(space);
  });

  describe("Codify", () => {
    const codify = new FrameLazy([Frame.nil]);

    it("returns itself when Frame is nil", () => {
      expect(codify.in(Frame.nil)).to.equal(codify);
    });

    it("converts Array to Expr when called", () => {
      const array = new FrameArray([context, new FrameName("nil")]);
      expect(array.toString()).to.equal("[“context”, .nil]");

      const expr = codify.call(array);
      expect(expr.toString()).to.equal("{ “context” .nil }");
      expect(expr).to.be.instanceof(FrameExpr);
      expect(expr.at(0)).to.equal(context);
      expect(expr.in()).to.equal(Frame.nil);
    });

    it("wraps other Frames in Expr when called", () => {
      const wrap = codify.call(turtle);

      expect(wrap).to.be.instanceof(FrameExpr);
      expect(wrap.at(0)).to.equal(turtle);
      expect(wrap.in()).to.equal(turtle);
    });
  });
});
{'fraction_non_alphanumeric': 0.20215633423180593, 'fraction_numerical': 0.00098015192354815, 'mean_word_length': 3.6598173515981736, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7564814', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1343, 'n_words': 263}