package analyzer import "testing" func TestConstantValueSpecified (test *testing.T) { testString (test, ` Weekday: Int | sunday = 1 | monday = 2 | tuesday = 3 | wednesday = 4 | thursday = 5 | friday = 6 | saturday = 7 [print s:String] [printWeekday w:Weekday] = [print switch w | Weekday.sunday 'sunday' | Weekday.monday 'monday' | Weekday.tuesday 'tuesday' | Weekday.wednesday 'wednesday' | Weekday.thursday 'thursday' | Weekday.friday 'friday' | Weekday.saturday 'saturday' * 'unknown'] [f] = [printWeekday Weekday.monday] `)} func TestConstantValueUnspecified (test *testing.T) { testString (test, ` Weekday: Int | sunday | monday | tuesday | wednesday | thursday | friday | saturday [print s:String] [printWeekday w:Weekday] = [print switch w | Weekday.sunday 'sunday' | Weekday.monday 'monday' | Weekday.tuesday 'tuesday' | Weekday.wednesday 'wednesday' | Weekday.thursday 'thursday' | Weekday.friday 'friday' | Weekday.saturday 'saturday' * 'unknown'] [f] = [printWeekday Weekday.monday] `)} func TestConstantString (test *testing.T) { testString (test, ` Weekday: String | sunday = 'sunday' | monday = 'monday' | tuesday = 'tuesday' | wednesday = 'wednesday' | thursday = 'thursday' | friday = 'friday' | saturday = 'saturday' [print s:String] [printWeekday w:Weekday] = [print [~String w]] [f] = [printWeekday Weekday.monday] `)} // TODO: consider filling values for string constants by using the constant // name? func TestErrConstantStringUnspecified (test *testing.T) { testStringErr (test, "cannot fill in constant value for non-numeric type Weekday", 3, 1, ` Weekday: String | sunday | monday | tuesday | wednesday | thursday | friday | saturday [print s:String] [printWeekday w:Weekday] = [print [~String w]] [f] = [printWeekday Weekday.monday] `)}