diff --git a/scanner/scanner.go b/scanner/scanner.go index d2b98c4..2fc3b27 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -113,7 +113,7 @@ func (s *Scanner) Scan() (tok token.Token) { } if isDigit(ch) { - // scanDigits() + s.scanNumber() // TODO(arslan) } @@ -129,6 +129,10 @@ func (s *Scanner) Scan() (tok token.Token) { return tok } +func (s *Scanner) scanNumber() { +} + +// scanString scans a quoted string func (s *Scanner) scanString() { for { // '"' opening already consumed diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index 1ed6326..4f69088 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -15,36 +15,40 @@ type tokenPair struct { text string } -func TestBool(t *testing.T) { - var tokenList = []tokenPair{ - {token.BOOL, "true"}, - {token.BOOL, "false"}, - } - +func testTokenList(t *testing.T, tokenList []tokenPair) { // create artifical source code buf := new(bytes.Buffer) for _, ident := range tokenList { fmt.Fprintf(buf, " \t%s\n", ident.text) } - l, err := NewScanner(buf) + s, err := NewScanner(buf) if err != nil { t.Fatal(err) } for _, ident := range tokenList { - tok := l.Scan() + tok := s.Scan() if tok != ident.tok { t.Errorf("tok = %s want %s for %s\n", tok, ident.tok, ident.text) } - if l.TokenText() != ident.text { - t.Errorf("text = %s want %s", l.TokenText(), ident.text) + if s.TokenText() != ident.text { + t.Errorf("text = %s want %s", s.TokenText(), ident.text) } } } +func TestBool(t *testing.T) { + var tokenList = []tokenPair{ + {token.BOOL, "true"}, + {token.BOOL, "false"}, + } + + testTokenList(t, tokenList) +} + func TestIdent(t *testing.T) { var tokenList = []tokenPair{ {token.IDENT, "a"}, @@ -65,28 +69,7 @@ func TestIdent(t *testing.T) { {token.IDENT, "bar9876"}, } - // create artifical source code - buf := new(bytes.Buffer) - for _, ident := range tokenList { - fmt.Fprintf(buf, " \t%s\n", ident.text) - } - - l, err := NewScanner(buf) - if err != nil { - t.Fatal(err) - } - - for _, ident := range tokenList { - tok := l.Scan() - if tok != ident.tok { - t.Errorf("tok = %s want %s for %s\n", tok, ident.tok, ident.text) - } - - if l.TokenText() != ident.text { - t.Errorf("text = %s want %s", l.TokenText(), ident.text) - } - - } + testTokenList(t, tokenList) } func TestString(t *testing.T) { @@ -113,26 +96,5 @@ func TestString(t *testing.T) { {token.STRING, `"` + f100 + `"`}, } - // create artifical source code - buf := new(bytes.Buffer) - for _, ident := range tokenList { - fmt.Fprintf(buf, " \t%s\n", ident.text) - } - - l, err := NewScanner(buf) - if err != nil { - t.Fatal(err) - } - - for _, ident := range tokenList { - tok := l.Scan() - if tok != ident.tok { - t.Errorf("tok = %s want %s for %s\n", tok, ident.tok, ident.text) - } - - if l.TokenText() != ident.text { - t.Errorf("text = %s want %s", l.TokenText(), ident.text) - } - - } + testTokenList(t, tokenList) }