|
| 1 | +"hello world" |
| 2 | + |
| 3 | +"\"" # double quote |
| 4 | +"\\" # backslash |
| 5 | +"\#" # hash character (to escape interpolation) |
| 6 | +"\a" # alert |
| 7 | +"\b" # backspace |
| 8 | +"\e" # escape |
| 9 | +"\f" # form feed |
| 10 | +"\n" # newline |
| 11 | +"\r" # carriage return |
| 12 | +"\t" # tab |
| 13 | +"\v" # vertical tab |
| 14 | +"\377" # octal ASCII character |
| 15 | +"\xFF" # hexadecimal ASCII character |
| 16 | +"\uFFFF" # hexadecimal unicode character |
| 17 | +"\u{0}".."\u{10FFFF}" # hexadecimal unicode character |
| 18 | + |
| 19 | +"\101" # => "A" |
| 20 | +"\123" # => "S" |
| 21 | +"\12" # => "\n" |
| 22 | +"\1" # string with one character with code point 1 |
| 23 | + |
| 24 | +"\u{48 45 4C 4C 4F}" # => "HELLO" |
| 25 | + |
| 26 | +"sum: #{a} + #{b} = #{a + b}" |
| 27 | + |
| 28 | +"\#{a + b}" # => "#{a + b}" |
| 29 | +%q(#{a + b}) # => "#{a + b}" |
| 30 | + |
| 31 | +%(hello ("world")) # => "hello (\"world\")" |
| 32 | +%[hello ["world"]] # => "hello [\"world\"]" |
| 33 | +%{hello {"world"}} # => "hello {\"world\"}" |
| 34 | +%<hello <"world">> # => "hello <\"world\">" |
| 35 | +%|hello "world"| # => "hello \"world\"" |
| 36 | + |
| 37 | +name = "world" |
| 38 | +%q(hello \n #{name}) # => "hello \\n \#{name}" |
| 39 | +%Q(hello \n #{name}) # => "hello \n world" |
| 40 | + |
| 41 | +%w(foo bar baz) # => ["foo", "bar", "baz"] |
| 42 | +%w(foo\nbar baz) # => ["foo\\nbar", "baz"] |
| 43 | +%w(foo(bar) baz) # => ["foo(bar)", "baz"] |
| 44 | + |
| 45 | +%w(foo\ bar baz) # => ["foo bar", "baz"] |
| 46 | + |
| 47 | +"hello " \ |
| 48 | +"world, " \ |
| 49 | +"no newlines" # same as "hello world, no newlines" |
| 50 | + |
| 51 | +"hello \ |
| 52 | + world, \ |
| 53 | + no newlines" # same as "hello world, no newlines" |
| 54 | + |
| 55 | +<<-XML |
| 56 | +<parent> |
| 57 | + <child /> |
| 58 | +</parent> |
| 59 | +XML |
| 60 | + |
| 61 | +---------------------------------------------------- |
| 62 | + |
| 63 | +[ |
| 64 | + ["string-literal", [ |
| 65 | + ["string", "\"hello world\""] |
| 66 | + ]], |
| 67 | + |
| 68 | + ["string-literal", [ |
| 69 | + ["string", "\"\\\"\""] |
| 70 | + ]], |
| 71 | + ["comment", "# double quote"], |
| 72 | + |
| 73 | + ["string-literal", [ |
| 74 | + ["string", "\"\\\\\""] |
| 75 | + ]], |
| 76 | + ["comment", "# backslash"], |
| 77 | + |
| 78 | + ["string-literal", [ |
| 79 | + ["string", "\"\\#\""] |
| 80 | + ]], |
| 81 | + ["comment", "# hash character (to escape interpolation)"], |
| 82 | + |
| 83 | + ["string-literal", [ |
| 84 | + ["string", "\"\\a\""] |
| 85 | + ]], |
| 86 | + ["comment", "# alert"], |
| 87 | + |
| 88 | + ["string-literal", [ |
| 89 | + ["string", "\"\\b\""] |
| 90 | + ]], |
| 91 | + ["comment", "# backspace"], |
| 92 | + |
| 93 | + ["string-literal", [ |
| 94 | + ["string", "\"\\e\""] |
| 95 | + ]], |
| 96 | + ["comment", "# escape"], |
| 97 | + |
| 98 | + ["string-literal", [ |
| 99 | + ["string", "\"\\f\""] |
| 100 | + ]], |
| 101 | + ["comment", "# form feed"], |
| 102 | + |
| 103 | + ["string-literal", [ |
| 104 | + ["string", "\"\\n\""] |
| 105 | + ]], |
| 106 | + ["comment", "# newline"], |
| 107 | + |
| 108 | + ["string-literal", [ |
| 109 | + ["string", "\"\\r\""] |
| 110 | + ]], |
| 111 | + ["comment", "# carriage return"], |
| 112 | + |
| 113 | + ["string-literal", [ |
| 114 | + ["string", "\"\\t\""] |
| 115 | + ]], |
| 116 | + ["comment", "# tab"], |
| 117 | + |
| 118 | + ["string-literal", [ |
| 119 | + ["string", "\"\\v\""] |
| 120 | + ]], |
| 121 | + ["comment", "# vertical tab"], |
| 122 | + |
| 123 | + ["string-literal", [ |
| 124 | + ["string", "\"\\377\""] |
| 125 | + ]], |
| 126 | + ["comment", "# octal ASCII character"], |
| 127 | + |
| 128 | + ["string-literal", [ |
| 129 | + ["string", "\"\\xFF\""] |
| 130 | + ]], |
| 131 | + ["comment", "# hexadecimal ASCII character"], |
| 132 | + |
| 133 | + ["string-literal", [ |
| 134 | + ["string", "\"\\uFFFF\""] |
| 135 | + ]], |
| 136 | + ["comment", "# hexadecimal unicode character"], |
| 137 | + |
| 138 | + ["string-literal", [ |
| 139 | + ["string", "\"\\u{0}\""] |
| 140 | + ]], |
| 141 | + ["operator", ".."], |
| 142 | + ["string-literal", [ |
| 143 | + ["string", "\"\\u{10FFFF}\""] |
| 144 | + ]], |
| 145 | + ["comment", "# hexadecimal unicode character"], |
| 146 | + |
| 147 | + ["string-literal", [ |
| 148 | + ["string", "\"\\101\""] |
| 149 | + ]], |
| 150 | + ["comment", "# => \"A\""], |
| 151 | + |
| 152 | + ["string-literal", [ |
| 153 | + ["string", "\"\\123\""] |
| 154 | + ]], |
| 155 | + ["comment", "# => \"S\""], |
| 156 | + |
| 157 | + ["string-literal", [ |
| 158 | + ["string", "\"\\12\""] |
| 159 | + ]], |
| 160 | + ["comment", "# => \"\\n\""], |
| 161 | + |
| 162 | + ["string-literal", [ |
| 163 | + ["string", "\"\\1\""] |
| 164 | + ]], |
| 165 | + ["comment", "# string with one character with code point 1"], |
| 166 | + |
| 167 | + ["string-literal", [ |
| 168 | + ["string", "\"\\u{48 45 4C 4C 4F}\""] |
| 169 | + ]], |
| 170 | + ["comment", "# => \"HELLO\""], |
| 171 | + |
| 172 | + ["string-literal", [ |
| 173 | + ["string", "\"sum: "], |
| 174 | + ["interpolation", [ |
| 175 | + ["delimiter", "#{"], |
| 176 | + ["content", ["a"]], |
| 177 | + ["delimiter", "}"] |
| 178 | + ]], |
| 179 | + ["string", " + "], |
| 180 | + ["interpolation", [ |
| 181 | + ["delimiter", "#{"], |
| 182 | + ["content", ["b"]], |
| 183 | + ["delimiter", "}"] |
| 184 | + ]], |
| 185 | + ["string", " = "], |
| 186 | + ["interpolation", [ |
| 187 | + ["delimiter", "#{"], |
| 188 | + ["content", [ |
| 189 | + "a ", |
| 190 | + ["operator", "+"], |
| 191 | + " b" |
| 192 | + ]], |
| 193 | + ["delimiter", "}"] |
| 194 | + ]], |
| 195 | + ["string", "\""] |
| 196 | + ]], |
| 197 | + |
| 198 | + ["string-literal", [ |
| 199 | + ["string", "\"\\#{a + b}\""] |
| 200 | + ]], |
| 201 | + ["comment", "# => \"#{a + b}\""], |
| 202 | + |
| 203 | + ["string-literal", [ |
| 204 | + ["string", "%q("], |
| 205 | + ["interpolation", [ |
| 206 | + ["delimiter", "#{"], |
| 207 | + ["content", [ |
| 208 | + "a ", |
| 209 | + ["operator", "+"], |
| 210 | + " b" |
| 211 | + ]], |
| 212 | + ["delimiter", "}"] |
| 213 | + ]], |
| 214 | + ["string", ")"] |
| 215 | + ]], |
| 216 | + ["comment", "# => \"#{a + b}\""], |
| 217 | + |
| 218 | + ["string-literal", [ |
| 219 | + ["string", "%(hello (\"world\"))"] |
| 220 | + ]], |
| 221 | + ["comment", "# => \"hello (\\\"world\\\")\""], |
| 222 | + |
| 223 | + ["string-literal", [ |
| 224 | + ["string", "%[hello [\"world\"]]"] |
| 225 | + ]], |
| 226 | + ["comment", "# => \"hello [\\\"world\\\"]\""], |
| 227 | + |
| 228 | + ["string-literal", [ |
| 229 | + ["string", "%{hello {\"world\"}}"] |
| 230 | + ]], |
| 231 | + ["comment", "# => \"hello {\\\"world\\\"}\""], |
| 232 | + |
| 233 | + ["string-literal", [ |
| 234 | + ["string", "%<hello <\"world\">>"] |
| 235 | + ]], |
| 236 | + ["comment", "# => \"hello <\\\"world\\\">\""], |
| 237 | + |
| 238 | + ["string-literal", [ |
| 239 | + ["string", "%|hello \"world\"|"] |
| 240 | + ]], |
| 241 | + ["comment", "# => \"hello \\\"world\\\"\""], |
| 242 | + |
| 243 | + "\r\n\r\nname ", |
| 244 | + ["operator", "="], |
| 245 | + ["string-literal", [ |
| 246 | + ["string", "\"world\""] |
| 247 | + ]], |
| 248 | + |
| 249 | + ["string-literal", [ |
| 250 | + ["string", "%q(hello \\n "], |
| 251 | + ["interpolation", [ |
| 252 | + ["delimiter", "#{"], |
| 253 | + ["content", ["name"]], |
| 254 | + ["delimiter", "}"] |
| 255 | + ]], |
| 256 | + ["string", ")"] |
| 257 | + ]], |
| 258 | + ["comment", "# => \"hello \\\\n \\#{name}\""], |
| 259 | + |
| 260 | + ["string-literal", [ |
| 261 | + ["string", "%Q(hello \\n "], |
| 262 | + ["interpolation", [ |
| 263 | + ["delimiter", "#{"], |
| 264 | + ["content", ["name"]], |
| 265 | + ["delimiter", "}"] |
| 266 | + ]], |
| 267 | + ["string", ")"] |
| 268 | + ]], |
| 269 | + ["comment", "# => \"hello \\n world\""], |
| 270 | + |
| 271 | + ["string-literal", [ |
| 272 | + ["string", "%w(foo bar baz)"] |
| 273 | + ]], |
| 274 | + ["comment", "# => [\"foo\", \"bar\", \"baz\"]"], |
| 275 | + |
| 276 | + ["string-literal", [ |
| 277 | + ["string", "%w(foo\\nbar baz)"] |
| 278 | + ]], |
| 279 | + ["comment", "# => [\"foo\\\\nbar\", \"baz\"]"], |
| 280 | + |
| 281 | + ["string-literal", [ |
| 282 | + ["string", "%w(foo(bar) baz)"] |
| 283 | + ]], |
| 284 | + ["comment", "# => [\"foo(bar)\", \"baz\"]"], |
| 285 | + |
| 286 | + ["string-literal", [ |
| 287 | + ["string", "%w(foo\\ bar baz)"] |
| 288 | + ]], |
| 289 | + ["comment", "# => [\"foo bar\", \"baz\"]"], |
| 290 | + |
| 291 | + ["string-literal", [ |
| 292 | + ["string", "\"hello \""] |
| 293 | + ]], |
| 294 | + ["punctuation", "\\"], |
| 295 | + |
| 296 | + ["string-literal", [ |
| 297 | + ["string", "\"world, \""] |
| 298 | + ]], |
| 299 | + ["punctuation", "\\"], |
| 300 | + |
| 301 | + ["string-literal", [ |
| 302 | + ["string", "\"no newlines\""] |
| 303 | + ]], |
| 304 | + ["comment", "# same as \"hello world, no newlines\""], |
| 305 | + |
| 306 | + ["string-literal", [ |
| 307 | + ["string", "\"hello \\\r\n world, \\\r\n no newlines\""] |
| 308 | + ]], |
| 309 | + ["comment", "# same as \"hello world, no newlines\""], |
| 310 | + |
| 311 | + ["string-literal", [ |
| 312 | + ["delimiter", [ |
| 313 | + ["punctuation", "<<-"], |
| 314 | + ["symbol", "XML"] |
| 315 | + ]], |
| 316 | + ["string", "\r\n<parent>\r\n <child />\r\n</parent>\r\n"], |
| 317 | + ["delimiter", [ |
| 318 | + ["symbol", "XML"] |
| 319 | + ]] |
| 320 | + ]] |
| 321 | +] |
0 commit comments