-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull_test.go
More file actions
119 lines (100 loc) · 3.11 KB
/
Copy pathfull_test.go
File metadata and controls
119 lines (100 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"cuteify/compile"
packageSys "cuteify/package"
"cuteify/parser"
typeSys "cuteify/type"
"testing"
)
func TestAliasType(t *testing.T) {
// True alias
alias := typeSys.NewAlias("MyInt", typeSys.GetSystemType("int"), true)
if alias.Kind() != "int" {
t.Errorf("AliasType.Kind() = %s, want int", alias.Kind())
}
if alias.Size() != typeSys.GetSystemType("int").Size() {
t.Errorf("AliasType.Size() = %d, want %d", alias.Size(), typeSys.GetSystemType("int").Size())
}
if alias.Type() != "MyInt" {
t.Errorf("AliasType.Type() = %s, want MyInt", alias.Type())
}
// New type (not true alias)
newType := typeSys.NewAlias("MyInt2", typeSys.GetSystemType("int"), false)
if newType.Kind() != "int" {
t.Errorf("NewType.Kind() = %s, want int", newType.Kind())
}
// Methods inheritance for true alias
// (methods would be inherited from underlying type)
// Methods merge for new type
// (methods would be merged from self and underlying)
}
func TestAliasTypeWithList(t *testing.T) {
listType := typeSys.NewList(typeSys.GetSystemType("int"))
alias := typeSys.NewAlias("MyList", listType, true)
if alias.Kind() != "list" {
t.Errorf("AliasType.Kind() = %s, want list", alias.Kind())
}
if alias.Elem().Kind() != "int" {
t.Errorf("AliasType.Elem().Kind() = %s, want int", alias.Elem().Kind())
}
}
func TestAliasTypeWithStruct(t *testing.T) {
structType := typeSys.NewStruct("Point", typeSys.StructFileds{
{Name: "x", Type: typeSys.GetSystemType("int")},
{Name: "y", Type: typeSys.GetSystemType("int")},
})
alias := typeSys.NewAlias("MyPoint", structType, true)
if alias.Kind() != "struct" {
t.Errorf("AliasType.Kind() = %s, want struct", alias.Kind())
}
if len(alias.Fields()) != 2 {
t.Errorf("AliasType.Fields() length = %d, want 2", len(alias.Fields()))
}
}
func TestFullSyntaxParse(t *testing.T) {
tmp, err := packageSys.GetPackage("./test/full_syntax_test", true)
if err != nil {
t.Fatal(err)
}
// Verify AST was parsed
if tmp.AST == nil {
t.Fatal("AST is nil")
}
node := tmp.AST.(*parser.Node)
if len(node.Children) == 0 {
t.Fatal("No children in AST")
}
}
func TestFullSyntaxCompile(t *testing.T) {
tmp, err := packageSys.GetPackage("./test/full_syntax_test", true)
if err != nil {
t.Fatal(err)
}
co := &compile.Compiler{}
code := co.Compile(tmp.AST.(*parser.Node))
if code == "" {
t.Error("Compile returned empty code")
}
// Print generated code for inspection
t.Logf("Generated code:\n%s", code)
}
func TestNameWithSlice(t *testing.T) {
// Test that Name can parse slices
// This is tested indirectly through the full syntax test
}
func TestAllTypeMethods(t *testing.T) {
// Test that all types have Methods()
intType := typeSys.GetSystemType("int")
if intType.Methods() == nil {
// Should return empty slice, not nil
t.Log("intType.Methods() is nil (acceptable)")
}
listType := typeSys.NewList(typeSys.GetSystemType("int"))
if listType.Methods() == nil {
t.Log("listType.Methods() is nil (acceptable)")
}
structType := typeSys.NewStruct("Test", typeSys.StructFileds{})
if structType.Methods() == nil {
t.Log("structType.Methods() is nil (acceptable)")
}
}