| 1 | package mail |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/goccmack/gocc/example/mail/lexer" |
| 7 | "github.com/goccmack/gocc/example/mail/token" |
| 8 | ) |
| 9 | |
| 10 | var testData1 = map[string]bool{ |
| 11 | "[email protected]": true, |
| 12 | "@google.com": false, |
| 13 | `"quoted string"@mymail.com`: true, |
| 14 | `"unclosed [email protected]`: false, |
| 15 | } |
| 16 | |
| 17 | func Test1(t *testing.T) { |
| 18 | for input, ok := range testData1 { |
| 19 | l := lexer.NewLexer([]byte(input)) |
| 20 | tok := l.Scan() |
| 21 | switch { |
| 22 | case tok.Type == token.INVALID: |
| 23 | if ok { |
| 24 | t.Errorf("%s", input) |
| 25 | } |
| 26 | case tok.Type == token.TokMap.Type("addrspec"): |
| 27 | if !ok { |
| 28 | t.Errorf("%s", input) |
| 29 | } |
| 30 | default: |
| 31 | t.Fatalf("This must not happen") |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | var checkData2 = []string{ |
| 37 | "[email protected]", |
| 38 | "[email protected]", |
| 39 | "[email protected]", |
| 40 | } |
| 41 | |
| 42 | var testData2 = ` |
| 43 | [email protected] |
| 44 | [email protected] |
| 45 | [email protected] |
| 46 | ` |
| 47 | |
| 48 | func Test2(t *testing.T) { |
| 49 | l := lexer.NewLexer([]byte(testData2)) |
| 50 | num := 0 |
| 51 | for tok := l.Scan(); tok.Type == token.TokMap.Type("addrspec"); tok = l.Scan() { |
| 52 | if string(tok.Lit) != checkData2[num] { |
| 53 | t.Errorf("%s != %s", string(tok.Lit), checkData2[num]) |
| 54 | } |
| 55 | num++ |
| 56 | } |
| 57 | if num != len(checkData2) { |
| 58 | t.Fatalf("%d addresses parsed", num) |
| 59 | } |
| 60 | } |