| 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 |
std.assertEqual(str1, 'foo bar baz\n') && |
| 75 |
|
| 76 |
|
| 77 |
// Concatenate chomped blocks |
| 78 |
local str1 = |||- |
| 79 |
foo bar baz |
| 80 |
||| + ' ' + |||- |
| 81 |
biz buzz |
| 82 |
|||; |
| 83 |
|
| 84 |
std.assertEqual(str1, 'foo bar baz biz buzz') && |
| 85 |
|
| 86 |
|
| 87 |
// More indent |
| 88 |
local str1 = ||| |
| 89 |
text |
| 90 |
|||; |
| 91 |
|
| 92 |
std.assertEqual(str1, 'text\n') && |
| 93 |
|
| 94 |
|
| 95 |
// Escape chars |
| 96 |
local str1 = ||| |
| 97 |
\n |
| 98 |
|||; |
| 99 |
|
| 100 |
std.assertEqual(str1, '\\n\n') && |
| 101 |
|
| 102 |
|
| 103 |
// Blank line with trailing whitespace |
| 104 |
local blank_line1 = ||| |
| 105 |
foo |
| 106 |
|
| 107 |
bar |
| 108 |
|||; |
| 109 |
|
| 110 |
std.assertEqual(blank_line1, 'foo\n\nbar\n') && |
| 111 |
|
| 112 |
|
| 113 |
// Blank line no trailing whitespace |
| 114 |
local blank_line2 = ||| |
| 115 |
foo |
| 116 |
|
| 117 |
bar |
| 118 |
|||; |
| 119 |
|
| 120 |
std.assertEqual(blank_line2, 'foo\n\nbar\n') && |
| 121 |
|
| 122 |
// Initial blank line |
| 123 |
local blank_line3 = ||| |
| 124 |
|
| 125 |
foo |
| 126 |
|||; |
| 127 |
|
| 128 |
std.assertEqual(blank_line3, '\nfoo\n') && |
| 129 |
|
| 130 |
// Interaction with operators (1) |
| 131 |
local op1 = 'foo' + ||| |
| 132 |
foo |
| 133 |
|||; |
| 134 |
|
| 135 |
std.assertEqual(op1, 'foofoo\n') && |
| 136 |
|
| 137 |
// Interaction with operators (2) |
| 138 |
local op2 = 'foo' < ||| |
| 139 |
foo |
| 140 |
|||; |
| 141 |
|
| 142 |
std.assertEqual(op2, true) && |
| 143 |
|
| 144 |
// whitespace after ||| |
| 145 |
local whitespace_after = ||| |
| 146 |
foo |
| 147 |
|||; |
| 148 |
|
| 149 |
std.assertEqual(whitespace_after, 'foo\n') && |
| 150 |
|
| 151 |
|
| 152 |
true |