data-section #3

Merged
sashakoshka merged 42 commits from data-section into main 2022-08-17 18:21:20 +00:00
1 changed files with 19 additions and 80 deletions
Showing only changes of commit 00bcfaab0b - Show all commits

View File

@ -1,21 +1,26 @@
package parser package parser
import "reflect" import "io"
import "testing" import "testing"
import "git.tebibyte.media/sashakoshka/arf/types" // import "git.tebibyte.media/sashakoshka/arf/types"
func checkTree (modulePath string, correct *SyntaxTree, test *testing.T) { func checkTree (modulePath string, correct string, test *testing.T) {
tree, err := Parse(modulePath) tree, err := Parse(modulePath)
if err != nil { if err != io.EOF {
test.Log("returned error:") test.Log("returned error:")
test.Log(err.Error()) test.Log(err.Error())
test.Fail() test.Fail()
return return
} }
if !reflect.DeepEqual(tree, correct) { treeString := tree.ToString(0)
test.Log("trees not equal") if treeString != correct {
test.Log("trees not equal!")
test.Log("CORRECT TREE:")
test.Log(correct)
test.Log("WHAT WAS PARSED:")
test.Log(treeString)
test.Fail() test.Fail()
return return
} }
@ -37,79 +42,13 @@ func quickIdentifier (trail ...string) (identifier Identifier) {
} }
func TestMeta (test *testing.T) { func TestMeta (test *testing.T) {
checkTree ("../tests/parser/meta", &SyntaxTree {
license: "GPLv3",
author: "Sasha Koshka",
requires: []string { checkTree ("../tests/parser/meta",
"someModule", `:arf
"otherModule", author "Sasha Koshka"
}, license "GPLv3"
}, test) require "someModule"
} require "otherModule"
---
func TestData (test *testing.T) { `, test)
tree := &SyntaxTree {
dataSections: []DataSection {
DataSection {
name: "integer",
permission: types.PermissionFrom("wr"),
what: Type {
kind: TypeKindBasic,
name: quickIdentifier("Int"),
},
value: []Argument {
Argument {
what: ArgumentKindUInt,
value: 3202,
},
},
},
DataSection {
name: "integerPointer",
permission: types.PermissionFrom("wr"),
what: Type {
kind: TypeKindPointer,
points: &Type {
kind: TypeKindBasic,
name: quickIdentifier("Int"),
},
},
value: []Argument {
Argument {
what: ArgumentKindUInt,
value: 3202,
},
},
},
DataSection {
name: "integerArray16",
permission: types.PermissionFrom("wr"),
what: Type {
kind: TypeKindArray,
points: &Type {
kind: TypeKindBasic,
name: quickIdentifier("Int"),
},
length: Argument {
what: ArgumentKindUInt,
value: 16,
}
},
value: []Argument {
Argument {
what: ArgumentKindUInt,
value: 3202,
},
},
},
},
}
checkTree ("../tests/parser/data", tree, test)
} }