]> Cypherpunks.ru repositories - gostls13.git/blob - test/string_lit.go
- gofmt these files
[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 import "os"
10
11 var ecode int
12
13 func assert(a, b, c string) {
14         if a != b {
15                 ecode = 1;
16                 print("FAIL: ", c, ": ", a, "!=", b, "\n");
17                 var max int = len(a);
18                 if len(b) > max {
19                         max = len(b)
20                 }
21                 for i := 0; i < max; i++ {
22                         ac := 0;
23                         bc := 0;
24                         if i < len(a) {
25                                 ac = int(a[i])
26                         }
27                         if i < len(b) {
28                                 bc = int(b[i])
29                         }
30                         if ac != bc {
31                                 print("\ta[", i, "] = ", ac, "; b[", i, "] =", bc, "\n")
32                         }
33                 }
34         }
35 }
36
37 func main() {
38         ecode = 0;
39         s :=
40                 "" +
41                         " " +
42                         "'`" +
43                         "a" +
44                         "ä" +
45                         "本" +
46                         "\a\b\f\n\r\t\v\\\"" +
47                         "\000\123\x00\xca\xFE\u0123\ubabe\U0000babe" +
48
49                         `` +
50                         ` ` +
51                         `'"` +
52                         `a` +
53                         `ä` +
54                         `本` +
55                         `\a\b\f\n\r\t\v\\\'` +
56                         `\000\123\x00\xca\xFE\u0123\ubabe\U0000babe` +
57                         `\x\u\U\`;
58
59         assert("", ``, "empty");
60         assert(" ", " ", "blank");
61         assert("\x61", "a", "lowercase a");
62         assert("\x61", `a`, "lowercase a (backquote)");
63         assert("\u00e4", "ä", "a umlaut");
64         assert("\u00e4", `ä`, "a umlaut (backquote)");
65         assert("\u672c", "本", "nihon");
66         assert("\u672c", `本`, "nihon (backquote)");
67         assert("\x07\x08\x0c\x0a\x0d\x09\x0b\x5c\x22",
68                 "\a\b\f\n\r\t\v\\\"",
69                 "backslashes");
70         assert("\\a\\b\\f\\n\\r\\t\\v\\\\\\\"",
71                 `\a\b\f\n\r\t\v\\\"`,
72                 "backslashes (backquote)");
73         assert("\x00\x53\000\xca\376S몾몾",
74                 "\000\123\x00\312\xFE\u0053\ubabe\U0000babe",
75                 "backslashes 2");
76         assert("\\000\\123\\x00\\312\\xFE\\u0123\\ubabe\\U0000babe",
77                 `\000\123\x00\312\xFE\u0123\ubabe\U0000babe`,
78                 "backslashes 2 (backquote)");
79         assert("\\x\\u\\U\\", `\x\u\U\`, "backslash 3 (backquote)");
80
81         // test large runes. perhaps not the most logical place for this test.
82         var r int32;
83         r = 0x10ffff;   // largest rune value
84         s = string(r);
85         assert(s, "\xf4\x8f\xbf\xbf", "largest rune");
86         r = 0x10ffff + 1;
87         s = string(r);
88         assert(s, "\xef\xbf\xbd", "too-large rune");
89         os.Exit(ecode);
90 }