123 lines
2.2 KiB
Go
123 lines
2.2 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, 45,
|
|
`
|
|
[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]
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestBitCastPointer (test *testing.T) {
|
|
testString (test,
|
|
`
|
|
Struct: (. x:Int y:Int)
|
|
Array: 4:Int
|
|
[main] = {
|
|
ptr:*Byte
|
|
stc:Struct
|
|
arr:Array
|
|
str:String
|
|
idx:Index
|
|
|
|
; struct
|
|
ptr = [~~*Byte [~~Struct ptr]]
|
|
stc = [~~Struct [~~*Byte stc]]
|
|
; array
|
|
ptr = [~~*Byte [~~Array ptr]]
|
|
arr = [~~Array [~~*Byte arr]]
|
|
; slice
|
|
ptr = [~~*Byte [~~String ptr]]
|
|
str = [~~String [~~*Byte str]]
|
|
; int
|
|
ptr = [~~*Byte [~~Index ptr]]
|
|
idx = [~~Index [~~*Byte idx]]
|
|
|
|
; arithmetic
|
|
ptr = [~~*Byte [+ 1 [~~Index ptr]]]
|
|
}
|
|
`)
|
|
}
|