<commit_before>
describe "WWW_Applet.new" do

  it "accepts a string" do
    o = WWW_Applet.new "[]"
    o.code.should == "[]"
  end

  it "accepts an array" do
    code = ["a", []]
    o = WWW_Applet.new code
    o.code.should == MultiJson.dump(code)
  end

  it "raises WWW_Applet::Invalid if object is not an Array" do
    lambda {
      WWW_Applet.new({a:"a"})
    }.should.raise(WWW_Applet::Invalid).
    message.should.match /JS object must be an array/i
  end

end # === describe WWW_Applet.new ===

describe "'value ='" do

  it "evaluates value if array" do
    o = WWW_Applet.new [
      "my val", "value =", ["go forth", []]
    ]
    o.write_computer "go forth", lambda { |o,n,v| 4 }
    o.run
    o.value("my val").should == 4
  end

  it "saves value with uppercase." do
    o = WWW_Applet.new [
      "my val", "value =", [5]
    ]
    o.run
    o.value("MY VAL").should == 5
  end

  it "raise Too_Many_Values if more than one value is passed." do
    o = WWW_Applet.new [ "my val", "value =", [1,5] ]
    lambda { o.run }.should.raise(WWW_Applet::Too_Many_Values).
      message.should.match /.value =. \[1,\ ?5\]/i
  end

  it "raises Value_Already_Created if value already exists." do
    o = WWW_Applet.new [
      "my val", "value =", [1],
      "mY vAl", "value =", [2]
    ]
    lambda { o.run }.should.raise(WWW_Applet::Value_Already_Created).
      message.should.match /my val/i
  end

end # === describe

describe "'computer ='" do

  it "does not evaluate Array" do
    o = WWW_Applet.new [
      "my func", "computer =", [1,2,3, "a", []]
    ]
    o.run
    o.computers("my func").first.tokens.should == [1,2,3,"a",[]]
  end

  it "raises Value_Not_Found if the name of the value belongs to an outside scope value" do
    o = WWW_Applet.new [
      "my val", "value =", ["a"],
      "my comp", "computer =", [
        "console print", ["value", ["my val"]]
      ],
      "my comp", []
    ]
    lambda {
      o.run
    }.should.raise(WWW_Applet::Value_Not_Found).
    message.should.match /MY VAL/
  end

end # === describe value as is

describe "Computer run:" do

  it "raises Invalid if an Array has no preceding String" do
    c = WWW_Applet.new [
      "my comp", "computer =", [
        [], [], "console print", [2]
      ],
      "my comp", []
    ]
    lambda { c.run }.
      should.raise(WWW_Applet::Invalid).
      message.should.match /Computer name not specified/
  end

  it "runs a local function first." do
    o = WWW_Applet.new [
      "yo", "computer =", [ "console print", ["yo yo"] ],
      "my func", "computer =", [
         "yo", "computer =", [ "console print", ["hello"] ],
         "yo", []
      ]
    ]
    o.run
    o.console.should == ["hello"].inspect
  end

  it "runs an a function from parent computer, if not found locally" do<commit_msg>Typo.<commit_after>
describe "WWW_Applet.new" do

  it "accepts a string" do
    o = WWW_Applet.new "[]"
    o.code.should == "[]"
  end

  it "accepts an array" do
    code = ["a", []]
    o = WWW_Applet.new code
    o.code.should == MultiJson.dump(code)
  end

  it "raises WWW_Applet::Invalid if object is not an Array" do
    lambda {
      WWW_Applet.new({a:"a"})
    }.should.raise(WWW_Applet::Invalid).
    message.should.match /JS object must be an array/i
  end

end # === describe WWW_Applet.new ===

describe "'value ='" do

  it "evaluates value if array" do
    o = WWW_Applet.new [
      "my val", "value =", ["go forth", []]
    ]
    o.write_computer "go forth", lambda { |o,n,v| 4 }
    o.run
    o.value("my val").should == 4
  end

  it "saves value with uppercase." do
    o = WWW_Applet.new [
      "my val", "value =", [5]
    ]
    o.run
    o.value("MY VAL").should == 5
  end

  it "raise Too_Many_Values if more than one value is passed." do
    o = WWW_Applet.new [ "my val", "value =", [1,5] ]
    lambda { o.run }.should.raise(WWW_Applet::Too_Many_Values).
      message.should.match /.value =. \[1,\ ?5\]/i
  end

  it "raises Value_Already_Created if value already exists." do
    o = WWW_Applet.new [
      "my val", "value =", [1],
      "mY vAl", "value =", [2]
    ]
    lambda { o.run }.should.raise(WWW_Applet::Value_Already_Created).
      message.should.match /my val/i
  end

end # === describe

describe "'computer ='" do

  it "does not evaluate Array" do
    o = WWW_Applet.new [
      "my func", "computer =", [1,2,3, "a", []]
    ]
    o.run
    o.computers("my func").first.tokens.should == [1,2,3,"a",[]]
  end

  it "raises Value_Not_Found if the name of the value belongs to an outside scope value" do
    o = WWW_Applet.new [
      "my val", "value =", ["a"],
      "my comp", "computer =", [
        "console print", ["value", ["my val"]]
      ],
      "my comp", []
    ]
    lambda {
      o.run
    }.should.raise(WWW_Applet::Value_Not_Found).
    message.should.match /MY VAL/
  end

end # === describe value as is

describe "Computer run:" do

  it "raises Invalid if an Array has no preceding String" do
    c = WWW_Applet.new [
      "my comp", "computer =", [
        [], [], "console print", [2]
      ],
      "my comp", []
    ]
    lambda { c.run }.
      should.raise(WWW_Applet::Invalid).
      message.should.match /Computer name not specified/
  end

  it "runs a local function first." do
    o = WWW_Applet.new [
      "yo", "computer =", [ "console print", ["yo yo"] ],
      "my func", "computer =", [
         "yo", "computer =", [ "console print", ["hello"] ],
         "yo", []
      ],
      "my func", []
    ]
    o.run
    o.console.should == ["hello".inspect]
  end

  it "runs an a function from parent computer, if not found locally" do
{'fraction_non_alphanumeric': 0.16379157033611952, 'fraction_numerical': 0.006046594344655877, 'mean_word_length': 2.381840048105833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5353519', 'n_tokens_mistral': 2096, 'n_tokens_neox': 2027, 'n_words': 573}