<commit_before>use("ispec")

parse = method(str,
  Message fromText(str) code)

describe("assignment",
  it("should set kind when assigned to a name with capital initial letter",
    Ground Foo = Origin mimic
    Foo kind should == "Foo")

  it("should set kind when assigned to a name inside something else",
    Ground Foo = Origin mimic
    Foo Bar = Origin mimic
    Foo Bar kind should == "Foo Bar")

  it("should not set kind when it already has a kind",
    Ground Foo = Origin mimic
    Bar = Foo
    Foo kind should == "Foo"
    Bar kind should == "Foo")

  it("should not set kind when assigning to something with a lower case letter",
    Ground foo = Origin mimic
    bar = foo
    foo kind should == "Origin"
    bar kind should == "Origin")

  it("should work for a simple string",
    a = "foo"
    a should == "foo")

  it("should be possible to assign a large expression to default receiver",
    a = Origin mimic
    a kind should == "Origin"
    a should not == Origin)

  it("should be possible to assign to something inside another object",
    Text a = "something"
    Text a should == "something")

  it("should work with combination of equals and plus sign",
    a = 1 + 1
    a should == 2)

  it("should work with something on the next line too",
    m = parse("count = count + 1\ncount println")
    m should == "=(count, count +(1)) .\ncount println")

  it("should work when assigning something to the empty parenthesis",
    m = parse("x = (10+20)")
    m should == "=(x, (10 +(20)))")

  it("should be possible to assign a method to +",
    m = parse("+ = method()")
    m should == "=(+, method)"

    m = parse("Ground + = method()")
    m should == "Ground =(+, method)"
  )

  it("should be possible to assign a method to =",
    m = parse("= = method()")
    m should == "=(=, method)"

    m = parse("Ground = = method()")
    m should == "Ground =(=, method)"
  )

  it("should be possible to assign a method to ..",
    m = parse(".. = method()")
    m should == "=(.., method)"

    m = parse("Ground .. = method()")
    m should == "Ground =(.., method)"
  )

  it("should not undetach things with spaces inbetween",
    m = parse("foo (1) = 42")
    m should == "foo =((1), 42)"
  )

  describe("with destructuring",
    it("should assign all the values in tuple to all the names on the left hand side",
      (val1, val2) = (42, 25)
      val1 should == 42
      val2 should == 25

      cont = Origin mimic
      cont (x, y, z) = (3,2,1)
      cont x should == 3
      cont y should == 2
      cont z should == 1
    )

    it("should use asTuple on the right hand side to get the values",
      (val1, val2) = 42 => 25
      val1 should == 42
      val2 should == 25

      cont = Origin mimic
      cont (x, y, z) = [3,2,1]
      cont x should == 3
      cont y should == 2
      cont z should == 1
    )

    it("should allow _ to be used to mark any remaining values",
      (val1, _) = (1,2,3,4)
      val1 should == 1
      cell?(:"_") should be false
    )

    it("should allow _ to be used in more than one place",
      (val1, _, val2, _, val3, _) = (1,2,3,4,5,6,7,8,9)
      val1 should == 1
      val2 should == 3
      val3 should == 5
      cell?(:"_") should be false
    )

    it("should report an error if the destructuring doesn't match up",
      fn((val1, val2) = (1,2,3)) should signal(Condition Error DestructuringMismatch)
    )

    it("should be able to destructure recursively")
    it("should be able to destructure recursively using asTuple")
    it("should make the assignments in parallel, so you can switch values easily")
    it("should allow for places inside of the assignment specification")
  )

  describe("+=",
    it("should parse correctly without receiver, with arguments",
      m = parse("(1) += 12")
      m should == "+=((1), 12)")

    it("should parse correctly with receiver without spaces and arguments",
      m = parse("foo(1) += 12")
      m should == "+=(foo(1), 12)")

    it("should parse correctly with receiver without even more spaces and arguments",
      m = parse("foo(1)+=12")
      m should == "+=(foo(1), 12)")

    it("should parse correctly with complicated expression on left hand side",<commit_msg>Add a test for parallel assignment<commit_after>use("ispec")

parse = method(str,
  Message fromText(str) code)

describe("assignment",
  it("should set kind when assigned to a name with capital initial letter",
    Ground Foo = Origin mimic
    Foo kind should == "Foo")

  it("should set kind when assigned to a name inside something else",
    Ground Foo = Origin mimic
    Foo Bar = Origin mimic
    Foo Bar kind should == "Foo Bar")

  it("should not set kind when it already has a kind",
    Ground Foo = Origin mimic
    Bar = Foo
    Foo kind should == "Foo"
    Bar kind should == "Foo")

  it("should not set kind when assigning to something with a lower case letter",
    Ground foo = Origin mimic
    bar = foo
    foo kind should == "Origin"
    bar kind should == "Origin")

  it("should work for a simple string",
    a = "foo"
    a should == "foo")

  it("should be possible to assign a large expression to default receiver",
    a = Origin mimic
    a kind should == "Origin"
    a should not == Origin)

  it("should be possible to assign to something inside another object",
    Text a = "something"
    Text a should == "something")

  it("should work with combination of equals and plus sign",
    a = 1 + 1
    a should == 2)

  it("should work with something on the next line too",
    m = parse("count = count + 1\ncount println")
    m should == "=(count, count +(1)) .\ncount println")

  it("should work when assigning something to the empty parenthesis",
    m = parse("x = (10+20)")
    m should == "=(x, (10 +(20)))")

  it("should be possible to assign a method to +",
    m = parse("+ = method()")
    m should == "=(+, method)"

    m = parse("Ground + = method()")
    m should == "Ground =(+, method)"
  )

  it("should be possible to assign a method to =",
    m = parse("= = method()")
    m should == "=(=, method)"

    m = parse("Ground = = method()")
    m should == "Ground =(=, method)"
  )

  it("should be possible to assign a method to ..",
    m = parse(".. = method()")
    m should == "=(.., method)"

    m = parse("Ground .. = method()")
    m should == "Ground =(.., method)"
  )

  it("should not undetach things with spaces inbetween",
    m = parse("foo (1) = 42")
    m should == "foo =((1), 42)"
  )

  describe("with destructuring",
    it("should assign all the values in tuple to all the names on the left hand side",
      (val1, val2) = (42, 25)
      val1 should == 42
      val2 should == 25

      cont = Origin mimic
      cont (x, y, z) = (3,2,1)
      cont x should == 3
      cont y should == 2
      cont z should == 1
    )

    it("should use asTuple on the right hand side to get the values",
      (val1, val2) = 42 => 25
      val1 should == 42
      val2 should == 25

      cont = Origin mimic
      cont (x, y, z) = [3,2,1]
      cont x should == 3
      cont y should == 2
      cont z should == 1
    )

    it("should allow _ to be used to mark any remaining values",
      (val1, _) = (1,2,3,4)
      val1 should == 1
      cell?(:"_") should be false
    )

    it("should allow _ to be used in more than one place",
      (val1, _, val2, _, val3, _) = (1,2,3,4,5,6,7,8,9)
      val1 should == 1
      val2 should == 3
      val3 should == 5
      cell?(:"_") should be false
    )

    it("should report an error if the destructuring doesn't match up",
      fn((val1, val2) = (1,2,3)) should signal(Condition Error DestructuringMismatch)
    )

    it("should be able to destructure recursively")
    it("should be able to destructure recursively using asTuple")
    it("should be able to use _ inside of a recursive structure")

    it("should make the assignments in parallel, so you can switch values easily",
      aval = 42
      bval = 35
      cval = 222
      (aval, bval, cval) = (cval, aval, bval)
      aval should == 222
      bval should == 42
      cval should == 35
    )

    it("should allow for places inside of the assignment specification")
    it("should be possible to use places inside of a recursive assignment")
  )

  describe("+=",
    it("should parse correctly without receiver, with arguments",
      m = parse("(1) += 12")
      m should == "+=((1), 12)")

    it("should parse correctly with receiver without spaces and arguments",
      m = parse("foo(1) += 12")
      m should == "+=(foo(1), 12)")

    it("should parse correctly with receiver without even more spaces and arguments",
      m = parse("foo(1)+=12")
      m should == "+=(foo(1), 12)")

    it("should parse correctly with complicated expression on left hand side",
{'fraction_non_alphanumeric': 0.13229083437963704, 'fraction_numerical': 0.025111288665677436, 'mean_word_length': 2.6402160365600333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7356471', 'n_tokens_mistral': 2852, 'n_tokens_neox': 2636, 'n_words': 1108}