From b64fbd9fc472eb1cc1db0024a240f5c5e13920dc Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 24 Aug 2022 01:22:24 -0400 Subject: [PATCH] Split tests into multiple files This should make it easier to work on sections independantly of one another without creating merge conflicts --- face_test.go | 21 +++++ parser/data_test.go | 38 ++++++++ parser/enum_test.go | 38 ++++++++ parser/meta_test.go | 14 +++ parser/objt_test.go | 28 ++++++ parser/parser_test.go | 212 ------------------------------------------ parser/test-common.go | 74 +++++++++++++++ parser/type_test.go | 17 ++++ 8 files changed, 230 insertions(+), 212 deletions(-) create mode 100644 face_test.go create mode 100644 parser/data_test.go create mode 100644 parser/enum_test.go create mode 100644 parser/meta_test.go create mode 100644 parser/objt_test.go delete mode 100644 parser/parser_test.go create mode 100644 parser/test-common.go create mode 100644 parser/type_test.go diff --git a/face_test.go b/face_test.go new file mode 100644 index 0000000..815c3cf --- /dev/null +++ b/face_test.go @@ -0,0 +1,21 @@ +package parser + +import "testing" + +func TestFace (test *testing.T) { + checkTree ("../tests/parser/face", +`:arf +--- +face ro Destroyer:Face + destroy +face ro ReadWriter:Face + read + > into:{Byte ..} + < read:Int + < err:Error + write + > data:{Byte ..} + < wrote:Int + < err:Error +`, test) +} diff --git a/parser/data_test.go b/parser/data_test.go new file mode 100644 index 0000000..9518e8c --- /dev/null +++ b/parser/data_test.go @@ -0,0 +1,38 @@ +package parser + +import "testing" + +func TestData (test *testing.T) { + checkTree ("../tests/parser/data", +`:arf +--- +data ro integer:Int 3202 +data ro integerArray16:{Int 16} +data ro integerArrayInitialized:{Int 16} + 3948 + 293 + 293049 + 948 + 912 + 340 + 0 + 2304 + 0 + 4785 + 92 +data ro integerArrayVariable:{Int ..} +data ro integerPointer:{Int} +data ro mutInteger:Int:mut 3202 +data ro mutIntegerPointer:{Int}:mut +data ro nestedObject:Obj + .that + .bird2 123.8439 + .bird3 9328.21348239 + .this + .bird0 324 + .bird1 "hello world" +data ro object:Obj + .that 2139 + .this 324 +`, test) +} diff --git a/parser/enum_test.go b/parser/enum_test.go new file mode 100644 index 0000000..7857387 --- /dev/null +++ b/parser/enum_test.go @@ -0,0 +1,38 @@ +package parser + +import "testing" + +func TestEnum (test *testing.T) { + checkTree ("../tests/parser/enum", +`:arf +--- +enum ro AffrontToGod:{Int 4} + bird0 + 28394 + 9328 + 398 + 9 + bird1 + 23 + 932832 + 398 + 2349 + bird2 + 1 + 2 + 3 + 4 +enum ro NamedColor:U32 + red 16711680 + green 65280 + blue 255 +enum ro Weekday:Int + sunday + monday + tuesday + wednesday + thursday + friday + saturday +`, test) +} diff --git a/parser/meta_test.go b/parser/meta_test.go new file mode 100644 index 0000000..36cc1f4 --- /dev/null +++ b/parser/meta_test.go @@ -0,0 +1,14 @@ +package parser + +import "testing" + +func TestMeta (test *testing.T) { + checkTree ("../tests/parser/meta", +`:arf +author "Sasha Koshka" +license "GPLv3" +require "someModule" +require "otherModule" +--- +`, test) +} diff --git a/parser/objt_test.go b/parser/objt_test.go new file mode 100644 index 0000000..68a4337 --- /dev/null +++ b/parser/objt_test.go @@ -0,0 +1,28 @@ +package parser + +import "testing" + +func TestObjt (test *testing.T) { + checkTree ("../tests/parser/objt", +`:arf +--- +objt ro Basic:Obj + ro that:Basic + ro this:Basic +objt ro ComplexInit:Obj + ro basic:Int 87 + ro complex0:Bird + .that 98 + .this 2 + ro complex1:Bird + .that 98902 + .this 235 + ro whatever:{Int 3} + 230984 + 849 + 394580 +objt ro Init:Obj + ro that:String "hello world" + ro this:Int 23 +`, test) +} diff --git a/parser/parser_test.go b/parser/parser_test.go deleted file mode 100644 index 133fbd2..0000000 --- a/parser/parser_test.go +++ /dev/null @@ -1,212 +0,0 @@ -package parser - -import "io" -import "strings" -import "testing" -// import "git.tebibyte.media/sashakoshka/arf/types" - -func checkTree (modulePath string, correct string, test *testing.T) { - tree, err := Parse(modulePath) - treeString := tree.ToString(0) - treeRunes := []rune(treeString) - - test.Log("CORRECT TREE:") - logWithLineNumbers(correct, test) - test.Log("WHAT WAS PARSED:") - logWithLineNumbers(treeString, test) - - if err != io.EOF && err != nil { - test.Log("returned error:") - test.Log(err.Error()) - test.Fail() - return - } - - equal := true - line := 0 - column := 0 - - for index, correctChar := range correct { - if index >= len(treeRunes) { - test.Log ( - "parsed is too short at line", line + 1, - "col", column + 1) - test.Fail() - return - } - - if correctChar != treeRunes[index] { - test.Log ( - "trees not equal at line", line + 1, - "col", column + 1) - test.Log("correct: [" + string(correctChar) + "]") - test.Log("got: [" + string(treeRunes[index]) + "]") - test.Fail() - return - } - - if correctChar == '\n' { - line ++ - column = 0 - } else { - column ++ - } - } - - if len(treeString) > len(correct) { - test.Log("parsed is too long") - test.Fail() - return - } - - if !equal { - return - } -} - -func logWithLineNumbers (bigString string, test *testing.T) { - lines := strings.Split ( - strings.Replace(bigString, "\t", " ", -1), "\n") - - for index, line := range lines { - test.Logf("%3d | %s", index + 1, line) - } -} - -func TestMeta (test *testing.T) { - checkTree ("../tests/parser/meta", -`:arf -author "Sasha Koshka" -license "GPLv3" -require "someModule" -require "otherModule" ---- -`, test) -} - -func TestData (test *testing.T) { - checkTree ("../tests/parser/data", -`:arf ---- -data ro integer:Int 3202 -data ro integerArray16:{Int 16} -data ro integerArrayInitialized:{Int 16} - 3948 - 293 - 293049 - 948 - 912 - 340 - 0 - 2304 - 0 - 4785 - 92 -data ro integerArrayVariable:{Int ..} -data ro integerPointer:{Int} -data ro mutInteger:Int:mut 3202 -data ro mutIntegerPointer:{Int}:mut -data ro nestedObject:Obj - .that - .bird2 123.8439 - .bird3 9328.21348239 - .this - .bird0 324 - .bird1 "hello world" -data ro object:Obj - .that 2139 - .this 324 -`, test) -} - -func TestType (test *testing.T) { - checkTree ("../tests/parser/type", -`:arf ---- -type ro Basic:Int -type ro BasicInit:Int 6 -type ro IntArray:{Int ..} -type ro IntArrayInit:{Int 3} - 3298 - 923 - 92 -`, test) -} - -func TestObjt (test *testing.T) { - checkTree ("../tests/parser/objt", -`:arf ---- -objt ro Basic:Obj - ro that:Basic - ro this:Basic -objt ro ComplexInit:Obj - ro basic:Int 87 - ro complex0:Bird - .that 98 - .this 2 - ro complex1:Bird - .that 98902 - .this 235 - ro whatever:{Int 3} - 230984 - 849 - 394580 -objt ro Init:Obj - ro that:String "hello world" - ro this:Int 23 -`, test) -} - -func TestEnum (test *testing.T) { - checkTree ("../tests/parser/enum", -`:arf ---- -enum ro AffrontToGod:{Int 4} - bird0 - 28394 - 9328 - 398 - 9 - bird1 - 23 - 932832 - 398 - 2349 - bird2 - 1 - 2 - 3 - 4 -enum ro NamedColor:U32 - red 16711680 - green 65280 - blue 255 -enum ro Weekday:Int - sunday - monday - tuesday - wednesday - thursday - friday - saturday -`, test) -} - -func Test (test *testing.T) { - checkTree ("../tests/parser/face", -`:arf ---- -face ro Destroyer:Face - destroy -face ro ReadWriter:Face - read - > into:{Byte ..} - < read:Int - < err:Error - write - > data:{Byte ..} - < wrote:Int - < err:Error -`, test) -} diff --git a/parser/test-common.go b/parser/test-common.go new file mode 100644 index 0000000..8bea0c2 --- /dev/null +++ b/parser/test-common.go @@ -0,0 +1,74 @@ +package parser + +import "io" +import "strings" +import "testing" +// import "git.tebibyte.media/sashakoshka/arf/types" + +func checkTree (modulePath string, correct string, test *testing.T) { + tree, err := Parse(modulePath) + treeString := tree.ToString(0) + treeRunes := []rune(treeString) + + test.Log("CORRECT TREE:") + logWithLineNumbers(correct, test) + test.Log("WHAT WAS PARSED:") + logWithLineNumbers(treeString, test) + + if err != io.EOF && err != nil { + test.Log("returned error:") + test.Log(err.Error()) + test.Fail() + return + } + + equal := true + line := 0 + column := 0 + + for index, correctChar := range correct { + if index >= len(treeRunes) { + test.Log ( + "parsed is too short at line", line + 1, + "col", column + 1) + test.Fail() + return + } + + if correctChar != treeRunes[index] { + test.Log ( + "trees not equal at line", line + 1, + "col", column + 1) + test.Log("correct: [" + string(correctChar) + "]") + test.Log("got: [" + string(treeRunes[index]) + "]") + test.Fail() + return + } + + if correctChar == '\n' { + line ++ + column = 0 + } else { + column ++ + } + } + + if len(treeString) > len(correct) { + test.Log("parsed is too long") + test.Fail() + return + } + + if !equal { + return + } +} + +func logWithLineNumbers (bigString string, test *testing.T) { + lines := strings.Split ( + strings.Replace(bigString, "\t", " ", -1), "\n") + + for index, line := range lines { + test.Logf("%3d | %s", index + 1, line) + } +} diff --git a/parser/type_test.go b/parser/type_test.go new file mode 100644 index 0000000..3221737 --- /dev/null +++ b/parser/type_test.go @@ -0,0 +1,17 @@ +package parser + +import "testing" + +func TestType (test *testing.T) { + checkTree ("../tests/parser/type", +`:arf +--- +type ro Basic:Int +type ro BasicInit:Int 6 +type ro IntArray:{Int ..} +type ro IntArrayInit:{Int 3} + 3298 + 923 + 92 +`, test) +}