220 lines
3.8 KiB
Go
220 lines
3.8 KiB
Go
package analyzer
|
|
|
|
import "testing"
|
|
|
|
func TestTwoUnit (test *testing.T) {
|
|
testUnits (test,
|
|
`[main]:something::X = 5`,
|
|
|
|
"something.fspl",
|
|
`+ X:Int`,
|
|
)}
|
|
|
|
func TestUnitPrivateTypeErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::X is private", 1, 8,
|
|
`[main]:other::X = 5`,
|
|
|
|
"other.fspl",
|
|
`- X:Int`,
|
|
)}
|
|
|
|
func TestUnitPrivateFunctionErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "function other::[x] is private", 1, 11,
|
|
`[y]:Int = other::[x]`,
|
|
|
|
"other.fspl",
|
|
`- [x]:Int = 5`,
|
|
)}
|
|
|
|
func TestUnitPrivateMethodErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "method T.[x] is private", 1, 21,
|
|
`[y]:Int = z:other::T.[x]`,
|
|
|
|
"other.fspl",
|
|
`
|
|
+ T:Int
|
|
- T.[x]:Int = 5`,
|
|
)}
|
|
|
|
func TestUnitAssignOpaque (test *testing.T) {
|
|
testUnits (test,
|
|
`[main] = {
|
|
x:other::OpaqueInt
|
|
y:other::OpaqueInt
|
|
x = y
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`# OpaqueInt:Int`,
|
|
)}
|
|
|
|
func TestUnitAssignLiteralOpaqueErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::OpaqueInt is opaque", 1, 27,
|
|
`[main]:other::OpaqueInt = 5`,
|
|
|
|
"other.fspl",
|
|
`# OpaqueInt:Int`,
|
|
)}
|
|
|
|
func TestAssignLiteralOpaque (test *testing.T) {
|
|
testString (test,
|
|
`# OpaqueInt:Int
|
|
[main]:OpaqueInt = 5`,
|
|
)}
|
|
|
|
func TestUnitMemberAccessOpaqueErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::OpaqueStruct is opaque", 3, 3,
|
|
`[main] = {
|
|
x:other::OpaqueStruct
|
|
x.x = 5
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`# OpaqueStruct:(. x:Int y:Int)`,
|
|
)}
|
|
|
|
func TestMemberAccessOpaque (test *testing.T) {
|
|
testString (test,
|
|
`# OpaqueStruct:(. x:Int y:Int)
|
|
[main] = {
|
|
x:OpaqueStruct
|
|
x.x = 5
|
|
}`,
|
|
)}
|
|
|
|
func TestUnitSubscriptOpaqueErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::OpaqueArr is opaque", 3, 4,
|
|
`[main] = {
|
|
x:other::OpaqueArr
|
|
[.x 0] = 5
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`# OpaqueArr:5:Int`,
|
|
)}
|
|
|
|
func TestSubscriptOpaque (test *testing.T) {
|
|
testString (test,
|
|
`# OpaqueArr:5:Int
|
|
[main] = {
|
|
x:OpaqueArr
|
|
[.x 0] = 5
|
|
}`,
|
|
)}
|
|
|
|
func TestUnitMathOpaqueErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::OpaqueInt is opaque", 2, 23,
|
|
`[main] = {
|
|
x:other::OpaqueInt = [+
|
|
y:other::OpaqueInt
|
|
z:other::OpaqueInt]
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`# OpaqueInt:Int`,
|
|
)}
|
|
|
|
func TestMathOpaque (test *testing.T) {
|
|
testString (test,
|
|
`# OpaqueInt:Int
|
|
[main] = {
|
|
x:OpaqueInt = [+
|
|
y:OpaqueInt
|
|
z:OpaqueInt]
|
|
}`,
|
|
)}
|
|
|
|
func TestNestedUnitTypedef (test *testing.T) {
|
|
testUnits (test,
|
|
`[main]:layer1::X = 5`,
|
|
|
|
"layer0.fspl",
|
|
`+ X:Int`,
|
|
|
|
"layer1.fspl",
|
|
`+ X:layer0::X`,
|
|
)}
|
|
|
|
func TestUnitBehaviorCallOpaqueErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::OpaqueInterface is opaque", 3, 3,
|
|
`[main] = {
|
|
x:other::OpaqueInterface
|
|
x.[y]
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`# OpaqueInterface:(& [y])`,
|
|
)}
|
|
|
|
func TestBehaviorCallOpaque (test *testing.T) {
|
|
testString (test,
|
|
`[main] = {
|
|
x:OpaqueInterface
|
|
x.[y]
|
|
}
|
|
# OpaqueInterface:(& [y])`,
|
|
)}
|
|
|
|
func TestUnitCastOpaqueErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::OpaqueInt is opaque", 2, 16,
|
|
`[main] = {
|
|
x:Int = [~Int y:other::OpaqueInt]
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`# OpaqueInt:Int`,
|
|
)}
|
|
|
|
func TestCastOpaque (test *testing.T) {
|
|
testString (test,
|
|
`[main] = {
|
|
x:Int = [~Int y:OpaqueInt]
|
|
}
|
|
# OpaqueInt:Int`,
|
|
)}
|
|
|
|
func TestFunctionOpaqueErr (test *testing.T) {
|
|
testStringErr (test,
|
|
"cannot mark function as opaque", 1, 1,
|
|
`# [f]`,
|
|
)}
|
|
|
|
func TestMethodOpaqueErr (test *testing.T) {
|
|
testStringErr (test,
|
|
"cannot mark method as opaque", 2, 1,
|
|
`T:Int
|
|
# T.[f]`,
|
|
)}
|
|
|
|
func TestUnitInterfaceSatisfaction (test *testing.T) {
|
|
testUnits (test,
|
|
`[sayHello writer:io::Writer] = writer.[write 'well hello their\n']
|
|
|
|
[main]: I32 'main' = {
|
|
stdout:io::File = 1
|
|
[sayHello stdout]
|
|
0
|
|
}`,
|
|
|
|
"cstdio.fspl",
|
|
`+ FileDescriptor: Int
|
|
+ [write file:FileDescriptor buffer:*Byte count:Index]: Index 'write'`,
|
|
|
|
"io.fspl",
|
|
`+ Writer: (& [write buffer:*:Byte]: Index)
|
|
+ File: cstdio::FileDescriptor
|
|
+ File.[write buffer:*:Byte]:Index =
|
|
cstdio::[write
|
|
[~cstdio::FileDescriptor [.this]]
|
|
[~*Byte buffer] [#buffer]]`,
|
|
)}
|