| 1 |
|
| 2 |
|
| 3 |
"use strict"; |
| 4 |
|
| 5 |
describe("compiler pass |generateBytecode|", function() { |
| 6 |
var pass = peg.compiler.passes.generate.generateBytecode; |
| 7 |
|
| 8 |
function bytecodeDetails(bytecode) { |
| 9 |
return { |
| 10 |
rules: [{ bytecode: bytecode }] |
| 11 |
}; |
| 12 |
} |
| 13 |
|
| 14 |
function constsDetails(consts) { return { consts: consts }; } |
| 15 |
|
| 16 |
describe("for grammar", function() { |
| 17 |
it("generates correct bytecode", function() { |
| 18 |
expect(pass).toChangeAST([ |
| 19 |
'a = "a"', |
| 20 |
'b = "b"', |
| 21 |
'c = "c"' |
| 22 |
].join("\n"), { |
| 23 |
rules: [ |
| 24 |
{ bytecode: [18, 0, 2, 2, 22, 0, 23, 1] }, |
| 25 |
{ bytecode: [18, 2, 2, 2, 22, 2, 23, 3] }, |
| 26 |
{ bytecode: [18, 4, 2, 2, 22, 4, 23, 5] } |
| 27 |
] |
| 28 |
}); |
| 29 |
}); |
| 30 |
|
| 31 |
it("defines correct constants", function() { |
| 32 |
expect(pass).toChangeAST([ |
| 33 |
'a = "a"', |
| 34 |
'b = "b"', |
| 35 |
'c = "c"' |
| 36 |
].join("\n"), constsDetails([ |
| 37 |
'"a"', |
| 38 |
'peg$literalExpectation("a", false)', |
| 39 |
'"b"', |
| 40 |
'peg$literalExpectation("b", false)', |
| 41 |
'"c"', |
| 42 |
'peg$literalExpectation("c", false)' |
| 43 |
])); |
| 44 |
}); |
| 45 |
}); |
| 46 |
|
| 47 |
describe("for rule", function() { |
| 48 |
it("generates correct bytecode", function() { |
| 49 |
expect(pass).toChangeAST('start = "a"', bytecodeDetails([ |
| 50 |
18, 0, 2, 2, 22, 0, 23, 1 |
| 51 |
])); |
| 52 |
}); |
| 53 |
}); |
| 54 |
|
| 55 |
describe("for named", function() { |
| 56 |
var grammar = 'start "start" = "a"'; |
| 57 |
|
| 58 |
it("generates correct bytecode", function() { |
| 59 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 60 |
28, |
| 61 |
18, 1, 2, 2, 22, 1, 23, 2, |
| 62 |
29, |
| 63 |
14, 2, 0, |
| 64 |
23, 0 |
| 65 |
])); |
| 66 |
}); |
| 67 |
|
| 68 |
it("defines correct constants", function() { |
| 69 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 70 |
'peg$otherExpectation("start")', |
| 71 |
'"a"', |
| 72 |
'peg$literalExpectation("a", false)' |
| 73 |
])); |
| 74 |
}); |
| 75 |
}); |
| 76 |
|
| 77 |
describe("for choice", function() { |
| 78 |
it("generates correct bytecode", function() { |
| 79 |
expect(pass).toChangeAST('start = "a" / "b" / "c"', bytecodeDetails([ |
| 80 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 81 |
14, 21, 0, |
| 82 |
6, |
| 83 |
18, 2, 2, 2, 22, 2, 23, 3, |
| 84 |
14, 9, 0, |
| 85 |
6, |
| 86 |
18, 4, 2, 2, 22, 4, 23, 5 |
| 87 |
])); |
| 88 |
}); |
| 89 |
}); |
| 90 |
|
| 91 |
describe("for action", function() { |
| 92 |
describe("without labels", function() { |
| 93 |
var grammar = 'start = "a" { code }'; |
| 94 |
|
| 95 |
it("generates correct bytecode", function() { |
| 96 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 97 |
5, |
| 98 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 99 |
15, 6, 0, |
| 100 |
24, 1, |
| 101 |
26, 2, 1, 0, |
| 102 |
9 |
| 103 |
])); |
| 104 |
}); |
| 105 |
|
| 106 |
it("defines correct constants", function() { |
| 107 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 108 |
'"a"', |
| 109 |
'peg$literalExpectation("a", false)', |
| 110 |
'function() { code }' |
| 111 |
])); |
| 112 |
}); |
| 113 |
}); |
| 114 |
|
| 115 |
describe("with one label", function() { |
| 116 |
var grammar = 'start = a:"a" { code }'; |
| 117 |
|
| 118 |
it("generates correct bytecode", function() { |
| 119 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 120 |
5, |
| 121 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 122 |
15, 7, 0, |
| 123 |
24, 1, |
| 124 |
26, 2, 1, 1, 0, |
| 125 |
9 |
| 126 |
])); |
| 127 |
}); |
| 128 |
|
| 129 |
it("defines correct constants", function() { |
| 130 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 131 |
'"a"', |
| 132 |
'peg$literalExpectation("a", false)', |
| 133 |
'function(a) { code }' |
| 134 |
])); |
| 135 |
}); |
| 136 |
}); |
| 137 |
|
| 138 |
describe("with multiple labels", function() { |
| 139 |
var grammar = 'start = a:"a" b:"b" c:"c" { code }'; |
| 140 |
|
| 141 |
it("generates correct bytecode", function() { |
| 142 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 143 |
5, |
| 144 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 145 |
15, 40, 3, |
| 146 |
18, 2, 2, 2, 22, 2, 23, 3, |
| 147 |
15, 25, 4, |
| 148 |
18, 4, 2, 2, 22, 4, 23, 5, |
| 149 |
15, 10, 4, |
| 150 |
24, 3, |
| 151 |
26, 6, 3, 3, 2, 1, 0, |
| 152 |
9, |
| 153 |
8, 3, |
| 154 |
7, |
| 155 |
3, |
| 156 |
8, 2, |
| 157 |
7, |
| 158 |
3, |
| 159 |
6, |
| 160 |
7, |
| 161 |
3 |
| 162 |
])); |
| 163 |
}); |
| 164 |
|
| 165 |
it("defines correct constants", function() { |
| 166 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 167 |
'"a"', |
| 168 |
'peg$literalExpectation("a", false)', |
| 169 |
'"b"', |
| 170 |
'peg$literalExpectation("b", false)', |
| 171 |
'"c"', |
| 172 |
'peg$literalExpectation("c", false)', |
| 173 |
'function(a, b, c) { code }' |
| 174 |
])); |
| 175 |
}); |
| 176 |
}); |
| 177 |
}); |
| 178 |
|
| 179 |
describe("for sequence", function() { |
| 180 |
var grammar = 'start = "a" "b" "c"'; |
| 181 |
|
| 182 |
it("generates correct bytecode", function() { |
| 183 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 184 |
5, |
| 185 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 186 |
15, 33, 3, |
| 187 |
18, 2, 2, 2, 22, 2, 23, 3, |
| 188 |
15, 18, 4, |
| 189 |
18, 4, 2, 2, 22, 4, 23, 5, |
| 190 |
15, 3, 4, |
| 191 |
11, 3, |
| 192 |
9, |
| 193 |
8, 3, |
| 194 |
7, |
| 195 |
3, |
| 196 |
8, 2, |
| 197 |
7, |
| 198 |
3, |
| 199 |
6, |
| 200 |
7, |
| 201 |
3 |
| 202 |
])); |
| 203 |
}); |
| 204 |
|
| 205 |
it("defines correct constants", function() { |
| 206 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 207 |
'"a"', |
| 208 |
'peg$literalExpectation("a", false)', |
| 209 |
'"b"', |
| 210 |
'peg$literalExpectation("b", false)', |
| 211 |
'"c"', |
| 212 |
'peg$literalExpectation("c", false)' |
| 213 |
])); |
| 214 |
}); |
| 215 |
}); |
| 216 |
|
| 217 |
describe("for labeled", function() { |
| 218 |
it("generates correct bytecode", function() { |
| 219 |
expect(pass).toChangeAST('start = a:"a"', bytecodeDetails([ |
| 220 |
18, 0, 2, 2, 22, 0, 23, 1 |
| 221 |
])); |
| 222 |
}); |
| 223 |
}); |
| 224 |
|
| 225 |
describe("for text", function() { |
| 226 |
it("generates correct bytecode", function() { |
| 227 |
expect(pass).toChangeAST('start = $"a"', bytecodeDetails([ |
| 228 |
5, |
| 229 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 230 |
15, 2, 1, |
| 231 |
6, |
| 232 |
12, |
| 233 |
9 |
| 234 |
])); |
| 235 |
}); |
| 236 |
}); |
| 237 |
|
| 238 |
describe("for simple_and", function() { |
| 239 |
var grammar = 'start = &"a"'; |
| 240 |
|
| 241 |
it("generates correct bytecode", function() { |
| 242 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 243 |
5, |
| 244 |
28, |
| 245 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 246 |
29, |
| 247 |
15, 3, 3, |
| 248 |
6, |
| 249 |
7, |
| 250 |
1, |
| 251 |
6, |
| 252 |
6, |
| 253 |
3 |
| 254 |
])); |
| 255 |
}); |
| 256 |
|
| 257 |
it("defines correct constants", function() { |
| 258 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 259 |
'"a"', |
| 260 |
'peg$literalExpectation("a", false)' |
| 261 |
])); |
| 262 |
}); |
| 263 |
}); |
| 264 |
|
| 265 |
describe("for simple_not", function() { |
| 266 |
var grammar = 'start = !"a"'; |
| 267 |
|
| 268 |
it("generates correct bytecode", function() { |
| 269 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 270 |
5, |
| 271 |
28, |
| 272 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 273 |
29, |
| 274 |
14, 3, 3, |
| 275 |
6, |
| 276 |
6, |
| 277 |
1, |
| 278 |
6, |
| 279 |
7, |
| 280 |
3 |
| 281 |
])); |
| 282 |
}); |
| 283 |
|
| 284 |
it("defines correct constants", function() { |
| 285 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 286 |
'"a"', |
| 287 |
'peg$literalExpectation("a", false)' |
| 288 |
])); |
| 289 |
}); |
| 290 |
}); |
| 291 |
|
| 292 |
describe("for optional", function() { |
| 293 |
var grammar = 'start = "a"?'; |
| 294 |
|
| 295 |
it("generates correct bytecode", function() { |
| 296 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 297 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 298 |
14, 2, 0, |
| 299 |
6, |
| 300 |
2 |
| 301 |
])); |
| 302 |
}); |
| 303 |
|
| 304 |
it("defines correct constants", function() { |
| 305 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 306 |
'"a"', |
| 307 |
'peg$literalExpectation("a", false)' |
| 308 |
])); |
| 309 |
}); |
| 310 |
}); |
| 311 |
|
| 312 |
describe("for zero_or_more", function() { |
| 313 |
var grammar = 'start = "a"*'; |
| 314 |
|
| 315 |
it("generates correct bytecode", function() { |
| 316 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 317 |
4, |
| 318 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 319 |
16, 9, |
| 320 |
10, |
| 321 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 322 |
6 |
| 323 |
])); |
| 324 |
}); |
| 325 |
|
| 326 |
it("defines correct constants", function() { |
| 327 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 328 |
'"a"', |
| 329 |
'peg$literalExpectation("a", false)' |
| 330 |
])); |
| 331 |
}); |
| 332 |
}); |
| 333 |
|
| 334 |
describe("for one_or_more", function() { |
| 335 |
var grammar = 'start = "a"+'; |
| 336 |
|
| 337 |
it("generates correct bytecode", function() { |
| 338 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 339 |
4, |
| 340 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 341 |
15, 12, 3, |
| 342 |
16, 9, |
| 343 |
10, |
| 344 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 345 |
6, |
| 346 |
6, |
| 347 |
6, |
| 348 |
3 |
| 349 |
])); |
| 350 |
}); |
| 351 |
|
| 352 |
it("defines correct constants", function() { |
| 353 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 354 |
'"a"', |
| 355 |
'peg$literalExpectation("a", false)' |
| 356 |
])); |
| 357 |
}); |
| 358 |
}); |
| 359 |
|
| 360 |
describe("for group", function() { |
| 361 |
it("generates correct bytecode", function() { |
| 362 |
expect(pass).toChangeAST('start = ("a")', bytecodeDetails([ |
| 363 |
18, 0, 2, 2, 22, 0, 23, 1 |
| 364 |
])); |
| 365 |
}); |
| 366 |
}); |
| 367 |
|
| 368 |
describe("for semantic_and", function() { |
| 369 |
describe("without labels", function() { |
| 370 |
var grammar = 'start = &{ code }'; |
| 371 |
|
| 372 |
it("generates correct bytecode", function() { |
| 373 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 374 |
25, |
| 375 |
26, 0, 0, 0, |
| 376 |
13, 2, 2, |
| 377 |
6, |
| 378 |
1, |
| 379 |
6, |
| 380 |
3 |
| 381 |
])); |
| 382 |
}); |
| 383 |
|
| 384 |
it("defines correct constants", function() { |
| 385 |
expect(pass).toChangeAST( |
| 386 |
grammar, |
| 387 |
constsDetails(['function() { code }']) |
| 388 |
); |
| 389 |
}); |
| 390 |
}); |
| 391 |
|
| 392 |
describe("with labels", function() { |
| 393 |
var grammar = 'start = a:"a" b:"b" c:"c" &{ code }'; |
| 394 |
|
| 395 |
it("generates correct bytecode", function() { |
| 396 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 397 |
5, |
| 398 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 399 |
15, 55, 3, |
| 400 |
18, 2, 2, 2, 22, 2, 23, 3, |
| 401 |
15, 40, 4, |
| 402 |
18, 4, 2, 2, 22, 4, 23, 5, |
| 403 |
15, 25, 4, |
| 404 |
25, |
| 405 |
26, 6, 0, 3, 2, 1, 0, |
| 406 |
13, 2, 2, |
| 407 |
6, |
| 408 |
1, |
| 409 |
6, |
| 410 |
3, |
| 411 |
15, 3, 4, |
| 412 |
11, 4, |
| 413 |
9, |
| 414 |
8, 4, |
| 415 |
7, |
| 416 |
3, |
| 417 |
8, 3, |
| 418 |
7, |
| 419 |
3, |
| 420 |
8, 2, |
| 421 |
7, |
| 422 |
3, |
| 423 |
6, |
| 424 |
7, |
| 425 |
3 |
| 426 |
])); |
| 427 |
}); |
| 428 |
|
| 429 |
it("defines correct constants", function() { |
| 430 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 431 |
'"a"', |
| 432 |
'peg$literalExpectation("a", false)', |
| 433 |
'"b"', |
| 434 |
'peg$literalExpectation("b", false)', |
| 435 |
'"c"', |
| 436 |
'peg$literalExpectation("c", false)', |
| 437 |
'function(a, b, c) { code }' |
| 438 |
])); |
| 439 |
}); |
| 440 |
}); |
| 441 |
}); |
| 442 |
|
| 443 |
describe("for semantic_not", function() { |
| 444 |
describe("without labels", function() { |
| 445 |
var grammar = 'start = !{ code }'; |
| 446 |
|
| 447 |
it("generates correct bytecode", function() { |
| 448 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 449 |
25, |
| 450 |
26, 0, 0, 0, |
| 451 |
13, 2, 2, |
| 452 |
6, |
| 453 |
3, |
| 454 |
6, |
| 455 |
1 |
| 456 |
])); |
| 457 |
}); |
| 458 |
|
| 459 |
it("defines correct constants", function() { |
| 460 |
expect(pass).toChangeAST( |
| 461 |
grammar, |
| 462 |
constsDetails(['function() { code }']) |
| 463 |
); |
| 464 |
}); |
| 465 |
}); |
| 466 |
|
| 467 |
describe("with labels", function() { |
| 468 |
var grammar = 'start = a:"a" b:"b" c:"c" !{ code }'; |
| 469 |
|
| 470 |
it("generates correct bytecode", function() { |
| 471 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 472 |
5, |
| 473 |
18, 0, 2, 2, 22, 0, 23, 1, |
| 474 |
15, 55, 3, |
| 475 |
18, 2, 2, 2, 22, 2, 23, 3, |
| 476 |
15, 40, 4, |
| 477 |
18, 4, 2, 2, 22, 4, 23, 5, |
| 478 |
15, 25, 4, |
| 479 |
25, |
| 480 |
26, 6, 0, 3, 2, 1, 0, |
| 481 |
13, 2, 2, |
| 482 |
6, |
| 483 |
3, |
| 484 |
6, |
| 485 |
1, |
| 486 |
15, 3, 4, |
| 487 |
11, 4, |
| 488 |
9, |
| 489 |
8, 4, |
| 490 |
7, |
| 491 |
3, |
| 492 |
8, 3, |
| 493 |
7, |
| 494 |
3, |
| 495 |
8, 2, |
| 496 |
7, |
| 497 |
3, |
| 498 |
6, |
| 499 |
7, |
| 500 |
3 |
| 501 |
])); |
| 502 |
}); |
| 503 |
|
| 504 |
it("defines correct constants", function() { |
| 505 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 506 |
'"a"', |
| 507 |
'peg$literalExpectation("a", false)', |
| 508 |
'"b"', |
| 509 |
'peg$literalExpectation("b", false)', |
| 510 |
'"c"', |
| 511 |
'peg$literalExpectation("c", false)', |
| 512 |
'function(a, b, c) { code }' |
| 513 |
])); |
| 514 |
}); |
| 515 |
}); |
| 516 |
}); |
| 517 |
|
| 518 |
describe("for rule_ref", function() { |
| 519 |
it("generates correct bytecode", function() { |
| 520 |
expect(pass).toChangeAST([ |
| 521 |
'start = other', |
| 522 |
'other = "other"' |
| 523 |
].join("\n"), { |
| 524 |
rules: [ |
| 525 |
{ |
| 526 |
bytecode: [27, 1] |
| 527 |
}, |
| 528 |
{ } |
| 529 |
] |
| 530 |
}); |
| 531 |
}); |
| 532 |
}); |
| 533 |
|
| 534 |
describe("for literal", function() { |
| 535 |
describe("empty", function() { |
| 536 |
var grammar = 'start = ""'; |
| 537 |
|
| 538 |
it("generates correct bytecode", function() { |
| 539 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 540 |
0, 0 |
| 541 |
])); |
| 542 |
}); |
| 543 |
|
| 544 |
it("defines correct constants", function() { |
| 545 |
expect(pass).toChangeAST(grammar, constsDetails(['""'])); |
| 546 |
}); |
| 547 |
}); |
| 548 |
|
| 549 |
describe("non-empty case-sensitive", function() { |
| 550 |
var grammar = 'start = "a"'; |
| 551 |
|
| 552 |
it("generates correct bytecode", function() { |
| 553 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 554 |
18, 0, 2, 2, |
| 555 |
22, 0, |
| 556 |
23, 1 |
| 557 |
])); |
| 558 |
}); |
| 559 |
|
| 560 |
it("defines correct constants", function() { |
| 561 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 562 |
'"a"', |
| 563 |
'peg$literalExpectation("a", false)' |
| 564 |
])); |
| 565 |
}); |
| 566 |
}); |
| 567 |
|
| 568 |
describe("non-empty case-insensitive", function() { |
| 569 |
var grammar = 'start = "A"i'; |
| 570 |
|
| 571 |
it("generates correct bytecode", function() { |
| 572 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 573 |
19, 0, 2, 2, |
| 574 |
21, 1, |
| 575 |
23, 1 |
| 576 |
])); |
| 577 |
}); |
| 578 |
|
| 579 |
it("defines correct constants", function() { |
| 580 |
expect(pass).toChangeAST(grammar, constsDetails([ |
| 581 |
'"a"', |
| 582 |
'peg$literalExpectation("A", true)' |
| 583 |
])); |
| 584 |
}); |
| 585 |
}); |
| 586 |
}); |
| 587 |
|
| 588 |
describe("for class", function() { |
| 589 |
it("generates correct bytecode", function() { |
| 590 |
expect(pass).toChangeAST('start = [a]', bytecodeDetails([ |
| 591 |
20, 0, 2, 2, |
| 592 |
21, 1, |
| 593 |
23, 1 |
| 594 |
])); |
| 595 |
}); |
| 596 |
|
| 597 |
describe("non-empty non-inverted case-sensitive", function() { |
| 598 |
it("defines correct constants", function() { |
| 599 |
expect(pass).toChangeAST('start = [a]', constsDetails([ |
| 600 |
'/^[a]/', |
| 601 |
'peg$classExpectation(["a"], false, false)' |
| 602 |
])); |
| 603 |
}); |
| 604 |
}); |
| 605 |
|
| 606 |
describe("non-empty inverted case-sensitive", function() { |
| 607 |
it("defines correct constants", function() { |
| 608 |
expect(pass).toChangeAST('start = [^a]', constsDetails([ |
| 609 |
'/^[^a]/', |
| 610 |
'peg$classExpectation(["a"], true, false)' |
| 611 |
])); |
| 612 |
}); |
| 613 |
}); |
| 614 |
|
| 615 |
describe("non-empty non-inverted case-insensitive", function() { |
| 616 |
it("defines correct constants", function() { |
| 617 |
expect(pass).toChangeAST('start = [a]i', constsDetails([ |
| 618 |
'/^[a]/i', |
| 619 |
'peg$classExpectation(["a"], false, true)' |
| 620 |
])); |
| 621 |
}); |
| 622 |
}); |
| 623 |
|
| 624 |
describe("non-empty complex", function() { |
| 625 |
it("defines correct constants", function() { |
| 626 |
expect(pass).toChangeAST('start = [ab-def-hij-l]', constsDetails([ |
| 627 |
'/^[ab-def-hij-l]/', |
| 628 |
'peg$classExpectation(["a", ["b", "d"], "e", ["f", "h"], "i", ["j", "l"]], false, false)' |
| 629 |
])); |
| 630 |
}); |
| 631 |
}); |
| 632 |
|
| 633 |
describe("empty non-inverted", function() { |
| 634 |
it("defines correct constants", function() { |
| 635 |
expect(pass).toChangeAST('start = []', constsDetails([ |
| 636 |
'/^(?!)/', |
| 637 |
'peg$classExpectation([], false, false)' |
| 638 |
])); |
| 639 |
}); |
| 640 |
}); |
| 641 |
|
| 642 |
describe("empty inverted", function() { |
| 643 |
it("defines correct constants", function() { |
| 644 |
expect(pass).toChangeAST('start = [^]', constsDetails([ |
| 645 |
'/^[\\S\\s]/', |
| 646 |
'peg$classExpectation([], true, false)' |
| 647 |
])); |
| 648 |
}); |
| 649 |
}); |
| 650 |
}); |
| 651 |
|
| 652 |
describe("for any", function() { |
| 653 |
var grammar = 'start = .'; |
| 654 |
|
| 655 |
it("generates bytecode", function() { |
| 656 |
expect(pass).toChangeAST(grammar, bytecodeDetails([ |
| 657 |
17, 2, 2, |
| 658 |
21, 1, |
| 659 |
23, 0 |
| 660 |
])); |
| 661 |
}); |
| 662 |
|
| 663 |
it("defines correct constants", function() { |
| 664 |
expect(pass).toChangeAST( |
| 665 |
grammar, |
| 666 |
constsDetails(['peg$anyExpectation()']) |
| 667 |
); |
| 668 |
}); |
| 669 |
}); |
| 670 |
}); |