-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsymbol_scanner_test.go
63 lines (56 loc) · 1.34 KB
/
symbol_scanner_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
package gmars
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
type symbolScannerTestCase struct {
input string
output map[string][]token
}
func runSymbolScannerTests(t *testing.T, cases []symbolScannerTestCase) {
for _, test := range cases {
tokens, err := LexInput(strings.NewReader(test.input))
require.NoError(t, err)
require.NotNil(t, tokens)
scanner := newSymbolScanner(newBufTokenReader(tokens))
symbols, _, err := scanner.ScanInput()
require.NoError(t, err)
require.NotNil(t, symbols)
require.Equal(t, test.output, symbols)
}
}
func TestSymbolScanner(t *testing.T) {
tests := []symbolScannerTestCase{
{
input: "test equ 2\ndat 0, test\n",
output: map[string][]token{
"test": {{tokNumber, "2"}},
},
},
{
input: "dat 0, 0",
output: map[string][]token{},
},
{
input: "test\ntest2\nequ 2",
output: map[string][]token{
"test": {{tokNumber, "2"}},
"test2": {{tokNumber, "2"}},
},
},
{
// ignore symbols inside for loops because they could be redifined.
// will just re-scan after expanding for loops
input: "test equ 2\nfor 0\nq equ 1\nrof\nfor 1\nq equ 2\nrof\n",
output: map[string][]token{
"test": {{tokNumber, "2"}},
},
},
{
input: "for 1\nend\nrof\n ~",
output: map[string][]token{},
},
}
runSymbolScannerTests(t, tests)
}