Added more tests to analyzer
This commit is contained in:
parent
f19e819280
commit
6b9e0f4f2d
|
@ -2,7 +2,7 @@ package analyzer
|
|||
|
||||
import "testing"
|
||||
|
||||
func TestUnique (test *testing.T) {
|
||||
func TestFunctionUnique (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"hello already declared at stream0.fspl:2:1", 3, 1,
|
||||
`
|
||||
|
@ -10,3 +10,23 @@ testStringErr (test,
|
|||
[hello] = { }
|
||||
`)
|
||||
}
|
||||
|
||||
func TestTypeUnique (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"hello already declared at stream0.fspl:2:1", 3, 1,
|
||||
`
|
||||
hello: *Int
|
||||
hello: (x:Int y:Int)
|
||||
`)
|
||||
}
|
||||
|
||||
func TestMethodUnique (test *testing.T) {
|
||||
testStringErr (test,
|
||||
"Bird.fly already declared at stream0.fspl:3:1", 5, 1,
|
||||
`
|
||||
Bird: Int
|
||||
Bird.[fly] = { }
|
||||
Bird.[land] = { }
|
||||
Bird.[fly distance:Int] = { }
|
||||
`)
|
||||
}
|
||||
|
|
|
@ -58,3 +58,25 @@ func testReaderErr (
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
func testString (test *testing.T, input string) {
|
||||
testReader(test, strings.NewReader(input))
|
||||
}
|
||||
|
||||
func testReader (test *testing.T, inputs ...io.Reader) {
|
||||
ast := parser.Tree { }
|
||||
for index, stream := range inputs {
|
||||
err := ast.Parse(fmt.Sprintf("stream%d.fspl", index), stream)
|
||||
if err != nil {
|
||||
test.Error("parser returned error: ", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
tree := Tree { }
|
||||
err := tree.Analyze(ast)
|
||||
if err != nil {
|
||||
test.Error("analyzer returned error: ", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue