Added analyzer tests for constants
This commit is contained in:
parent
e12e83921b
commit
6313992c10
|
@ -321,3 +321,15 @@ B:(& [g]:Int)
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAssignmentErrConstant (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot assign to constant", 5, 2,
|
||||||
|
`
|
||||||
|
T: Int
|
||||||
|
| x 0
|
||||||
|
[main] = {
|
||||||
|
T.x = 5
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
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]
|
||||||
|
`)}
|
|
@ -203,3 +203,36 @@ Type: (. world:Int)
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConstantNameErrMissing (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"no constant Weekday.palday", 13, 21,
|
||||||
|
`
|
||||||
|
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.palday]
|
||||||
|
`)}
|
||||||
|
|
||||||
|
func TestConstantUniqueErr (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"Weekday.tuesday already defined at stream0.fspl:5:1", 8, 1,
|
||||||
|
`
|
||||||
|
Weekday: String
|
||||||
|
| sunday 'sunday'
|
||||||
|
| monday 'monday'
|
||||||
|
| tuesday 'tuesday'
|
||||||
|
| wednesday 'wednesday'
|
||||||
|
| thursday 'thursday'
|
||||||
|
| tuesday 'tuesday'
|
||||||
|
| friday 'friday'
|
||||||
|
| saturday 'saturday'
|
||||||
|
`)}
|
||||||
|
|
Loading…
Reference in New Issue