Debian Codegraph @

test_suite/text_block.jsonnet

raw
1 /*
2 Copyright 2015 Google Inc. All rights reserved.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 // Golden
18 local bash_golden = std.lines([
19 "#!/usr/bin/env bash",
20 "if [ $# -lt 1 ] ; then",
21 " echo \"No arguments!\"",
22 "else",
23 " echo \"$# arguments!\"",
24 "fi",
25 ]);
26
27 // Soft tabs
28 local bash_soft = |||
29 #!/usr/bin/env bash
30 if [ $# -lt 1 ] ; then
31 echo "No arguments!"
32 else
33 echo "$# arguments!"
34 fi
35 |||;
36 std.assertEqual(bash_golden, bash_soft) &&
37
38 // Hard tabs
39 local bash_hard = |||
40 #!/usr/bin/env bash
41 if [ $# -lt 1 ] ; then
42 echo "No arguments!"
43 else
44 echo "$# arguments!"
45 fi
46 |||;
47 std.assertEqual(bash_golden, bash_hard) &&
48
49 // Mixed tabs
50 local bash_mixed = |||
51 #!/usr/bin/env bash
52 if [ $# -lt 1 ] ; then
53 echo "No arguments!"
54 else
55 echo "$# arguments!"
56 fi
57 |||;
58 std.assertEqual(bash_golden, bash_mixed) &&
59
60
61 // Chomp trailing newline
62 local str1 = |||-
63 foo bar baz
64 |||;
65
66 std.assertEqual(str1, "foo bar baz") &&
67
68
69 // Chomp just one trailing newline
70 local str1 = |||-
71 foo bar baz
72
73 |||;
74
75 std.assertEqual(str1, "foo bar baz\n") &&
76
77
78 // Concatenate chomped blocks
79 local str1 = |||-
80 foo bar baz
81 ||| + " " + |||-
82 biz buzz
83 |||;
84
85 std.assertEqual(str1, "foo bar baz biz buzz") &&
86
87
88 // More indent
89 local str1 = |||
90 text
91 |||;
92
93 std.assertEqual(str1, "text\n") &&
94
95
96 // Escape chars
97 local str1 = |||
98 \n
99 |||;
100
101 std.assertEqual(str1, "\\n\n") &&
102
103
104 // Blank line with trailing whitespace
105 local blank_line1 = |||
106 foo
107
108 bar
109 |||;
110
111 std.assertEqual(blank_line1, "foo\n\nbar\n") &&
112
113
114 // Blank line no trailing whitespace
115 local blank_line2 = |||
116 foo
117
118 bar
119 |||;
120
121 std.assertEqual(blank_line2, "foo\n\nbar\n") &&
122
123 // Initial blank line
124 local blank_line3 = |||
125
126 foo
127 |||;
128
129 std.assertEqual(blank_line3, "\nfoo\n") &&
130
131 // Interaction with operators (1)
132 local op1 = "foo"+|||
133 foo
134 |||;
135
136 std.assertEqual(op1, "foofoo\n") &&
137
138 // Interaction with operators (2)
139 local op2 = "foo"<|||
140 foo
141 |||;
142
143 std.assertEqual(op2, true) &&
144
145 // whitespace after |||
146 local whitespace_after = |||
147 foo
148 |||;
149
150 std.assertEqual(whitespace_after, "foo\n") &&
151
152
153 true