This repository has been archived on 2022-08-29. You can view files and clone it, but cannot push or open issues or pull requests.
arf/parser/parser_test.go

78 lines
1.3 KiB
Go
Raw Normal View History

2022-08-12 10:55:17 -06:00
package parser
import "io"
2022-08-12 10:55:17 -06:00
import "testing"
// import "git.tebibyte.media/sashakoshka/arf/types"
2022-08-12 10:55:17 -06:00
func checkTree (modulePath string, correct string, test *testing.T) {
2022-08-12 10:55:17 -06:00
tree, err := Parse(modulePath)
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
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
}
if treeString != correct {
test.Log("trees not equal!")
2022-08-12 10:55:17 -06:00
test.Fail()
return
}
}
func TestMeta (test *testing.T) {
checkTree ("../tests/parser/meta",
`:arf
author "Sasha Koshka"
license "GPLv3"
require "someModule"
require "otherModule"
---
`, test)
}
2022-08-15 12:23:53 -06:00
func TestData (test *testing.T) {
checkTree ("../tests/parser/data",
`:arf
---
data wr integer:Int 3202
data wr integerArray16:{Int 16}
data wr integerArrayInitialized:{Int 16}
3948
293
293049
948
912
340
0
2304
0
4785
92
data wr integerArrayVariable:{Int ..}
data wr integerPointer:{Int}
data wr integerPointerInit:{Int} [& integer]
data wr mutInteger:Int:mut 3202
data wr mutIntegerPointer:{Int}:mut
data wr mutIntegerPointerInit:{Int}:mut [& integer]
2022-08-15 12:23:53 -06:00
data wr nestedObject:Obj
.that
.bird2 123.8439
.bird3 9328.21348239
.this
.bird0 324
.bird1 "hello world"
data wr object:Obj
.this 324
.that 2139
2022-08-15 12:23:53 -06:00
`, test)
}