-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_test.go
147 lines (126 loc) · 3.3 KB
/
data_test.go
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package wfobj
// This is a invalid 3d object
// but it's a syntatic valid .obj file
// so for the purpose of these testing
// this just works
type TestData struct {
title string
ignore bool
mesh *Mesh
tokens []Token
objlit string
}
var testdata = []TestData{
{
title: "Simple mesh",
ignore: false,
mesh: &Mesh{
[]Face{
Face{VertexList{Vertex{1.0, 1.0, 1.0}, Vertex{0.0, 1.0, 0.0}}, VertexList{}},
Face{VertexList{Vertex{0.0, 1.0, 0.0}, Vertex{1.0, 1.0, 1.0}}, VertexList{}},
},
},
objlit: `# comment
v 1.0 1.0 1.0
v 0.0 1.0 0.0
f 1 2
f 2 1
`,
tokens: []Token{
// Vertex
Token{"", VertexDecl, Position{}},
Token{"1.0", NumberLit, Position{}},
Token{"1.0", NumberLit, Position{}},
Token{"1.0", NumberLit, Position{}},
// Vertex
Token{"", VertexDecl, Position{}},
Token{"0.0", NumberLit, Position{}},
Token{"1.0", NumberLit, Position{}},
Token{"0.0", NumberLit, Position{}},
// Face
Token{"", FaceDecl, Position{}},
Token{"1", NumberLit, Position{}},
Token{"2", NumberLit, Position{}},
// Face
Token{"", FaceDecl, Position{}},
Token{"2", NumberLit, Position{}},
Token{"1", NumberLit, Position{}},
Token{"", Eof, Position{}},
},
},
// Mesh with normals
{
title: "Mesh with normals",
ignore: false,
mesh: &Mesh{
[]Face{
Face{VertexList{Vertex{1.0, 1.0, 1.0}, Vertex{0.0, 1.0, 0.0}}, VertexList{
Vertex{1.0, 1.0, 1.0}, Vertex{0.0, 1.0, 0.0},
}},
Face{VertexList{Vertex{0.0, 1.0, 0.0}, Vertex{1.0, 1.0, 1.0}}, VertexList{
Vertex{0.0, 1.0, 0.0}, Vertex{1.0, 1.0, 1.0},
}},
},
},
objlit: `# comment
v 1.0 1.0 1.0
v 0.0 1.0 0.0
vn 1.0 1.0 1.0
vn 0.0 1.0 0.0
f 1//1 2//2
f 2//2 1//1
`,
tokens: []Token{
// Vertex
Token{"", VertexDecl, Position{}},
Token{"1.0", NumberLit, Position{}},
Token{"1.0", NumberLit, Position{}},
Token{"1.0", NumberLit, Position{}},
// Vertex
Token{"", VertexDecl, Position{}},
Token{"0.0", NumberLit, Position{}},
Token{"1.0", NumberLit, Position{}},
Token{"0.0", NumberLit, Position{}},
// Normal
Token{"", NormalDecl, Position{}},
Token{"0.0", NumberLit, Position{}},
Token{"1.0", NumberLit, Position{}},
Token{"0.0", NumberLit, Position{}},
// Normal
Token{"", NormalDecl, Position{}},
Token{"0.0", NumberLit, Position{}},
Token{"1.0", NumberLit, Position{}},
Token{"0.0", NumberLit, Position{}},
// Face
Token{"", FaceDecl, Position{}},
Token{"1", NumberLit, Position{}},
Token{"", SlashLit, Position{}},
Token{"", SlashLit, Position{}},
Token{"1", NumberLit, Position{}},
// vector
Token{"2", NumberLit, Position{}},
Token{"", SlashLit, Position{}},
Token{"", SlashLit, Position{}},
Token{"2", NumberLit, Position{}},
// Face
Token{"", FaceDecl, Position{}},
Token{"2", NumberLit, Position{}},
Token{"", SlashLit, Position{}},
Token{"", SlashLit, Position{}},
Token{"2", NumberLit, Position{}},
// vector
Token{"1", NumberLit, Position{}},
Token{"", SlashLit, Position{}},
Token{"", SlashLit, Position{}},
Token{"1", NumberLit, Position{}},
Token{"", Eof, Position{}},
},
},
}
type PrintState struct{}
func (ps *PrintState) State(p *Parser) {
print("STATE: ", p.String(), "\n")
}
func (ps *PrintState) Emit(t *Token) {
print("EMIT: ", t.String(), "\n")
}