github.com/hirochachacha/plua@v0.0.0-20170217012138-c82f520cc725/compiler/scanner/scan_test.go (about) 1 package scanner_test 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "testing" 8 9 "github.com/hirochachacha/plua/compiler/scanner" 10 "github.com/hirochachacha/plua/compiler/token" 11 ) 12 13 func TestScan(t *testing.T) { 14 matches, err := filepath.Glob("testdata/*.lua") 15 if err != nil { 16 t.Fatal(err) 17 } 18 for _, fname := range matches { 19 if fname == "testdata/example.lua" { 20 continue 21 } 22 23 fmt.Println("filename:", fname) 24 25 f, err := os.Open(fname) 26 if err != nil { 27 t.Fatal(err) 28 } 29 defer f.Close() 30 31 s := scanner.Scan(f, "@"+fname, 0) 32 for { 33 tok, err := s.Token() 34 if err != nil { 35 t.Fatal(err) 36 } 37 if tok.Type == token.EOF { 38 break 39 } 40 fmt.Printf("line: %d, column: %d, tok: %s, lit: %s\n", tok.Pos.Line, tok.Pos.Column, tok.Type, tok.Lit) 41 } 42 43 fmt.Println() 44 } 45 }