]> Cypherpunks.ru repositories - gostls13.git/blob - test/string_lit.go
export sys.exit
[gostls13.git] / test / string_lit.go
1 // $G $F.go && $L $F.$A && ./$A.out
2
3 // Copyright 2009 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package main
8
9 var ecode int;
10
11 func assert(a, b, c string) {
12         if a != b {
13                 ecode = 1;
14                 print "FAIL: ", c, ": ", a, "!=", b, "\n";
15                 var max int = len(a);
16                 if len(b) > max {
17                         max = len(b);
18                 }
19                 for i := 0; i < max; i++ {
20                         ac := 0;
21                         bc := 0;
22                         if i < len(a) {
23                                 ac = int(a[i]);
24                         }
25                         if i < len(b) {
26                                 bc = int(b[i]);
27                         }
28                         if ac != bc {
29                                 print "\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n";
30                         }
31                 }
32         }
33 }
34
35 func main() {
36         ecode = 0;
37         s :=
38                 ""
39                 " "
40                 "'`"
41                 "a"
42                 "ä"
43                 "本"
44                 "\a\b\f\n\r\t\v\\\""
45                 "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe"
46                 
47                 ``
48                 ` `
49                 `'"`
50                 `a`
51                 `ä`
52                 `本`
53                 `\a\b\f\n\r\t\v\\\'`
54                 `\000\123\x00\xca\xFE\u0123\ubabe\U0000babe`
55                 `\x\u\U\`
56         ;
57         assert("", ``, "empty");
58         assert(" ", " ", "blank");
59         assert("\x61", "a", "lowercase a");
60         assert("\x61", `a`, "lowercase a (backquote)");
61         assert("\u00e4", "ä", "a umlaut");
62         assert("\u00e4", `ä`, "a umlaut (backquote)");
63         assert("\u672c", "本", "nihon");
64         assert("\u672c", `本`, "nihon (backquote)");
65         assert("\x07\x08\x0c\x0a\x0d\x09\x0b\x5c\x22",
66                "\a\b\f\n\r\t\v\\\"",
67                "backslashes");
68         assert("\\a\\b\\f\\n\\r\\t\\v\\\\\\\"",
69                `\a\b\f\n\r\t\v\\\"`,
70                "backslashes (backquote)");
71         assert("\x00\x53\000\xca\376S몾몾",
72                "\000\123\x00\312\xFE\u0053\ubabe\U0000babe",
73                    "backslashes 2");
74         assert("\\000\\123\\x00\\312\\xFE\\u0123\\ubabe\\U0000babe",
75                `\000\123\x00\312\xFE\u0123\ubabe\U0000babe`,
76            "backslashes 2 (backquote)");
77         assert("\\x\\u\\U\\", `\x\u\U\`, "backslash 3 (backquote)");
78         sys.exit(ecode);
79 }