# HG changeset patch # User Thorsten Meyer # Date 1239791371 -7200 # Node ID 8ca06fd9c6ef5b98f8b0ab8a4bceba9799d25580 # Parent bb62bc406ea72c371d1ceacfe7c8f6584e82d403 test lazy copying in structures diff --git a/test/ChangeLog b/test/ChangeLog --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2009-04-15 Thorsten Meyer + + * test_struct.m: Add tests for lazy copying in nested assignments + of struct elements. + 2009-04-12 Thorsten Meyer * test_contin.m, test_error.m, test_eval-catch.m, test_for.m, diff --git a/test/test_struct.m b/test/test_struct.m --- a/test/test_struct.m +++ b/test/test_struct.m @@ -197,3 +197,57 @@ %! c(3, 3, 3, 3).value = 1; %! c([1, 3], 2, :, [3, 4]).value = 1; +## test lazy copying in structs: nested assignment to self +%!test +%! a.a = 1; +%! a.b = a; +%! a.b.c = a; +%! assert (a.b.c.b, struct ("a", 1)); + +## test lazy copying in structs: indirect nested assignment to self +%!test +%! a.a = 1; +%! a.b = 2; +%! b.c = a; +%! b.d = 3; +%! c.d = b; +%! c.e = 4; +%! a.b = c; +%! a.b.e = a; +%! assert (a.b.e.b.d.c, struct ("a", 1, "b", 2)); + +## test lazy copying in structs: nested assignment via function +%!function aa = do_nest (a); +%! aa = a; +%! aa.b = a; +%! endfunction +%!test +%! a.c = 1; +%! a = do_nest (a); +%! a = do_nest (a); +%! a = do_nest (a); +%! assert (a.b.b.b, struct ("c", 1)); + +## test lazy copying in structs: nested assignment via function +%!function aa = do_nest (a); +%! aa = a; +%! aa.b = a; +%! aa.b.c = aa; +%! endfunction +%!test +%! a.c = 1; +%! a = do_nest (a); +%! a = do_nest (a); +%! a = do_nest (a); +%! assert (a.b.c.b.b.c.b.b.c.b, struct ("c", 1)); + +## test lazy copying in structs: nested assignment on different levels. +%!test +%! a.b = 1; +%! b.c = a; +%! b.d.e = a; +%! b.f.g.h = a; +%! b.i.j.k.l = a; +%! a.m = b; +%! a.m.c.b = a; +%! assert (a.m.c.b.m.i.j.k.l, struct ("b", 1));