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
|
package scanner_test
import (
"jinx/pkg/lang/scanner"
"jinx/pkg/lang/scanner/token"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestBasic(t *testing.T) {
source := "var x = 1"
s := scanner.New(strings.NewReader(source))
tokens, err := s.Scan()
require.NoError(t, err)
expected := []token.Token{
token.Simple(token.KwVar, token.Loc{Row: 0, Col: 0}),
token.New(token.Ident, token.Loc{Row: 0, Col: 4}, "x"),
token.Simple(token.Assign, token.Loc{Row: 0, Col: 6}),
token.New(token.Int, token.Loc{Row: 0, Col: 8}, uint64(1)),
token.Simple(token.EOF, token.Loc{Row: 0, Col: 9}),
}
require.Equal(t, expected, tokens)
}
|