From bc9beb0317162df69368f5683d15107284f6dcbd Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 18 Aug 2022 16:56:42 -0400 Subject: [PATCH] Created test case for type section --- parser/parser_test.go | 33 +++++++++++++++++++++++++++++++++ parser/tree.go | 23 ++++++++++++++++++++++- tests/parser/type/main.arf | 27 +++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 tests/parser/type/main.arf diff --git a/parser/parser_test.go b/parser/parser_test.go index 221084f..fb87077 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -109,3 +109,36 @@ data ro object:Obj `, 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 + +type ro Complex:Obj + ro that:Basic + ro this:Basic + +type ro ComplexInit:Obj + ro that:BasicInit + ro this:Basic 23 + +type ro ComplexWithComplexInit + ro basic:Basic 87 + ro complex0:Complex + .that 98 + .this 2 + ro complex1:Complex + .that 98902 + .this 235 +`, test) +} + diff --git a/parser/tree.go b/parser/tree.go index 9ef87e7..070f36a 100644 --- a/parser/tree.go +++ b/parser/tree.go @@ -156,6 +156,27 @@ type DataSection struct { name string what Type - value Argument permission types.Permission + value Argument +} + +// TypeMember represents member data +type TypeMember struct { + location file.Location + name string + + what Type + permission types.Permission + defaultValue Argument +} + +// TypeSection represents a type definition. +type TypeSection struct { + location file.Location + name string + + what Type + permission types.Permission + // this should be 1 dimensional for now. + members map[string] TypeMember } diff --git a/tests/parser/type/main.arf b/tests/parser/type/main.arf new file mode 100644 index 0000000..b4085bb --- /dev/null +++ b/tests/parser/type/main.arf @@ -0,0 +1,27 @@ +:arf +--- +type ro Basic:Int + +type ro BasicInit:Int 6 + +type ro IntArray:{Int ..} + +type ro IntArrayInit:{Int 3} + 3298 923 92 + +type ro Complex:Obj + ro that:Basic + ro this:Basic + +type ro ComplexInit:Obj + ro that:BasicInit + ro this:Basic 23 + +type ro ComplexWithComplexInit + ro complex0:Complex + .that 98 + .this 2 + ro complex1:Complex + .that 98902 + .this 235 + ro basic:Basic 87