fspl/analyzer/constant_test.go

91 lines
1.7 KiB
Go

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
| sunday 'sunday'
| monday 'monday'
| tuesday 'tuesday'
| wednesday 'wednesday'
| thursday 'thursday'
| friday 'friday'
| 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
| sunday 'sunday'
| monday 'monday'
| tuesday 'tuesday'
| wednesday 'wednesday'
| thursday 'thursday'
| friday 'friday'
| 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 values for non-numeric type Weekday", 5, 11,
`
Weekday: String
| sunday
| monday
| tuesday
| wednesday
| thursday
| friday
| saturday
[print s:String]
[printWeekday w:Weekday] = [print [~String w]]
[f] = [printWeekday Weekday.monday]
`)}