class Test def main is shared Test().run def run .testSimpleLiterals .testMultilineLiterals .testUglyMultilineLiterals .testTrailingCommaLiteral .testInferredType .testReturningSet .testPassSetArg .testGCD .testSetOfTypes .testEquality def testSimpleLiterals t1 = {1, 2, 3} t2 = {'aoeu', 'asdf'} t3 = {,} t4 = {1} t5 = {'aoeu'} assert t1.count==3 assert t2.count==2 assert t3.count==0 assert t4.count==1 assert t5.count==1 def testMultilineLiterals t1 = {1, 2, 3} t2 = { 'aoeu', 'asdf' } t3 = {,} assert t1.count==3 assert t2.count==2 assert t3.count==0 def testUglyMultilineLiterals t1 = {1, 2, 3} t2 = { 'aoeu', 'asdf' } t3 = { , } assert t1.count==3 assert t2.count==2 assert t3.count==0 def testTrailingCommaLiteral t1 = {1, 2, 3,} t2 = {'aoeu', 'asdf',} t3 = { 'aoeu', 'asdf', } assert t1.count==3 assert t2.count==2 assert t3.count==2 def testInferredType # Set t1 = {1, 2, 3} # Set t2 = {'aoeu', 'asdf'} # Set t3 = {1, 'aoeu'} t1.add(5) t2.add('dvorak rules') t3.add('aoeu') t3.add(5) def testReturningSet .makeSet1(1, true, Object()) .makeSet2(Test(), Test()) def makeSet1(a as Object, b as Object, c as Object) as Set s = {a, b, c} return s def makeSet2(a as Test, b as Test) as Set s = {a, b} return s def testPassSetArg .takeSet({1, 2, 3}) def takeSet(t as Set) assert 1 in t assert 2 in t assert 3 in t def testGCD # test that Cobra will use the greatest common denominator between the set elements vehicles = {Car(), Truck()} # should be inferred as Set for v in vehicles # which means `v` should be inferred as Vehicle assert v.speed > 0 def testSetOfTypes classes = {Car, Truck} for c in classes obj = c() assert obj inherits Vehicle assert obj.speed > 0 def testInferIndexedTypeOfNilable t as Set? t = nil t = {'aoeu'} #s = t['aoeu'] #assert s=='aoeu' CobraCore.noOp(t) def testEquality s = {,} assert s == {,} s.add(1) assert s <> {,} assert s == {1} class Vehicle get speed as int return 100 class Car inherits Vehicle class Truck inherits Vehicle