OSDN Git Service

Update Go library to r60.
[pf3gnuchains/gcc-fork.git] / libgo / go / go / scanner / scanner_test.go
index 8afb00e..eb9e1cb 100644 (file)
@@ -12,10 +12,8 @@ import (
        "testing"
 )
 
-
 var fset = token.NewFileSet()
 
-
 const /* class */ (
        special = iota
        literal
@@ -23,7 +21,6 @@ const /* class */ (
        keyword
 )
 
-
 func tokenclass(tok token.Token) int {
        switch {
        case tok.IsLiteral():
@@ -36,14 +33,12 @@ func tokenclass(tok token.Token) int {
        return special
 }
 
-
 type elt struct {
        tok   token.Token
        lit   string
        class int
 }
 
-
 var tokens = [...]elt{
        // Special tokens
        {token.COMMENT, "/* a comment */", special},
@@ -89,7 +84,7 @@ var tokens = [...]elt{
                literal,
        },
 
-       // Operators and delimitors
+       // Operators and delimiters
        {token.ADD, "+", operator},
        {token.SUB, "-", operator},
        {token.MUL, "*", operator},
@@ -178,7 +173,6 @@ var tokens = [...]elt{
        {token.VAR, "var", keyword},
 }
 
-
 const whitespace = "  \t  \n\n\n" // to separate tokens
 
 type testErrorHandler struct {
@@ -189,7 +183,6 @@ func (h *testErrorHandler) Error(pos token.Position, msg string) {
        h.t.Errorf("Error() called (msg = %s)", msg)
 }
 
-
 func newlineCount(s string) int {
        n := 0
        for i := 0; i < len(s); i++ {
@@ -200,7 +193,6 @@ func newlineCount(s string) int {
        return n
 }
 
-
 func checkPos(t *testing.T, lit string, p token.Pos, expected token.Position) {
        pos := fset.Position(p)
        if pos.Filename != expected.Filename {
@@ -217,7 +209,6 @@ func checkPos(t *testing.T, lit string, p token.Pos, expected token.Position) {
        }
 }
 
-
 // Verify that calling Scan() provides the correct results.
 func TestScan(t *testing.T) {
        // make source
@@ -271,7 +262,6 @@ func TestScan(t *testing.T) {
        }
 }
 
-
 func checkSemi(t *testing.T, line string, mode uint) {
        var S Scanner
        file := fset.AddFile("TestSemis", fset.Base(), len(line))
@@ -305,7 +295,6 @@ func checkSemi(t *testing.T, line string, mode uint) {
        }
 }
 
-
 var lines = []string{
        // # indicates a semicolon present in the source
        // $ indicates an automatically inserted semicolon
@@ -429,7 +418,6 @@ var lines = []string{
        "package main$",
 }
 
-
 func TestSemis(t *testing.T) {
        for _, line := range lines {
                checkSemi(t, line, AllowIllegalChars|InsertSemis)
@@ -463,25 +451,31 @@ var segments = []segment{
        {"\n //line foo:42\n  line44", filepath.Join("dir", "foo"), 44},           // bad line comment, ignored
        {"\n//line foo 42\n  line46", filepath.Join("dir", "foo"), 46},            // bad line comment, ignored
        {"\n//line foo:42 extra text\n  line48", filepath.Join("dir", "foo"), 48}, // bad line comment, ignored
-       {"\n//line /bar:42\n  line42", string(filepath.Separator) + "bar", 42},
        {"\n//line ./foo:42\n  line42", filepath.Join("dir", "foo"), 42},
        {"\n//line a/b/c/File1.go:100\n  line100", filepath.Join("dir", "a", "b", "c", "File1.go"), 100},
 }
 
+var unixsegments = []segment{
+       {"\n//line /bar:42\n  line42", "/bar", 42},
+}
+
 var winsegments = []segment{
+       {"\n//line c:\\bar:42\n  line42", "c:\\bar", 42},
        {"\n//line c:\\dir\\File1.go:100\n  line100", "c:\\dir\\File1.go", 100},
 }
 
-
 // Verify that comments of the form "//line filename:line" are interpreted correctly.
 func TestLineComments(t *testing.T) {
+       segs := segments
        if runtime.GOOS == "windows" {
-               segments = append(segments, winsegments...)
+               segs = append(segs, winsegments...)
+       } else {
+               segs = append(segs, unixsegments...)
        }
 
        // make source
        var src string
-       for _, e := range segments {
+       for _, e := range segs {
                src += e.srcline
        }
 
@@ -489,7 +483,7 @@ func TestLineComments(t *testing.T) {
        var S Scanner
        file := fset.AddFile(filepath.Join("dir", "TestLineComments"), fset.Base(), len(src))
        S.Init(file, []byte(src), nil, 0)
-       for _, s := range segments {
+       for _, s := range segs {
                p, _, lit := S.Scan()
                pos := file.Position(p)
                checkPos(t, lit, p, token.Position{s.filename, pos.Offset, s.line, pos.Column})
@@ -500,7 +494,6 @@ func TestLineComments(t *testing.T) {
        }
 }
 
-
 // Verify that initializing the same scanner more then once works correctly.
 func TestInit(t *testing.T) {
        var s Scanner
@@ -536,7 +529,6 @@ func TestInit(t *testing.T) {
        }
 }
 
-
 func TestIllegalChars(t *testing.T) {
        var s Scanner
 
@@ -558,7 +550,6 @@ func TestIllegalChars(t *testing.T) {
        }
 }
 
-
 func TestStdErrorHander(t *testing.T) {
        const src = "@\n" + // illegal character, cause an error
                "@ @\n" + // two errors on the same line
@@ -601,21 +592,18 @@ func TestStdErrorHander(t *testing.T) {
        }
 }
 
-
 type errorCollector struct {
        cnt int            // number of errors encountered
        msg string         // last error message encountered
        pos token.Position // last error position encountered
 }
 
-
 func (h *errorCollector) Error(pos token.Position, msg string) {
        h.cnt++
        h.msg = msg
        h.pos = pos
 }
 
-
 func checkError(t *testing.T, src string, tok token.Token, pos int, err string) {
        var s Scanner
        var h errorCollector
@@ -643,14 +631,15 @@ func checkError(t *testing.T, src string, tok token.Token, pos int, err string)
        }
 }
 
-
 var errors = []struct {
        src string
        tok token.Token
        pos int
        err string
 }{
-       {`#`, token.ILLEGAL, 0, "illegal character '#' (U+23)"},
+       {"\a", token.ILLEGAL, 0, "illegal character U+0007"},
+       {`#`, token.ILLEGAL, 0, "illegal character U+0023 '#'"},
+       {`…`, token.ILLEGAL, 0, "illegal character U+2026 '…'"},
        {`' '`, token.CHAR, 0, ""},
        {`''`, token.CHAR, 0, "illegal character literal"},
        {`'\8'`, token.CHAR, 2, "unknown escape sequence"},
@@ -670,11 +659,12 @@ var errors = []struct {
        {"078e0", token.FLOAT, 0, ""},
        {"078", token.INT, 0, "illegal octal number"},
        {"07800000009", token.INT, 0, "illegal octal number"},
+       {"0x", token.INT, 0, "illegal hexadecimal number"},
+       {"0X", token.INT, 0, "illegal hexadecimal number"},
        {"\"abc\x00def\"", token.STRING, 4, "illegal character NUL"},
        {"\"abc\x80def\"", token.STRING, 4, "illegal UTF-8 encoding"},
 }
 
-
 func TestScanErrors(t *testing.T) {
        for _, e := range errors {
                checkError(t, e.src, e.tok, e.pos, e.err)