2022-08-12 16:55:17 +00:00
|
|
|
package parser
|
|
|
|
|
2022-08-15 18:17:29 +00:00
|
|
|
import "io"
|
2022-08-12 16:55:17 +00:00
|
|
|
import "testing"
|
2022-08-15 18:17:29 +00:00
|
|
|
// import "git.tebibyte.media/sashakoshka/arf/types"
|
2022-08-12 16:55:17 +00:00
|
|
|
|
2022-08-15 18:17:29 +00:00
|
|
|
func checkTree (modulePath string, correct string, test *testing.T) {
|
2022-08-12 16:55:17 +00:00
|
|
|
tree, err := Parse(modulePath)
|
|
|
|
|
2022-08-15 18:17:29 +00:00
|
|
|
if err != io.EOF {
|
2022-08-12 16:55:17 +00:00
|
|
|
test.Log("returned error:")
|
|
|
|
test.Log(err.Error())
|
|
|
|
test.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-15 18:17:29 +00:00
|
|
|
treeString := tree.ToString(0)
|
|
|
|
if treeString != correct {
|
|
|
|
test.Log("trees not equal!")
|
|
|
|
test.Log("CORRECT TREE:")
|
|
|
|
test.Log(correct)
|
|
|
|
test.Log("WHAT WAS PARSED:")
|
|
|
|
test.Log(treeString)
|
2022-08-12 16:55:17 +00:00
|
|
|
test.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-15 18:04:57 +00:00
|
|
|
// quickIdentifier returns a simple identifier of names
|
|
|
|
func quickIdentifier (trail ...string) (identifier Identifier) {
|
|
|
|
for _, item := range trail {
|
|
|
|
identifier.trail = append (
|
|
|
|
identifier.trail,
|
|
|
|
Argument {
|
|
|
|
what: ArgumentKindString,
|
|
|
|
value: item,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-12 16:55:17 +00:00
|
|
|
func TestMeta (test *testing.T) {
|
|
|
|
|
2022-08-15 18:17:29 +00:00
|
|
|
checkTree ("../tests/parser/meta",
|
|
|
|
`:arf
|
|
|
|
author "Sasha Koshka"
|
|
|
|
license "GPLv3"
|
|
|
|
require "someModule"
|
|
|
|
require "otherModule"
|
|
|
|
---
|
|
|
|
`, test)
|
2022-08-15 18:04:57 +00:00
|
|
|
}
|