Reorganized tests
This commit is contained in:
parent
3570caeb2e
commit
160cbd16ad
@ -1,320 +0,0 @@
|
|||||||
package analyzer
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func TestAssignLiteralErrUnsignedNegative (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"expected unsigned integer", 3, 11,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
x:UInt = -5
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrIntegerFloat (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"expected integer", 3, 10,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
x:Int = 5.5
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrIntegerStruct (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"expected integer", 3, 10,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
x:Int = (x: 5)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrIntegerArray (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"expected integer", 3, 10,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
x:Int = (* 5)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrIntegerOverflow (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"expected smaller number", 3, 11,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
x:Byte = 1000
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrArrayInt (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"expected array", 3, 11,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
x:3:Int = 5
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrArrayWrongLength (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"expected 3 elements", 3, 11,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
x:3:Int = (* 1 2 3 4)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrArrayWrongType (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"expected integer", 3, 19,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
x:3:Int = (* 1 2 3.3 4)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrSliceWrongType (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"expected integer", 3, 19,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
x:*:Int = (* 1 2 3.3 4)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrStructWrongType (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"expected integer", 3, 26,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
x:3:(x:Int y:Int) = (x: 5.5 y: 3)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
func TestAssignLiteralErrStructInteger (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"expected struct", 3, 26,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
x:3:(x:Int y:Int) = 5
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrInterfaceInt (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot assign literal to interface", 6, 2,
|
|
||||||
`
|
|
||||||
Bird: ([fly distance:F64] [land])
|
|
||||||
[main] = {
|
|
||||||
b:Bird = 5
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrInterfaceFloat (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot assign literal to interface", 6, 2,
|
|
||||||
`
|
|
||||||
Bird: ([fly distance:F64] [land])
|
|
||||||
[main] = {
|
|
||||||
b:Bird = 5.5
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrInterfaceArray (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot assign literal to interface", 6, 2,
|
|
||||||
`
|
|
||||||
Bird: ([fly distance:F64] [land])
|
|
||||||
[main] = {
|
|
||||||
b:Bird = (* 1 2 3 4)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteralErrInterfaceStruct (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot assign literal to interface", 6, 2,
|
|
||||||
`
|
|
||||||
Bird: ([fly distance:F64] [land])
|
|
||||||
BlueJay: Int
|
|
||||||
BlueJay::[land] = { }
|
|
||||||
[main] = {
|
|
||||||
b:Bird = (x: 5 y: 6)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignLiteral (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
[main] = {
|
|
||||||
a:F64 = 5.3
|
|
||||||
b:F32 = 5.3
|
|
||||||
c:F64 = -5
|
|
||||||
d:F32 = -5
|
|
||||||
e:Byte = 64
|
|
||||||
z:UInt = 5
|
|
||||||
x:Int = -5
|
|
||||||
arr:4:2:Int = (*
|
|
||||||
(* 1 2)
|
|
||||||
(* 3 4)
|
|
||||||
(* 5 6)
|
|
||||||
(* 7 8))
|
|
||||||
slice:*:Int = (* 3 1 2 3)
|
|
||||||
struct:(x:Int y:Int) = (
|
|
||||||
x: 9
|
|
||||||
y: 10)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignInterfaceErrBadSignature (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"BlueJay has wrong signature for method fly", 7, 2,
|
|
||||||
`
|
|
||||||
Bird: ([fly distance:F64] [land])
|
|
||||||
BlueJay: Int
|
|
||||||
BlueJay::[fly] = { }
|
|
||||||
BlueJay::[land] = { }
|
|
||||||
[main] = {
|
|
||||||
b:Bird = [@a:BlueJay]
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAssignInterface (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
Bird: ([fly distance:F64] [land])
|
|
||||||
BlueJay: Int
|
|
||||||
BlueJay::[fly distance:F64] = { }
|
|
||||||
BlueJay::[fly land] = { }
|
|
||||||
[main] = {
|
|
||||||
a:BlueJay
|
|
||||||
b:Bird = [@a]
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCastErrIntPointer (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot convert from *Int to Int", 2, 14,
|
|
||||||
`
|
|
||||||
[main]:Int = [~ [@ a:Int] Int]
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCastErrIntStruct (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot convert from (x:Int y:Int) to Int", 2, 14,
|
|
||||||
`
|
|
||||||
[main]:Int = [~ a:(x:Int y:Int) Int]
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCastErrIntArray (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot convert from 5:Int to Int", 2, 14,
|
|
||||||
`
|
|
||||||
[main]:Int = [~ a:5:Int Int]
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCastErrIntSlice (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot convert from *:Int to Int", 2, 14,
|
|
||||||
`
|
|
||||||
[main]:Int = [~ a:*:Int Int]
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCastErrPointerInt (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot convert from Int to *Int", 2, 15,
|
|
||||||
`
|
|
||||||
[main]:*Int = [~ [@ a:Int] *Int]
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCastErrStructInt (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot convert from Int to (x:Int y:Int)", 2, 24,
|
|
||||||
`
|
|
||||||
[main]:(x:Int y:Int) = [~ a:Int (x:Int y:Int)]
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCastErrArrayInt (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot convert from Int to 5:Int", 2, 13,
|
|
||||||
`
|
|
||||||
[main]:Int = [~ a:5:Int Int]
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCastErrSliceInt (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot convert from Int to *:Int", 2, 16,
|
|
||||||
`
|
|
||||||
[main]:*:Int = [~ a:Int *:Int]
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestCast (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
Bird: ([fly distance:F64] [land])
|
|
||||||
BlueJay: Int
|
|
||||||
BlueJay::[fly distance:F64] = { }
|
|
||||||
BlueJay::[fly land] = { }
|
|
||||||
IntDerived: Int
|
|
||||||
[main] = {
|
|
||||||
a:IntDerived = 5
|
|
||||||
b:Int [~ [~ [~ a Byte] F64] Int]
|
|
||||||
c:Int [~~ [~~ [~~ a Byte] F64] Int]
|
|
||||||
d:(x:Int y:Int) = (x: 1 y: 2)
|
|
||||||
e:(z:Int a:Int) = [~~ d (z:Int a:Int)]
|
|
||||||
f:Bird = [@ [~~ 0 BlueJay]]
|
|
||||||
g:*:Int = (~ h:5:Int *:int)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: complete and test error cases
|
|
||||||
func TestPropagateAssignRules (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
[f]:Byte = 5
|
|
||||||
A:Int
|
|
||||||
A::[g]:Int = 2
|
|
||||||
B:([g]:Int)
|
|
||||||
[main] = {
|
|
||||||
a:Int
|
|
||||||
b:Int = a
|
|
||||||
c:Int = d:Int
|
|
||||||
d:Int = { a:F64 b }
|
|
||||||
e:Byte = [f]
|
|
||||||
g:(x:Int y:(w:F64 z:F64)) = (x: 1 y: (w: 1.2 z: 78.5))
|
|
||||||
h:F64 = g.x.z
|
|
||||||
i:A
|
|
||||||
j:Int = [i::g]
|
|
||||||
k:B = i
|
|
||||||
l:Int = [k::g]
|
|
||||||
m:5:Int = (* 0 1 2 3 4)
|
|
||||||
n:Int = [. m 3]
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
236
analyzer/assignment_test.go
Normal file
236
analyzer/assignment_test.go
Normal file
@ -0,0 +1,236 @@
|
|||||||
|
package analyzer
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrUnsignedNegative (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"expected unsigned integer", 3, 11,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
x:UInt = -5
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrIntegerFloat (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"expected integer", 3, 10,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
x:Int = 5.5
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrIntegerStruct (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"expected integer", 3, 10,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
x:Int = (x: 5)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrIntegerArray (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"expected integer", 3, 10,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
x:Int = (* 5)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrIntegerOverflow (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"expected smaller number", 3, 11,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
x:Byte = 1000
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrArrayInt (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"expected array", 3, 11,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
x:3:Int = 5
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrArrayWrongLength (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"expected 3 elements", 3, 11,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
x:3:Int = (* 1 2 3 4)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrArrayWrongType (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"expected integer", 3, 19,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
x:3:Int = (* 1 2 3.3 4)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrSliceWrongType (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"expected integer", 3, 19,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
x:*:Int = (* 1 2 3.3 4)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrStructWrongType (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"expected integer", 3, 26,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
x:3:(x:Int y:Int) = (x: 5.5 y: 3)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
func TestAssignmentLiteralErrStructInteger (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"expected struct", 3, 26,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
x:3:(x:Int y:Int) = 5
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrInterfaceInt (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot assign literal to interface", 6, 2,
|
||||||
|
`
|
||||||
|
Bird: ([fly distance:F64] [land])
|
||||||
|
[main] = {
|
||||||
|
b:Bird = 5
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrInterfaceFloat (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot assign literal to interface", 6, 2,
|
||||||
|
`
|
||||||
|
Bird: ([fly distance:F64] [land])
|
||||||
|
[main] = {
|
||||||
|
b:Bird = 5.5
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrInterfaceArray (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot assign literal to interface", 6, 2,
|
||||||
|
`
|
||||||
|
Bird: ([fly distance:F64] [land])
|
||||||
|
[main] = {
|
||||||
|
b:Bird = (* 1 2 3 4)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteralErrInterfaceStruct (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot assign literal to interface", 6, 2,
|
||||||
|
`
|
||||||
|
Bird: ([fly distance:F64] [land])
|
||||||
|
BlueJay: Int
|
||||||
|
BlueJay::[land] = { }
|
||||||
|
[main] = {
|
||||||
|
b:Bird = (x: 5 y: 6)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentLiteral (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
[main] = {
|
||||||
|
a:F64 = 5.3
|
||||||
|
b:F32 = 5.3
|
||||||
|
c:F64 = -5
|
||||||
|
d:F32 = -5
|
||||||
|
e:Byte = 64
|
||||||
|
z:UInt = 5
|
||||||
|
x:Int = -5
|
||||||
|
arr:4:2:Int = (*
|
||||||
|
(* 1 2)
|
||||||
|
(* 3 4)
|
||||||
|
(* 5 6)
|
||||||
|
(* 7 8))
|
||||||
|
slice:*:Int = (* 3 1 2 3)
|
||||||
|
struct:(x:Int y:Int) = (
|
||||||
|
x: 9
|
||||||
|
y: 10)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentInterfaceErrBadSignature (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"BlueJay has wrong signature for method fly", 7, 2,
|
||||||
|
`
|
||||||
|
Bird: ([fly distance:F64] [land])
|
||||||
|
BlueJay: Int
|
||||||
|
BlueJay::[fly] = { }
|
||||||
|
BlueJay::[land] = { }
|
||||||
|
[main] = {
|
||||||
|
b:Bird = [@a:BlueJay]
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAssignmentInterface (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
Bird: ([fly distance:F64] [land])
|
||||||
|
BlueJay: Int
|
||||||
|
BlueJay::[fly distance:F64] = { }
|
||||||
|
BlueJay::[fly land] = { }
|
||||||
|
[main] = {
|
||||||
|
a:BlueJay
|
||||||
|
b:Bird = [@a]
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: complete and test error cases
|
||||||
|
func TestAssignmentPropagateRules (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
[f]:Byte = 5
|
||||||
|
A:Int
|
||||||
|
A::[g]:Int = 2
|
||||||
|
B:([g]:Int)
|
||||||
|
[main] = {
|
||||||
|
a:Int
|
||||||
|
b:Int = a
|
||||||
|
c:Int = d:Int
|
||||||
|
d:Int = { a:F64 b }
|
||||||
|
e:Byte = [f]
|
||||||
|
g:(x:Int y:(w:F64 z:F64)) = (x: 1 y: (w: 1.2 z: 78.5))
|
||||||
|
h:F64 = g.x.z
|
||||||
|
i:A
|
||||||
|
j:Int = [i::g]
|
||||||
|
k:B = i
|
||||||
|
l:Int = [k::g]
|
||||||
|
m:5:Int = (* 0 1 2 3 4)
|
||||||
|
n:Int = [. m 3]
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
87
analyzer/cast_test.go
Normal file
87
analyzer/cast_test.go
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package analyzer
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestCastErrIntPointer (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot convert from *Int to Int", 2, 14,
|
||||||
|
`
|
||||||
|
[main]:Int = [~ [@ a:Int] Int]
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCastErrIntStruct (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot convert from (x:Int y:Int) to Int", 2, 14,
|
||||||
|
`
|
||||||
|
[main]:Int = [~ a:(x:Int y:Int) Int]
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCastErrIntArray (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot convert from 5:Int to Int", 2, 14,
|
||||||
|
`
|
||||||
|
[main]:Int = [~ a:5:Int Int]
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCastErrIntSlice (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot convert from *:Int to Int", 2, 14,
|
||||||
|
`
|
||||||
|
[main]:Int = [~ a:*:Int Int]
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCastErrPointerInt (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot convert from Int to *Int", 2, 15,
|
||||||
|
`
|
||||||
|
[main]:*Int = [~ [@ a:Int] *Int]
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCastErrStructInt (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot convert from Int to (x:Int y:Int)", 2, 24,
|
||||||
|
`
|
||||||
|
[main]:(x:Int y:Int) = [~ a:Int (x:Int y:Int)]
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCastErrArrayInt (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot convert from Int to 5:Int", 2, 13,
|
||||||
|
`
|
||||||
|
[main]:Int = [~ a:5:Int Int]
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCastErrSliceInt (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot convert from Int to *:Int", 2, 16,
|
||||||
|
`
|
||||||
|
[main]:*:Int = [~ a:Int *:Int]
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCast (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
Bird: ([fly distance:F64] [land])
|
||||||
|
BlueJay: Int
|
||||||
|
BlueJay::[fly distance:F64] = { }
|
||||||
|
BlueJay::[fly land] = { }
|
||||||
|
IntDerived: Int
|
||||||
|
[main] = {
|
||||||
|
a:IntDerived = 5
|
||||||
|
b:Int [~ [~ [~ a Byte] F64] Int]
|
||||||
|
c:Int [~~ [~~ [~~ a Byte] F64] Int]
|
||||||
|
d:(x:Int y:Int) = (x: 1 y: 2)
|
||||||
|
e:(z:Int a:Int) = [~~ d (z:Int a:Int)]
|
||||||
|
f:Bird = [@ [~~ 0 BlueJay]]
|
||||||
|
g:*:Int = (~ h:5:Int *:int)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
43
analyzer/function_test.go
Normal file
43
analyzer/function_test.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package analyzer
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestFunctionUniqueErrShadowBuiltin (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot shadow builtin true ", 2, 2,
|
||||||
|
`
|
||||||
|
[true]:Bool = false
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFunctionUniqueErr (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"hello already declared at stream0.fspl:2:1", 3, 1,
|
||||||
|
`
|
||||||
|
[hello] = { }
|
||||||
|
[world] = { }
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFunctionUnique (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
hello: *Int
|
||||||
|
[world] = { }
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFunctionArgumentUniqueErr (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"x already declared in block at stream0.fspl:2:8", 2, 14,
|
||||||
|
`
|
||||||
|
[main x:Int x:U8 y:Int] = { }
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFunctionArgumentUnique (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
[main x:Int y:U8 z:Int] = { }
|
||||||
|
`)
|
||||||
|
}
|
30
analyzer/literal_test.go
Normal file
30
analyzer/literal_test.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package analyzer
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestLiteralStructMemberUniqueErr (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"x already listed in struct literal at stream0.fspl:5:2", 7, 2,
|
||||||
|
`
|
||||||
|
Point: (x:Int y:Int z:Int)
|
||||||
|
[main] = {
|
||||||
|
point:Point = (
|
||||||
|
x: 5
|
||||||
|
y: 0
|
||||||
|
x: 32)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLiteralStructMemberUnique (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
Point: (x:Int y:Int z:Int)
|
||||||
|
[main] = {
|
||||||
|
point:Point = (
|
||||||
|
x: 5
|
||||||
|
y: 0
|
||||||
|
z: 32)
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
43
analyzer/method_test.go
Normal file
43
analyzer/method_test.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package analyzer
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestMethodUniqueErr (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"Bird.fly already declared at stream0.fspl:3:1", 4, 1,
|
||||||
|
`
|
||||||
|
Bird: Int
|
||||||
|
Bird::[fly] = { }
|
||||||
|
Bird::[fly distance:Int] = { }
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMethodUnique (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
Bird: Int
|
||||||
|
Bird::[fly] = { }
|
||||||
|
Bird::[land] = { }
|
||||||
|
Bird::[walk distance:Int] = { }
|
||||||
|
Bat: Int
|
||||||
|
Bat::[fly] = { }
|
||||||
|
[fly] = { }
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMethodArgumentUniqueErr (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"x already declared in block at stream0.fspl:3:13", 3, 19,
|
||||||
|
`
|
||||||
|
Bird: Int
|
||||||
|
Bird::[main x:Int x:U8 y:Int] = { }
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMethodArgumentUnique (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
Bird: Int
|
||||||
|
Bird::[main x:Int y:U8 z:Int] = { }
|
||||||
|
`)
|
||||||
|
}
|
@ -2,132 +2,6 @@ package analyzer
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestFunctionUniqueErr (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"hello already declared at stream0.fspl:2:1", 3, 1,
|
|
||||||
`
|
|
||||||
[hello] = { }
|
|
||||||
[hello] = { }
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFunctionUniqueErrShadowBuiltin (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot shadow builtin true ", 2, 2,
|
|
||||||
`
|
|
||||||
[true]:Bool = false
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFunctionUnique (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
[hello] = { }
|
|
||||||
[world] = { }
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTypeUniqueErr (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"hello already declared at stream0.fspl:2:1", 3, 1,
|
|
||||||
`
|
|
||||||
hello: *Int
|
|
||||||
hello: (x:Int y:Int)
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTypeUniqueErrShadowBuiltin (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"cannot shadow builtin true ", 2, 2,
|
|
||||||
`
|
|
||||||
true:Int
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTypeUnique (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
hello: *Int
|
|
||||||
world: (x:Int y:Int)
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTypeNameErrMissing (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"no type named example", 2, 20,
|
|
||||||
`
|
|
||||||
[main] = { example:Example }
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTypeName (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
Example: Int
|
|
||||||
AllBuiltin: (
|
|
||||||
int: Int
|
|
||||||
uint: UInt
|
|
||||||
byte: Byte
|
|
||||||
rune: Rune
|
|
||||||
string: String
|
|
||||||
i8: I8
|
|
||||||
i8: I16
|
|
||||||
i8: I32
|
|
||||||
i8: I64
|
|
||||||
u8: U8
|
|
||||||
u8: U16
|
|
||||||
u8: U32
|
|
||||||
u8: U64
|
|
||||||
f32: F32
|
|
||||||
f64: F64
|
|
||||||
bool: Bool)
|
|
||||||
[main] = {
|
|
||||||
example:Example
|
|
||||||
allBuiltin:AllBuiltin
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFunctionUniqueErr (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"hello already declared at stream0.fspl:2:1", 3, 1,
|
|
||||||
`
|
|
||||||
hello: *Int
|
|
||||||
[hello] = { }
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFunctionUnique (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
hello: *Int
|
|
||||||
[world] = { }
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMethodUniqueErr (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"Bird.fly already declared at stream0.fspl:3:1", 4, 1,
|
|
||||||
`
|
|
||||||
Bird: Int
|
|
||||||
Bird::[fly] = { }
|
|
||||||
Bird::[fly distance:Int] = { }
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMethodUnique (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
Bird: Int
|
|
||||||
Bird::[fly] = { }
|
|
||||||
Bird::[land] = { }
|
|
||||||
Bird::[walk distance:Int] = { }
|
|
||||||
Bat: Int
|
|
||||||
Bat::[fly] = { }
|
|
||||||
[fly] = { }
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMethodNameErrMissing (test *testing.T) {
|
func TestMethodNameErrMissing (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"no method Type::world", 5, 3,
|
"no method Type::world", 5, 3,
|
||||||
@ -153,82 +27,6 @@ Type::[world] = { }
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBehaviorUniqueErr (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"fly already listed in interface at stream0.fspl:2:8", 2, 14,
|
|
||||||
`
|
|
||||||
Bird: ([fly] [fly])
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBehaviorUnique (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
Bird: ([fly] [land])
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBehaviorNameErrMissing (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"no behavior Bird::swim", 8, 3,
|
|
||||||
`
|
|
||||||
Bird: ([fly] [land])
|
|
||||||
BirdImpl: Int
|
|
||||||
BirdImpl::[fly] = { }
|
|
||||||
BirdImpl::[land] = { }
|
|
||||||
[main] = {
|
|
||||||
bird:Bird = [@impl:BirdImpl]
|
|
||||||
[bird::swim]
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBehaviorName (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
Bird: ([fly] [land])
|
|
||||||
BirdImpl: Int
|
|
||||||
BirdImpl::[fly] = { }
|
|
||||||
BirdImpl::[land] = { }
|
|
||||||
[main] = {
|
|
||||||
bird:Bird = [@impl:BirdImpl]
|
|
||||||
[bird::fly]
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFunctionArgumentUniqueErr (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"x already declared in block at stream0.fspl:2:8", 2, 14,
|
|
||||||
`
|
|
||||||
[main x:Int x:U8 y:Int] = { }
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFunctionArgumentUnique (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
[main x:Int y:U8 z:Int] = { }
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMethodArgumentUniqueErr (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"x already declared in block at stream0.fspl:3:13", 3, 19,
|
|
||||||
`
|
|
||||||
Bird: Int
|
|
||||||
Bird::[main x:Int x:U8 y:Int] = { }
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMethodArgumentUnique (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
Bird: Int
|
|
||||||
Bird::[main x:Int y:U8 z:Int] = { }
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestVariableUniqueErr (test *testing.T) {
|
func TestVariableUniqueErr (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"x already declared in block at stream0.fspl:3:2", 5, 2,
|
"x already declared in block at stream0.fspl:3:2", 5, 2,
|
||||||
@ -333,79 +131,6 @@ testString (test,
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStructMemberUniqueErr (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"x already listed in struct at stream0.fspl:3:2", 6, 2,
|
|
||||||
`
|
|
||||||
Bird: (
|
|
||||||
x:Int
|
|
||||||
y:Int
|
|
||||||
z:Int
|
|
||||||
x:U8)
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStructMemberUnique (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
Bird: (
|
|
||||||
x:Int
|
|
||||||
y:Int
|
|
||||||
z:Int
|
|
||||||
a:U8)
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStructMemberNameErrMissing (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"no member Type.world", 5, 2,
|
|
||||||
`
|
|
||||||
Type: (something:Int)
|
|
||||||
[main] = {
|
|
||||||
instance:Type
|
|
||||||
instance.world = 5
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStructMemberName (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
Type: (world:Int)
|
|
||||||
[main] = {
|
|
||||||
instance:Type
|
|
||||||
instance.world = 5
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStructLiteralMemberUniqueErr (test *testing.T) {
|
|
||||||
testStringErr (test,
|
|
||||||
"x already listed in struct literal at stream0.fspl:5:2", 7, 2,
|
|
||||||
`
|
|
||||||
Point: (x:Int y:Int z:Int)
|
|
||||||
[main] = {
|
|
||||||
point:Point = (
|
|
||||||
x: 5
|
|
||||||
y: 0
|
|
||||||
x: 32)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStructLiteralMemberUnique (test *testing.T) {
|
|
||||||
testString (test,
|
|
||||||
`
|
|
||||||
Point: (x:Int y:Int z:Int)
|
|
||||||
[main] = {
|
|
||||||
point:Point = (
|
|
||||||
x: 5
|
|
||||||
y: 0
|
|
||||||
z: 32)
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFunctionNameErrType (test *testing.T) {
|
func TestFunctionNameErrType (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"cannot call named type example", 3, 3,
|
"cannot call named type example", 3, 3,
|
||||||
@ -441,3 +166,55 @@ testString (test,
|
|||||||
[main] = [example]
|
[main] = [example]
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInterfaceBehaviorNameErrMissing (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"no behavior Bird::swim", 8, 3,
|
||||||
|
`
|
||||||
|
Bird: ([fly] [land])
|
||||||
|
BirdImpl: Int
|
||||||
|
BirdImpl::[fly] = { }
|
||||||
|
BirdImpl::[land] = { }
|
||||||
|
[main] = {
|
||||||
|
bird:Bird = [@impl:BirdImpl]
|
||||||
|
[bird::swim]
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInterfaceBehaviorName (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
Bird: ([fly] [land])
|
||||||
|
BirdImpl: Int
|
||||||
|
BirdImpl::[fly] = { }
|
||||||
|
BirdImpl::[land] = { }
|
||||||
|
[main] = {
|
||||||
|
bird:Bird = [@impl:BirdImpl]
|
||||||
|
[bird::fly]
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStructMemberNameErrMissing (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"no member Type.world", 5, 2,
|
||||||
|
`
|
||||||
|
Type: (something:Int)
|
||||||
|
[main] = {
|
||||||
|
instance:Type
|
||||||
|
instance.world = 5
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStructMemberName (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
Type: (world:Int)
|
||||||
|
[main] = {
|
||||||
|
instance:Type
|
||||||
|
instance.world = 5
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
@ -2,7 +2,7 @@ package analyzer
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestOperatorModUnderArgCountErr (test *testing.T) {
|
func TestOperationModUnderArgCountErr (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"wrong argument count for %", 10, 2,
|
"wrong argument count for %", 10, 2,
|
||||||
`
|
`
|
||||||
@ -10,7 +10,7 @@ testStringErr (test,
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOperatorModOverArgCountErr (test *testing.T) {
|
func TestOperationModOverArgCountErr (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"wrong argument count for %", 10, 2,
|
"wrong argument count for %", 10, 2,
|
||||||
`
|
`
|
||||||
@ -18,7 +18,7 @@ testStringErr (test,
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOperatorLogicalNegationUnderArgCountErr (test *testing.T) {
|
func TestOperationLogicalNegationUnderArgCountErr (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"wrong argument count for !", 10, 2,
|
"wrong argument count for !", 10, 2,
|
||||||
`
|
`
|
||||||
@ -26,7 +26,7 @@ testStringErr (test,
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOperatorLogicalNegationOverArgCountErr (test *testing.T) {
|
func TestOperationLogicalNegationOverArgCountErr (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"wrong argument count for !", 10, 2,
|
"wrong argument count for !", 10, 2,
|
||||||
`
|
`
|
||||||
@ -34,7 +34,7 @@ testStringErr (test,
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOperatorBitwiseNegationUnderArgCountErr (test *testing.T) {
|
func TestOperationBitwiseNegationUnderArgCountErr (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"wrong argument count for !!", 10, 2,
|
"wrong argument count for !!", 10, 2,
|
||||||
`
|
`
|
||||||
@ -42,7 +42,7 @@ testStringErr (test,
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOperatorBitwiseNegationOverArgCountErr (test *testing.T) {
|
func TestOperationBitwiseNegationOverArgCountErr (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"wrong argument count for !!", 10, 2,
|
"wrong argument count for !!", 10, 2,
|
||||||
`
|
`
|
||||||
@ -50,7 +50,7 @@ testStringErr (test,
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOperatorBitShiftLeftUnderArgCountErr (test *testing.T) {
|
func TestOperationBitShiftLeftUnderArgCountErr (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"wrong argument count for <<", 10, 2,
|
"wrong argument count for <<", 10, 2,
|
||||||
`
|
`
|
||||||
@ -58,7 +58,7 @@ testStringErr (test,
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOperatorBitShiftLeftOverArgCountErr (test *testing.T) {
|
func TestOperationBitShiftLeftOverArgCountErr (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"wrong argument count for <<", 10, 2,
|
"wrong argument count for <<", 10, 2,
|
||||||
`
|
`
|
||||||
@ -66,7 +66,7 @@ testStringErr (test,
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOperatorBitShiftRightUnderArgCountErr (test *testing.T) {
|
func TestOperationBitShiftRightUnderArgCountErr (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"wrong argument count for >>", 10, 2,
|
"wrong argument count for >>", 10, 2,
|
||||||
`
|
`
|
||||||
@ -74,7 +74,7 @@ testStringErr (test,
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOperatorBitShiftRightOverArgCountErr (test *testing.T) {
|
func TestOperationBitShiftRightOverArgCountErr (test *testing.T) {
|
||||||
testStringErr (test,
|
testStringErr (test,
|
||||||
"wrong argument count for >>", 10, 2,
|
"wrong argument count for >>", 10, 2,
|
||||||
`
|
`
|
||||||
@ -82,7 +82,7 @@ testStringErr (test,
|
|||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOperatorArgCount (test *testing.T) {
|
func TestOperationArgCount (test *testing.T) {
|
||||||
testString (test,
|
testString (test,
|
||||||
`
|
`
|
||||||
[main] = {
|
[main] = {
|
||||||
|
102
analyzer/type_test.go
Normal file
102
analyzer/type_test.go
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package analyzer
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestTypedefUniqueErr (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"hello already declared at stream0.fspl:2:1", 3, 1,
|
||||||
|
`
|
||||||
|
hello: *Int
|
||||||
|
hello: (x:Int y:Int)
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTypedefUniqueErrShadowBuiltin (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"cannot shadow builtin true ", 2, 2,
|
||||||
|
`
|
||||||
|
true:Int
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTypedefUnique (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
hello: *Int
|
||||||
|
world: (x:Int y:Int)
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTypeNameErrMissing (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"no type named example", 2, 20,
|
||||||
|
`
|
||||||
|
[main] = { example:Example }
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestTypeName (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
Example: Int
|
||||||
|
AllBuiltin: (
|
||||||
|
int: Int
|
||||||
|
uint: UInt
|
||||||
|
byte: Byte
|
||||||
|
rune: Rune
|
||||||
|
string: String
|
||||||
|
i8: I8
|
||||||
|
i8: I16
|
||||||
|
i8: I32
|
||||||
|
i8: I64
|
||||||
|
u8: U8
|
||||||
|
u8: U16
|
||||||
|
u8: U32
|
||||||
|
u8: U64
|
||||||
|
f32: F32
|
||||||
|
f64: F64
|
||||||
|
bool: Bool)
|
||||||
|
[main] = {
|
||||||
|
example:Example
|
||||||
|
allBuiltin:AllBuiltin
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStructMemberUniqueErr (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"x already listed in struct at stream0.fspl:3:2", 6, 2,
|
||||||
|
`
|
||||||
|
Bird: (
|
||||||
|
x:Int
|
||||||
|
y:Int
|
||||||
|
z:Int
|
||||||
|
x:U8)
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStructMemberUnique (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
Bird: (
|
||||||
|
x:Int
|
||||||
|
y:Int
|
||||||
|
z:Int
|
||||||
|
a:U8)
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInterfaceBehaviorUniqueErr (test *testing.T) {
|
||||||
|
testStringErr (test,
|
||||||
|
"fly already listed in interface at stream0.fspl:2:8", 2, 14,
|
||||||
|
`
|
||||||
|
Bird: ([fly] [fly])
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInterfaceBehaviorUnique (test *testing.T) {
|
||||||
|
testString (test,
|
||||||
|
`
|
||||||
|
Bird: ([fly] [land])
|
||||||
|
`)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user