fspl/analyzer/multiunit_test.go

144 lines
2.5 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 RestrictedInt is restricted", 0, 0,
`[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 RestrictedStruct is restricted", 0, 0,
`[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 RestrictedArr is restricted", 0, 0,
`[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 RestrictedInt is restricted", 0, 0,
`[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`,
)}