summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErnie Rael <errael@raelity.com>2024-07-06 11:44:37 +0200
committerChristian Brabandt <cb@256bit.org>2024-07-06 11:44:37 +0200
commitf397549332eed7a1f2f7cd494a28be3b5c4821cb (patch)
treeef00c6965e8cfcfc4517b20bd5696a45d88206ed
parentb81109192f8019f324a547dfdf0b4cf6aca3fe3a (diff)
patch 9.1.0533: Vim9: need more tests for nested objects equalityv9.1.0533
Problem: Vim9: need more tests for nested objects equality Solution: Add more tests (Ernie Rael) related: #15070 related: #15081 related: #15085 closes: #15153 Signed-off-by: Ernie Rael <errael@raelity.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--src/testdir/test_vim9_class.vim97
-rw-r--r--src/version.c2
2 files changed, 99 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index 13e8ea6e0b..4f75a945ad 100644
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -10580,6 +10580,103 @@ def Test_Object_Compare_With_Recursive_Class_Ref()
v9.CheckScriptSuccess(lines)
enddef
+" Test for comparing a class with nesting objects
+def Test_Object_Compare_With_Nesting_Objects()
+ # On a compare, after vim equal recurses 1000 times, not finding an unequal,
+ # return the compare is equal.
+ # Test that limit
+
+ var lines =<< trim END
+ vim9script
+ class C
+ public var n: number
+ public var nest: C
+
+ # Create a "C" that chains/nests to indicated depth.
+ # return {head: firstC, tail: lastC}
+ static def CreateNested(depth: number): dict<C>
+ var first = C.new(1, null_object)
+ var last = first
+ for i in range(2, depth)
+ last.nest = C.new(i, null_object)
+ last = last.nest
+ endfor
+ return {head: first, tail: last}
+ enddef
+
+ # Return pointer to nth item in chain.
+ def GetLink(depth: number): C
+ var count = 1
+ var p: C = this
+ while count < depth
+ p = p.nest
+ if p == null
+ throw "too deep"
+ endif
+ count += 1
+ endwhile
+ return p
+ enddef
+
+ # Return the length of the chain
+ def len(): number
+ var count = 1
+ var p: C = this
+ while p.nest != null
+ p = p.nest
+ count += 1
+ endwhile
+ return count
+ enddef
+ endclass
+
+ var chain = C.CreateNested(3)
+ var s = "object of C {n: 1, nest: object of C {n: 2, nest: object of C {n: 3, nest: object of [unknown]}}}"
+ assert_equal(s, string(chain.head))
+ assert_equal(3, chain.head->len())
+
+ var chain1 = C.CreateNested(100)
+ var chain2 = C.CreateNested(100)
+ assert_true(chain1.head == chain2.head)
+
+ # modify the tail of chain2, compare not equal
+ chain2.tail.n = 123456
+ assert_true(chain1.head != chain2.head)
+
+ # a tail of a different length compares not equal
+ chain2 = C.CreateNested(101)
+ assert_true(chain1.head != chain2.head)
+
+ chain1 = C.CreateNested(1000)
+ chain2 = C.CreateNested(1000)
+ assert_true(chain1.head == chain2.head)
+
+ # modify the tail of chain2, compare not equal
+ chain2.tail.n = 123456
+ assert_true(chain1.head != chain2.head)
+
+ # try a chain longer that the limit
+ chain1 = C.CreateNested(1001)
+ chain2 = C.CreateNested(1001)
+ assert_true(chain1.head == chain2.head)
+
+ # modify the tail, but still equal
+ chain2.tail.n = 123456
+ assert_true(chain1.head == chain2.head)
+
+ # remove 2 items from front, shorten the chain by two.
+ chain1.head = chain1.head.GetLink(3)
+ chain2.head = chain2.head.GetLink(3)
+ assert_equal(3, chain1.head.n)
+ assert_equal(3, chain2.head.n)
+ assert_equal(999, chain1.head->len())
+ assert_equal(999, chain2.head->len())
+ # Now less than the limit, compare not equal
+ assert_true(chain1.head != chain2.head)
+ END
+ v9.CheckScriptSuccess(lines)
+enddef
+
" Test for using a compound operator from a lambda function in an object method
def Test_compound_op_in_objmethod_lambda()
# Test using the "+=" operator
diff --git a/src/version.c b/src/version.c
index 9cea344934..4867fe8d76 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 533,
+/**/
532,
/**/
531,