# tests for multiTarget assignment from comma-sep expression stream class Test var avar = 99 var bvar = 88 var _avar1 = 77 get prop return 66 def main .literals .variables .exprs .cast .asExpected .swap .typedList .transformedExpr def literals a,b,c = 1,2,3 assert a==1 assert b==2 assert c==3 x,y,z = 'this','is','silly' assert x == 'this' assert y == 'is' assert z == 'silly' x,y = 'a','b' assert x == 'a' assert y == 'b' assert z == 'silly' #mixed types a,x,ch = 99,'wokka',c'x' assert a == 99 assert x == 'wokka' assert ch == c'x' def variables a = 22 b = 47 c = 76 d,e = a,b assert d == 22 assert e == 47 d,e = .avar, .bvar assert d == 99 assert e == 88 d,e = _avar1, 10 assert d == 77 assert e == 10 d,e = -1, _avar1 assert d == -1 assert e == 77 d,c = .prop, a assert d == 66 assert c == 22 def exprs a,b = 99+1,100-99 assert a == 100 assert b == 1 a = .geti(0) # OK assert a ==2 a, = .geti(1), # OK - note trailing commas assert a == 3 #a, = .geti(1) # typo missing trailing ',': peculiar error: cannot find an indexer #assert a == 3 a,b = .geti(2), .geti(10) assert a == 4 assert b == 12 a,b = 0,0 a,b = .geti(2), .geti(10) assert a == 4 assert b == 12 def geti(i as int) as int return i+2 def cast # ticket:170 x = 'aoeu' to Object y = 5 to Object a, b = x to String, y to int assert a.length == 4 assert b * 2 == 10 c, d = x to? String, y to? int assert c.length == 4 assert d * 2 == 10 def asExpected # test expression values are pinned outside assignment stream a,b = c=2,3 assert a == 2 assert c == 2 assert b == 3 a=100 a,b = a+1, a+2 assert a == 101 assert b == 102 c,c = 0,1 assert c == 1 def swap a = 10 b = 20 assert a == 10 assert b == 20 a,b = b,a assert a == 20 assert b == 10 def typedList t = ['abc', 'abcd'] a, b = t assert a.length == 3 or b.length == 4 assert a == 'abc' and b == 'abcd' def transformedExpr a, b = 'x', .bar('y') a, b = 'x', _bar('y') # the above line use to cause an internal error # due to mishandling of node transformation assert a == 'x' and b == 1 def bar(s as String) as int return 1 def _bar(s as String) as int return 1