fspl/analyzer/cast_test.go

92 lines
1.6 KiB
Go

package analyzer
import "testing"
func TestCastErrIntPointer (test *testing.T) {
testStringErr (test,
"cannot convert from *Int to Int", 4, 9,
`
[main]:Int = {
a:*Int
[~ Int a]
}
`)
}
func TestCastErrIntStruct (test *testing.T) {
testStringErr (test,
"cannot convert from (x:Int y:Int) to Int", 2, 21,
`
[main]:Int = [~ Int a:(x:Int y:Int)]
`)
}
func TestCastErrIntArray (test *testing.T) {
testStringErr (test,
"cannot convert from 5:Int to Int", 2, 21,
`
[main]:Int = [~ Int a:5:Int]
`)
}
func TestCastErrIntSlice (test *testing.T) {
testStringErr (test,
"cannot convert from *:Int to Int", 2, 21,
`
[main]:Int = [~ Int a:*:Int]
`)
}
func TestCastErrPointerInt (test *testing.T) {
testStringErr (test,
"cannot convert from Int to *Int", 2, 23,
`
[main]:*Int = [~ *Int a:Int]
`)
}
func TestCastErrStructInt (test *testing.T) {
testStringErr (test,
"cannot convert from Int to (x:Int y:Int)", 2, 41,
`
[main]:(x:Int y:Int) = [~ (x:Int y:Int) a:Int]
`)
}
func TestCastErrArrayInt (test *testing.T) {
testStringErr (test,
"cannot convert from 5:Int to Int", 2, 21,
`
[main]:Int = [~ Int a:5:Int]
`)
}
func TestCastErrSliceInt (test *testing.T) {
testStringErr (test,
"cannot convert from Int to *:Int", 2, 25,
`
[main]:*:Int = [~ *:Int a:Int]
`)
}
func TestCast (test *testing.T) {
testString (test,
`
Bird: ([fly distance:F64] [land])
BlueJay: Int
BlueJay.[fly distance:F64] = { }
BlueJay.[land] = { }
IntDerived: Int
[main] = {
a:IntDerived = 5
b:Int [~ Int [~ F64 [~ Byte a]]]
c:Int [~~ Int [~~ F64 [~~ Byte a]]]
d:(x:Int y:Int) = (x: 1 y: 2)
e:(z:Int a:Int) = [~~ (z:Int a:Int) d]
f:Bird = [~~ BlueJay 0]
g:String = 'hello'
h:*:Byte = [~ *:Byte g]
}
`)
}