aboutsummaryrefslogtreecommitdiff
path: root/test/string_lit.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2008-06-08 19:08:00 -0700
committerRob Pike <r@golang.org>2008-06-08 19:08:00 -0700
commitf07d2eea52b135575ff77b5446e1f8fe93146e0b (patch)
treedefd1eeade5ad01110662709d22480a7e827a89d /test/string_lit.go
parentf9c58c25e0aabf8420aadf12dafd507f97245de6 (diff)
downloadgo-f07d2eea52b135575ff77b5446e1f8fe93146e0b.tar.gz
go-f07d2eea52b135575ff77b5446e1f8fe93146e0b.zip
fix string_lit test to be more thorough
SVN=121623
Diffstat (limited to 'test/string_lit.go')
-rw-r--r--test/string_lit.go91
1 files changed, 70 insertions, 21 deletions
diff --git a/test/string_lit.go b/test/string_lit.go
index 1b106cdadf..56c4c6a668 100644
--- a/test/string_lit.go
+++ b/test/string_lit.go
@@ -6,25 +6,74 @@
package main
-func main() {
- []string(
- "",
- " ",
- "'`",
- "a",
- "ä",
- "本",
- "\a\b\f\n\r\t\v\\\"",
- "\000\123\x00\xca\xFE\u0123\ubabe\U0123ABCD\Ucafebabe",
-
- ``,
- ` `,
- `'"`,
- `a`,
- `ä`,
- `本`,
- `\a\b\f\n\r\t\v\\\'\"`,
- `\000\123\x00\xca\xFE\u0123\ubabe\U0123ABCD\Ucafebabe`,
- `\x\u\U\`
- );
+var ecode int;
+
+func assert(a, b, c string) {
+ if a != b {
+ ecode = 1;
+ print "FAIL: ", c, ": ", a, "!=", b, "\n";
+ var max int = len(a);
+ if len(b) > max {
+ max = len(b);
+ }
+ for i := 0; i < max; i++ {
+ ac := 0;
+ bc := 0;
+ if i < len(a) {
+ ac = int(a[i]);
+ }
+ if i < len(b) {
+ bc = int(b[i]);
+ }
+ if ac != bc {
+ print "\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n";
+ }
+ }
+ }
+}
+
+func main() int {
+ ecode = 0;
+ s :=
+ ""
+ " "
+ "'`"
+ "a"
+ "ä"
+ "本"
+ "\a\b\f\n\r\t\v\\\""
+ "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe"
+
+ ``
+ ` `
+ `'"`
+ `a`
+ `ä`
+ `本`
+ `\a\b\f\n\r\t\v\\\'`
+ `\000\123\x00\xca\xFE\u0123\ubabe\U0000babe`
+ `\x\u\U\`
+ ;
+ assert("", ``, "empty");
+ assert(" ", " ", "blank");
+ assert("\x61", "a", "lowercase a");
+ assert("\x61", `a`, "lowercase a (backquote)");
+ assert("\u00e4", "ä", "a umlaut");
+ assert("\u00e4", `ä`, "a umlaut (backquote)");
+ assert("\u672c", "本", "nihon");
+ assert("\u672c", `本`, "nihon (backquote)");
+ assert("\x07\x08\x0c\x0a\x0d\x09\x0b\x5c\x22",
+ "\a\b\f\n\r\t\v\\\"",
+ "backslashes");
+ assert("\\a\\b\\f\\n\\r\\t\\v\\\\\\\"",
+ `\a\b\f\n\r\t\v\\\"`,
+ "backslashes (backquote)");
+ assert("\x00\x53\000\xca\376S몾몾",
+ "\000\123\x00\312\xFE\u0053\ubabe\U0000babe",
+ "backslashes 2");
+ assert("\\000\\123\\x00\\312\\xFE\\u0123\\ubabe\\U0000babe",
+ `\000\123\x00\312\xFE\u0123\ubabe\U0000babe`,
+ "backslashes 2 (backquote)");
+ assert("\\x\\u\\U\\", `\x\u\U\`, "backslash 3 (backquote)");
+ return ecode;
}