Ticket #203: enums-comma-sep.patch
File enums-comma-sep.patch, 2.3 KB (added by hopscc, 15 years ago) |
---|
-
Source/CobraParser.cobra
1020 1020 enumValue = .expect('INTEGER_LIT').value to int? 1021 1021 else 1022 1022 enumValue = nil 1023 .endOfLine 1023 if not .optional('COMMA') 1024 .endOfLine 1024 1025 if enumNameToken.text in nameSet 1025 1026 .recordError(enumNameToken, 'Already defined "[enumNameToken.text]" earlier.') 1026 1027 else -
Tests/100-basics/331-enums-comma.cobra
1 enum Colors 2 Red = 2, Green, Blue 3 4 class Test 5 6 def main 7 is shared 8 c as Colors = Colors.Red 9 assert c == Colors.Red 10 assert c <> Colors.Green 11 assert c is Colors.Red # .warning. value types 12 assert c is not Colors.Green # .warning. value types -
Tests/100-basics/330-enums-comma.cobra
1 # alternate syntax, comma sepearated 2 enum Colors 3 Red, Green, Blue 4 5 class Test 6 7 def main 8 is shared 9 c as Colors = Colors.Red 10 assert c == Colors.Red 11 assert c <> Colors.Green 12 assert c is Colors.Red # .warning. value types 13 assert c is not Colors.Green # .warning. value types -
Tests/100-basics/332-enums-comma.cobra
1 # comma sep syntax 2 enum Color 3 Red = 1, Green = 2, 4 Blue = 4 5 6 class Test 7 8 def main is shared 9 c = Color(Red, Green) 10 print c 11 print c to int 12 .takeColor(Color(Red, Green)) 13 # TODO: Should have a qualified example. System.SomeEnum(MemberA, MemberB) and System.Something.SomeEnum(MemberA, MemberB) 14 15 # testing enum membership with bitwise-and 16 assert c & Color.Red == Color.Red 17 assert c & Color.Green == Color.Green 18 assert c & Color.Blue <> Color.Blue 19 20 def takeColor(c as Color) is shared 21 pass