fspl/analyzer/name_test.go

206 lines
2.8 KiB
Go

package analyzer
import "testing"
func TestMethodNameErrMissing (test *testing.T) {
testStringErr (test,
"no method named world defined on this type", 6, 10,
`
Type: Int
Type.[something] = { }
[main] = {
instance:Type
instance.[world]
}
`)
}
func TestMethodNameErrBadLayer (test *testing.T) {
testStringErr (test,
"no method named something defined on this type", 7, 10,
`
Type: Int
Type.[something] = { }
RefType: *Type
[main] = {
instance:RefType
instance.[something]
}
`)
}
func TestMethodName (test *testing.T) {
testString (test,
`
Type: Int
Type.[world] = { }
[main] = {
instance:Type
instance.[world]
ref:*Type = [@ instance]
ref.[world]
}
`)
}
func TestVariableUniqueErr (test *testing.T) {
testStringErr (test,
"x already declared in block at stream0.fspl:3:2", 5, 2,
`
[main] = {
x:Int
{ x:U8 }
x:U8
}
`)
}
func TestVariableUnique (test *testing.T) {
testString (test,
`
[x] = { }
[y] = { }
[main x:Int] = {
x:Int
y:Int
{
x:U8
y:U8
}
z:Int
}
`)
}
func TestVariableNameErrFunction (test *testing.T) {
testStringErr (test,
"no variable named example", 4, 2,
`
[example] = { }
[main] = {
example = 5
}
`)
}
func TestVariableNameErrMissing (test *testing.T) {
testStringErr (test,
"no variable named example", 3, 2,
`
[main] = {
example = 5
}
`)
}
func TestVariableNameErrNotInScope (test *testing.T) {
testStringErr (test,
"no variable named example", 6, 2,
`
[main] = {
{
example:Int
}
example = 5
}
`)
}
func TestVariableName (test *testing.T) {
testString (test,
`
[main] = {
example:Int
example = 5
{
example = 2
x:Int
x = 5
{
x = 2
example = 3
}
}
}
`)
}
func TestFunctionNameErrVar (test *testing.T) {
testStringErr (test,
"no function named example", 4, 2,
`
[main] = {
example:Int
[example]
}
`)
}
func TestFunctionNameErrMissing (test *testing.T) {
testStringErr (test,
"no function named example", 2, 10,
`
[main] = [example]
`)
}
func TestFunctionName (test *testing.T) {
testString (test,
`
[example] = { }
[main] = [example]
`)
}
func TestInterfaceBehaviorNameErrMissing (test *testing.T) {
testStringErr (test,
"no behavior or method named swim", 8, 6,
`
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 instance.world", 5, 10,
`
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
}
`)
}