220 lines
4.0 KiB
Go
220 lines
4.0 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 TestUnitAssignRestricted (test *testing.T) {
|
|
testUnits (test,
|
|
`[main] = {
|
|
x:other::RestrictedInt
|
|
y:other::RestrictedInt
|
|
x = y
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`~ RestrictedInt:Int`,
|
|
)}
|
|
|
|
func TestUnitAssignLiteralRestrictedErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::RestrictedInt is restricted", 1, 31,
|
|
`[main]:other::RestrictedInt = 5`,
|
|
|
|
"other.fspl",
|
|
`~ RestrictedInt:Int`,
|
|
)}
|
|
|
|
func TestAssignLiteralRestricted (test *testing.T) {
|
|
testString (test,
|
|
`~ RestrictedInt:Int
|
|
[main]:RestrictedInt = 5`,
|
|
)}
|
|
|
|
func TestUnitMemberAccessRestrictedErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::RestrictedStruct is restricted", 3, 3,
|
|
`[main] = {
|
|
x:other::RestrictedStruct
|
|
x.x = 5
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`~ RestrictedStruct:(. x:Int y:Int)`,
|
|
)}
|
|
|
|
func TestMemberAccessRestricted (test *testing.T) {
|
|
testString (test,
|
|
`~ RestrictedStruct:(. x:Int y:Int)
|
|
[main] = {
|
|
x:RestrictedStruct
|
|
x.x = 5
|
|
}`,
|
|
)}
|
|
|
|
func TestUnitSubscriptRestrictedErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::RestrictedArr is restricted", 3, 4,
|
|
`[main] = {
|
|
x:other::RestrictedArr
|
|
[.x 0] = 5
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`~ RestrictedArr:5:Int`,
|
|
)}
|
|
|
|
func TestSubscriptRestricted (test *testing.T) {
|
|
testString (test,
|
|
`~ RestrictedArr:5:Int
|
|
[main] = {
|
|
x:RestrictedArr
|
|
[.x 0] = 5
|
|
}`,
|
|
)}
|
|
|
|
func TestUnitMathRestrictedErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::RestrictedInt is restricted", 2, 27,
|
|
`[main] = {
|
|
x:other::RestrictedInt = [+
|
|
y:other::RestrictedInt
|
|
z:other::RestrictedInt]
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`~ RestrictedInt:Int`,
|
|
)}
|
|
|
|
func TestMathRestricted (test *testing.T) {
|
|
testString (test,
|
|
`~ RestrictedInt:Int
|
|
[main] = {
|
|
x:RestrictedInt = [+
|
|
y:RestrictedInt
|
|
z:RestrictedInt]
|
|
}`,
|
|
)}
|
|
|
|
func TestNestedUnitTypedef (test *testing.T) {
|
|
testUnits (test,
|
|
`[main]:layer1::X = 5`,
|
|
|
|
"layer0.fspl",
|
|
`+ X:Int`,
|
|
|
|
"layer1.fspl",
|
|
`+ X:layer0::X`,
|
|
)}
|
|
|
|
func TestUnitBehaviorCallRestrictedErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::RestrictedInterface is restricted", 3, 3,
|
|
`[main] = {
|
|
x:other::RestrictedInterface
|
|
x.[y]
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`~ RestrictedInterface:(~ [y])`,
|
|
)}
|
|
|
|
func TestBehaviorCallRestricted (test *testing.T) {
|
|
testString (test,
|
|
`[main] = {
|
|
x:RestrictedInterface
|
|
x.[y]
|
|
}
|
|
~ RestrictedInterface:(~ [y])`,
|
|
)}
|
|
|
|
func TestUnitCastRestrictedErr (test *testing.T) {
|
|
testUnitsErr (test,
|
|
"main.fspl", "type other::RestrictedInt is restricted", 2, 16,
|
|
`[main] = {
|
|
x:Int = [~Int y:other::RestrictedInt]
|
|
}`,
|
|
|
|
"other.fspl",
|
|
`~ RestrictedInt:Int`,
|
|
)}
|
|
|
|
func TestCastRestricted (test *testing.T) {
|
|
testString (test,
|
|
`[main] = {
|
|
x:Int = [~Int y:RestrictedInt]
|
|
}
|
|
~ RestrictedInt:Int`,
|
|
)}
|
|
|
|
func TestFunctionRestrictedErr (test *testing.T) {
|
|
testStringErr (test,
|
|
"cannot mark function as restricted", 1, 1,
|
|
`~ [f]`,
|
|
)}
|
|
|
|
func TestMethodRestrictedErr (test *testing.T) {
|
|
testStringErr (test,
|
|
"cannot mark method as restricted", 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]]`,
|
|
)}
|