# Test multivariable assignment in forEnumeration from a Dictionary # this is oriented towards dicts of generics since HashTable enumerator # type inference is NYI use System.Collections class Dict def main is shared d = Dict() d.manualAssign d.multiAssign d.twoArgs d.dictGen d.hashTblDict def manualAssign xdict = {0: 'z', 1: 'w', 3: 'x'} for kv in xdict k = kv.key v = kv.value #print 'k=', k, 'v=', v assert k in [0, 1, 3] assert v in ['z', 'w', 'x'] def multiAssign xdict = {0: 'z', 1: 'w', 3: 'x'} for kv in xdict k, v = kv.key, kv.value #print 'k=', k, 'v=', v assert k in [0, 1, 3] assert v in ['z', 'w', 'x'] def twoArgs xdict = {0: 'z', 1: 'w', 3: 'x'} for k, v in xdict #print 'k=', k, 'v=', v assert k in [0, 1, 3] assert v in ['z', 'w', 'x'] def edgeCases xdict = {0: 'z', 1: 'w', 3: 'x'} for kv, in xdict # note trailing comma after kv k, v = kv.key, kv.value #print 'k=', k, 'v=', v assert k in [0, 1, 3] assert v in ['z', 'w', 'x'] x1dict = {99: 'zzz'} for k, v in x1dict pass assert k == 99 assert v == 'zzz' k2=994 x2dict = {: } for k2, v2 in x2dict pass assert k2 == 994 assert v2 == nil def dictGen gdict = Dictionary() gdict['a1'] = 1 gdict['b1'] = 2 gdict['c1'] = 3 for k, v in gdict #for kv in gdict # k, v = [kv.key, kv.value] assert k in ['a1', 'b1', 'c1'] assert v in [1, 2, 3] def hashTblDict gdict = Hashtable() gdict['a'] = 'z' gdict['b'] = 'y' gdict['c'] = 'w' assert gdict['a'] == 'z' for de in gdict k, v = de.key to dynamic, de.value to dynamic assert k in ['a', 'b', 'c'] assert v in ['z', 'y', 'w'] for k2, v2 in gdict assert k2 to dynamic in ['a', 'b', 'c'] assert v2 to dynamic in ['z', 'y', 'w']