github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/core/asm/lex_test.go (about) 1 package asm 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func lexAll(src string) []token { 9 ch := Lex("test.asm", []byte(src), false) 10 11 var tokens []token 12 for i := range ch { 13 tokens = append(tokens, i) 14 } 15 return tokens 16 } 17 18 func TestLexer(t *testing.T) { 19 tests := []struct { 20 input string 21 tokens []token 22 }{ 23 { 24 input: ";; this is a comment", 25 tokens: []token{{typ: lineStart}, {typ: eof}}, 26 }, 27 { 28 input: "0x12345678", 29 tokens: []token{{typ: lineStart}, {typ: number, text: "0x12345678"}, {typ: eof}}, 30 }, 31 { 32 input: "0x123ggg", 33 tokens: []token{{typ: lineStart}, {typ: number, text: "0x123"}, {typ: element, text: "ggg"}, {typ: eof}}, 34 }, 35 { 36 input: "12345678", 37 tokens: []token{{typ: lineStart}, {typ: number, text: "12345678"}, {typ: eof}}, 38 }, 39 { 40 input: "123abc", 41 tokens: []token{{typ: lineStart}, {typ: number, text: "123"}, {typ: element, text: "abc"}, {typ: eof}}, 42 }, 43 { 44 input: "0123abc", 45 tokens: []token{{typ: lineStart}, {typ: number, text: "0123"}, {typ: element, text: "abc"}, {typ: eof}}, 46 }, 47 } 48 49 for _, test := range tests { 50 tokens := lexAll(test.input) 51 if !reflect.DeepEqual(tokens, test.tokens) { 52 t.Errorf("input %q\ngot: %+v\nwant: %+v", test.input, tokens, test.tokens) 53 } 54 } 55 }