2022-08-12 10:55:17 -06:00
|
|
|
package parser
|
|
|
|
|
2022-08-15 12:17:29 -06:00
|
|
|
import "io"
|
2022-08-12 10:55:17 -06:00
|
|
|
import "testing"
|
2022-08-15 12:17:29 -06:00
|
|
|
// import "git.tebibyte.media/sashakoshka/arf/types"
|
2022-08-12 10:55:17 -06:00
|
|
|
|
2022-08-15 12:17:29 -06:00
|
|
|
func checkTree (modulePath string, correct string, test *testing.T) {
|
2022-08-12 10:55:17 -06:00
|
|
|
tree, err := Parse(modulePath)
|
2022-08-15 23:55:22 -06:00
|
|
|
treeString := tree.ToString(0)
|
|
|
|
|
|
|
|
test.Log("CORRECT TREE:")
|
|
|
|
test.Log(correct)
|
|
|
|
test.Log("WHAT WAS PARSED:")
|
|
|
|
test.Log(treeString)
|
2022-08-12 10:55:17 -06:00
|
|
|
|
2022-08-15 15:05:57 -06:00
|
|
|
if err != io.EOF && err != nil {
|
2022-08-12 10:55:17 -06:00
|
|
|
test.Log("returned error:")
|
|
|
|
test.Log(err.Error())
|
|
|
|
test.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-15 12:17:29 -06:00
|
|
|
if treeString != correct {
|
|
|
|
test.Log("trees not equal!")
|
2022-08-12 10:55:17 -06:00
|
|
|
test.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMeta (test *testing.T) {
|
2022-08-15 12:17:29 -06:00
|
|
|
checkTree ("../tests/parser/meta",
|
|
|
|
`:arf
|
|
|
|
author "Sasha Koshka"
|
|
|
|
license "GPLv3"
|
|
|
|
require "someModule"
|
|
|
|
require "otherModule"
|
|
|
|
---
|
|
|
|
`, test)
|
2022-08-15 12:04:57 -06:00
|
|
|
}
|
2022-08-15 12:23:53 -06:00
|
|
|
|
|
|
|
func TestData (test *testing.T) {
|
|
|
|
checkTree ("../tests/parser/data",
|
|
|
|
`:arf
|
|
|
|
---
|
|
|
|
data wr integer:Int 3202
|
2022-08-15 23:55:22 -06:00
|
|
|
data wr mutInteger:Int:mut 3202
|
2022-08-16 14:16:39 -06:00
|
|
|
data wr integerPointer:{Int}
|
|
|
|
data wr mutIntegerPointer:{Int}:mut
|
2022-08-15 12:23:53 -06:00
|
|
|
data wr integerArray16:{Int 16}
|
2022-08-16 18:24:27 -06:00
|
|
|
data wr integerArrayVariable:{Int ..}
|
2022-08-15 12:23:53 -06:00
|
|
|
data wr integerArrayInitialized:{Int 16}
|
|
|
|
3948
|
|
|
|
293
|
|
|
|
293049
|
|
|
|
948
|
|
|
|
912
|
|
|
|
340
|
|
|
|
0
|
|
|
|
2304
|
|
|
|
0
|
|
|
|
4785
|
|
|
|
92
|
2022-08-16 14:16:39 -06:00
|
|
|
data wr integerPointerInit:{Int} [& integer]
|
|
|
|
data wr mutIntegerPointerInit:{Int}:mut [& integer]
|
2022-08-15 12:23:53 -06:00
|
|
|
data wr object:Obj
|
2022-08-16 15:45:31 -06:00
|
|
|
.this 324
|
|
|
|
.that 2139
|
2022-08-15 12:23:53 -06:00
|
|
|
data wr nestedObject:Obj
|
2022-08-16 15:45:31 -06:00
|
|
|
.this
|
|
|
|
.bird0 324
|
|
|
|
.bird1 "hello world"
|
|
|
|
.that
|
|
|
|
.bird2 123.8439
|
|
|
|
.bird3 9328.21348239
|
2022-08-15 12:23:53 -06:00
|
|
|
`, test)
|
|
|
|
}
|
|
|
|
|