summaryrefslogtreecommitdiff
path: root/src/pkg/scanner/scanner_test.go
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
committerOndřej Surý <ondrej@sury.org>2011-01-17 12:40:45 +0100
commit3e45412327a2654a77944249962b3652e6142299 (patch)
treebc3bf69452afa055423cbe0c5cfa8ca357df6ccf /src/pkg/scanner/scanner_test.go
parentc533680039762cacbc37db8dc7eed074c3e497be (diff)
downloadgolang-3e45412327a2654a77944249962b3652e6142299.tar.gz
Imported Upstream version 2011.01.12upstream/2011.01.12
Diffstat (limited to 'src/pkg/scanner/scanner_test.go')
-rw-r--r--src/pkg/scanner/scanner_test.go319
1 files changed, 158 insertions, 161 deletions
diff --git a/src/pkg/scanner/scanner_test.go b/src/pkg/scanner/scanner_test.go
index 563ceea0c..506f434fe 100644
--- a/src/pkg/scanner/scanner_test.go
+++ b/src/pkg/scanner/scanner_test.go
@@ -23,10 +23,7 @@ type StringReader struct {
func (r *StringReader) Read(p []byte) (n int, err os.Error) {
if r.step < len(r.data) {
s := r.data[r.step]
- for i := 0; i < len(s); i++ {
- p[i] = s[i]
- }
- n = len(s)
+ n = copy(p, s)
r.step++
} else {
err = os.EOF
@@ -53,14 +50,14 @@ func readRuneSegments(t *testing.T, segments []string) {
var segmentList = [][]string{
- []string{},
- []string{""},
- []string{"日", "本語"},
- []string{"\u65e5", "\u672c", "\u8a9e"},
- []string{"\U000065e5", " ", "\U0000672c", "\U00008a9e"},
- []string{"\xe6", "\x97\xa5\xe6", "\x9c\xac\xe8\xaa\x9e"},
- []string{"Hello", ", ", "World", "!"},
- []string{"Hello", ", ", "", "World", "!"},
+ {},
+ {""},
+ {"日", "本語"},
+ {"\u65e5", "\u672c", "\u8a9e"},
+ {"\U000065e5", " ", "\U0000672c", "\U00008a9e"},
+ {"\xe6", "\x97\xa5\xe6", "\x9c\xac\xe8\xaa\x9e"},
+ {"Hello", ", ", "World", "!"},
+ {"Hello", ", ", "", "World", "!"},
}
@@ -79,161 +76,161 @@ type token struct {
var f100 = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
var tokenList = []token{
- token{Comment, "// line comments\n"},
- token{Comment, "//\n"},
- token{Comment, "////\n"},
- token{Comment, "// comment\n"},
- token{Comment, "// /* comment */\n"},
- token{Comment, "// // comment //\n"},
- token{Comment, "//" + f100 + "\n"},
-
- token{Comment, "// general comments\n"},
- token{Comment, "/**/"},
- token{Comment, "/***/"},
- token{Comment, "/* comment */"},
- token{Comment, "/* // comment */"},
- token{Comment, "/* /* comment */"},
- token{Comment, "/*\n comment\n*/"},
- token{Comment, "/*" + f100 + "*/"},
-
- token{Comment, "// identifiers\n"},
- token{Ident, "a"},
- token{Ident, "a0"},
- token{Ident, "foobar"},
- token{Ident, "abc123"},
- token{Ident, "LGTM"},
- token{Ident, "_"},
- token{Ident, "_abc123"},
- token{Ident, "abc123_"},
- token{Ident, "_abc_123_"},
- token{Ident, "_äöü"},
- token{Ident, "_本"},
+ {Comment, "// line comments\n"},
+ {Comment, "//\n"},
+ {Comment, "////\n"},
+ {Comment, "// comment\n"},
+ {Comment, "// /* comment */\n"},
+ {Comment, "// // comment //\n"},
+ {Comment, "//" + f100 + "\n"},
+
+ {Comment, "// general comments\n"},
+ {Comment, "/**/"},
+ {Comment, "/***/"},
+ {Comment, "/* comment */"},
+ {Comment, "/* // comment */"},
+ {Comment, "/* /* comment */"},
+ {Comment, "/*\n comment\n*/"},
+ {Comment, "/*" + f100 + "*/"},
+
+ {Comment, "// identifiers\n"},
+ {Ident, "a"},
+ {Ident, "a0"},
+ {Ident, "foobar"},
+ {Ident, "abc123"},
+ {Ident, "LGTM"},
+ {Ident, "_"},
+ {Ident, "_abc123"},
+ {Ident, "abc123_"},
+ {Ident, "_abc_123_"},
+ {Ident, "_äöü"},
+ {Ident, "_本"},
// TODO for unknown reasons these fail when checking the literals
/*
token{Ident, "äöü"},
token{Ident, "本"},
*/
- token{Ident, "a۰۱۸"},
- token{Ident, "foo६४"},
- token{Ident, "bar9876"},
- token{Ident, f100},
-
- token{Comment, "// decimal ints\n"},
- token{Int, "0"},
- token{Int, "1"},
- token{Int, "9"},
- token{Int, "42"},
- token{Int, "1234567890"},
-
- token{Comment, "// octal ints\n"},
- token{Int, "00"},
- token{Int, "01"},
- token{Int, "07"},
- token{Int, "042"},
- token{Int, "01234567"},
-
- token{Comment, "// hexadecimal ints\n"},
- token{Int, "0x0"},
- token{Int, "0x1"},
- token{Int, "0xf"},
- token{Int, "0x42"},
- token{Int, "0x123456789abcDEF"},
- token{Int, "0x" + f100},
- token{Int, "0X0"},
- token{Int, "0X1"},
- token{Int, "0XF"},
- token{Int, "0X42"},
- token{Int, "0X123456789abcDEF"},
- token{Int, "0X" + f100},
-
- token{Comment, "// floats\n"},
- token{Float, "0."},
- token{Float, "1."},
- token{Float, "42."},
- token{Float, "01234567890."},
- token{Float, ".0"},
- token{Float, ".1"},
- token{Float, ".42"},
- token{Float, ".0123456789"},
- token{Float, "0.0"},
- token{Float, "1.0"},
- token{Float, "42.0"},
- token{Float, "01234567890.0"},
- token{Float, "0e0"},
- token{Float, "1e0"},
- token{Float, "42e0"},
- token{Float, "01234567890e0"},
- token{Float, "0E0"},
- token{Float, "1E0"},
- token{Float, "42E0"},
- token{Float, "01234567890E0"},
- token{Float, "0e+10"},
- token{Float, "1e-10"},
- token{Float, "42e+10"},
- token{Float, "01234567890e-10"},
- token{Float, "0E+10"},
- token{Float, "1E-10"},
- token{Float, "42E+10"},
- token{Float, "01234567890E-10"},
-
- token{Comment, "// chars\n"},
- token{Char, `' '`},
- token{Char, `'a'`},
- token{Char, `'本'`},
- token{Char, `'\a'`},
- token{Char, `'\b'`},
- token{Char, `'\f'`},
- token{Char, `'\n'`},
- token{Char, `'\r'`},
- token{Char, `'\t'`},
- token{Char, `'\v'`},
- token{Char, `'\''`},
- token{Char, `'\000'`},
- token{Char, `'\777'`},
- token{Char, `'\x00'`},
- token{Char, `'\xff'`},
- token{Char, `'\u0000'`},
- token{Char, `'\ufA16'`},
- token{Char, `'\U00000000'`},
- token{Char, `'\U0000ffAB'`},
-
- token{Comment, "// strings\n"},
- token{String, `" "`},
- token{String, `"a"`},
- token{String, `"本"`},
- token{String, `"\a"`},
- token{String, `"\b"`},
- token{String, `"\f"`},
- token{String, `"\n"`},
- token{String, `"\r"`},
- token{String, `"\t"`},
- token{String, `"\v"`},
- token{String, `"\""`},
- token{String, `"\000"`},
- token{String, `"\777"`},
- token{String, `"\x00"`},
- token{String, `"\xff"`},
- token{String, `"\u0000"`},
- token{String, `"\ufA16"`},
- token{String, `"\U00000000"`},
- token{String, `"\U0000ffAB"`},
- token{String, `"` + f100 + `"`},
-
- token{Comment, "// raw strings\n"},
- token{String, "``"},
- token{String, "`\\`"},
- token{String, "`" + "\n\n/* foobar */\n\n" + "`"},
- token{String, "`" + f100 + "`"},
-
- token{Comment, "// individual characters\n"},
+ {Ident, "a۰۱۸"},
+ {Ident, "foo६४"},
+ {Ident, "bar9876"},
+ {Ident, f100},
+
+ {Comment, "// decimal ints\n"},
+ {Int, "0"},
+ {Int, "1"},
+ {Int, "9"},
+ {Int, "42"},
+ {Int, "1234567890"},
+
+ {Comment, "// octal ints\n"},
+ {Int, "00"},
+ {Int, "01"},
+ {Int, "07"},
+ {Int, "042"},
+ {Int, "01234567"},
+
+ {Comment, "// hexadecimal ints\n"},
+ {Int, "0x0"},
+ {Int, "0x1"},
+ {Int, "0xf"},
+ {Int, "0x42"},
+ {Int, "0x123456789abcDEF"},
+ {Int, "0x" + f100},
+ {Int, "0X0"},
+ {Int, "0X1"},
+ {Int, "0XF"},
+ {Int, "0X42"},
+ {Int, "0X123456789abcDEF"},
+ {Int, "0X" + f100},
+
+ {Comment, "// floats\n"},
+ {Float, "0."},
+ {Float, "1."},
+ {Float, "42."},
+ {Float, "01234567890."},
+ {Float, ".0"},
+ {Float, ".1"},
+ {Float, ".42"},
+ {Float, ".0123456789"},
+ {Float, "0.0"},
+ {Float, "1.0"},
+ {Float, "42.0"},
+ {Float, "01234567890.0"},
+ {Float, "0e0"},
+ {Float, "1e0"},
+ {Float, "42e0"},
+ {Float, "01234567890e0"},
+ {Float, "0E0"},
+ {Float, "1E0"},
+ {Float, "42E0"},
+ {Float, "01234567890E0"},
+ {Float, "0e+10"},
+ {Float, "1e-10"},
+ {Float, "42e+10"},
+ {Float, "01234567890e-10"},
+ {Float, "0E+10"},
+ {Float, "1E-10"},
+ {Float, "42E+10"},
+ {Float, "01234567890E-10"},
+
+ {Comment, "// chars\n"},
+ {Char, `' '`},
+ {Char, `'a'`},
+ {Char, `'本'`},
+ {Char, `'\a'`},
+ {Char, `'\b'`},
+ {Char, `'\f'`},
+ {Char, `'\n'`},
+ {Char, `'\r'`},
+ {Char, `'\t'`},
+ {Char, `'\v'`},
+ {Char, `'\''`},
+ {Char, `'\000'`},
+ {Char, `'\777'`},
+ {Char, `'\x00'`},
+ {Char, `'\xff'`},
+ {Char, `'\u0000'`},
+ {Char, `'\ufA16'`},
+ {Char, `'\U00000000'`},
+ {Char, `'\U0000ffAB'`},
+
+ {Comment, "// strings\n"},
+ {String, `" "`},
+ {String, `"a"`},
+ {String, `"本"`},
+ {String, `"\a"`},
+ {String, `"\b"`},
+ {String, `"\f"`},
+ {String, `"\n"`},
+ {String, `"\r"`},
+ {String, `"\t"`},
+ {String, `"\v"`},
+ {String, `"\""`},
+ {String, `"\000"`},
+ {String, `"\777"`},
+ {String, `"\x00"`},
+ {String, `"\xff"`},
+ {String, `"\u0000"`},
+ {String, `"\ufA16"`},
+ {String, `"\U00000000"`},
+ {String, `"\U0000ffAB"`},
+ {String, `"` + f100 + `"`},
+
+ {Comment, "// raw strings\n"},
+ {String, "``"},
+ {String, "`\\`"},
+ {String, "`" + "\n\n/* foobar */\n\n" + "`"},
+ {String, "`" + f100 + "`"},
+
+ {Comment, "// individual characters\n"},
// NUL character is not allowed
- token{'\x01', "\x01"},
- token{' ' - 1, string(' ' - 1)},
- token{'+', "+"},
- token{'/', "/"},
- token{'.', "."},
- token{'~', "~"},
- token{'(', "("},
+ {'\x01', "\x01"},
+ {' ' - 1, string(' ' - 1)},
+ {'+', "+"},
+ {'/', "/"},
+ {'.', "."},
+ {'~', "~"},
+ {'(', "("},
}