# Tests for multiarg assignment from list, array and method to local vars class MultiAssign def main .array .list .nonMatchCount def array a, b = @[1, 2] assert a == 1 assert b == 2 c, d, x = @['1', '2', '3'] assert c == '1' assert d == '2' assert x == '3' e, f, g = @[1, 'Two', c'3'] assert e == 1 assert f == 'Two' assert g == c'3' def list a, b = [1, 2] assert a == 1 assert b == 2 d, e = .func2 assert d == 'a' assert e == 'b' # {:-)} d1,d2 = .funcStr2 assert d1 == c'e' assert d2 == c'h' ll = [21, 22] f, g = ll assert f == 21 assert g == 22 ii, s = [99, 'STR'] assert ii == 99 assert ii.getType is Int32 assert s == 'STR' ls = List() ls.add("one") ls.add("two") ls.add("three") s0, s1, s2 = ls assert s0 == 'one' assert s1 == 'two' assert s2 == 'three' def nonMatchCount expect UnpackException a, b, c = [11, 12] assert a == 0 and b == 0 and c == 0 ls = List() ls.add("one") ls.add("two") ls.add("three") expect UnpackException s0, s1 = ls # ? assert s0 is nil and s1 is nil CobraCore.noOp(s0, s1) expect UnpackException g, h = @['1', '2', '3'] # ? assert g is nil and h is nil CobraCore.noOp(g, h) m = '' c1 as Object = 'x' expect UnpackException l, m, n, c1 = @[1, 'Two', c'3'] assert m == '' and c1 == 'x' CobraCore.noOp(l, n) expect UnpackException p, q, r = 'ab' assert p == c'\0' and q == c'\0' and r == c'\0' def func2 as List is shared return ['a', 'b'] def funcStr2 as String is shared return 'eh' /# Dictionary .keys, .values and .getEnumerator do NOT guarantee an order to what they return. Furthermore, the use of for-expressions below just create lists which we already cover in other tests. - Charles Esterbrook, 2012-07 def dict # sorta interesting - resolves to a normal lookup by 0-offset # numeric key in order of given variables.... #x = {0:'a', 1:'b'} #print x[0] c, d, e = {0:'a', 1:'b', 2:'c', 3:'d'} assert c == 'a' assert d == 'b' assert e == 'c' # but if there's a key missing in the range -> KeyNotFoundException xdict = {0:'z', 1:'w', 3:'x'} keysColl = for k in xdict.keys get k #print keysColl f, g = keysColl assert f == 0 assert g == 1 valsColl = for v in xdict.values get v h, i = valsColl assert h == 'z' assert i == 'w' #print valsColl #/