github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/core/asm/lex_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:33</date> 10 //</624342614421803008> 11 12 13 package asm 14 15 import ( 16 "reflect" 17 "testing" 18 ) 19 20 func lexAll(src string) []token { 21 ch := Lex("test.asm", []byte(src), false) 22 23 var tokens []token 24 for i := range ch { 25 tokens = append(tokens, i) 26 } 27 return tokens 28 } 29 30 func TestLexer(t *testing.T) { 31 tests := []struct { 32 input string 33 tokens []token 34 }{ 35 { 36 input: ";; this is a comment", 37 tokens: []token{{typ: lineStart}, {typ: eof}}, 38 }, 39 { 40 input: "0x12345678", 41 tokens: []token{{typ: lineStart}, {typ: number, text: "0x12345678"}, {typ: eof}}, 42 }, 43 { 44 input: "0x123ggg", 45 tokens: []token{{typ: lineStart}, {typ: number, text: "0x123"}, {typ: element, text: "ggg"}, {typ: eof}}, 46 }, 47 { 48 input: "12345678", 49 tokens: []token{{typ: lineStart}, {typ: number, text: "12345678"}, {typ: eof}}, 50 }, 51 { 52 input: "123abc", 53 tokens: []token{{typ: lineStart}, {typ: number, text: "123"}, {typ: element, text: "abc"}, {typ: eof}}, 54 }, 55 { 56 input: "0123abc", 57 tokens: []token{{typ: lineStart}, {typ: number, text: "0123"}, {typ: element, text: "abc"}, {typ: eof}}, 58 }, 59 } 60 61 for _, test := range tests { 62 tokens := lexAll(test.input) 63 if !reflect.DeepEqual(tokens, test.tokens) { 64 t.Errorf("input %q\ngot: %+v\nwant: %+v", test.input, tokens, test.tokens) 65 } 66 } 67 } 68