|
1 | 1 | // This code is Deno only |
2 | 2 |
|
| 3 | +import { assertArrayIncludes } from "@std/assert/array-includes"; |
3 | 4 | import { assertEquals } from "@std/assert/equals"; |
4 | 5 | import { assertLess } from "@std/assert/less"; |
5 | 6 | import { assertNotEquals } from "@std/assert/not-equals"; |
6 | 7 | import { assertThrows } from "@std/assert/throws"; |
7 | 8 | import { EXAMPLE_SENTENCES, MALFORMED_SENTENCES } from "../examples.ts"; |
8 | 9 | import { parse } from "./parser.ts"; |
| 10 | +import { end, match, matchString, sequence } from "./parser_lib.ts"; |
9 | 11 | import { KU_LILI, KU_SULI, PU } from "./ucsur.ts"; |
10 | 12 |
|
11 | 13 | Deno.test("AST all distinct", () => { |
@@ -49,3 +51,14 @@ function uniquePairs<T>( |
49 | 51 | ): ReadonlyArray<readonly [T, T]> { |
50 | 52 | return array.flatMap((a, i) => array.slice(i + 1).map((b) => [a, b])); |
51 | 53 | } |
| 54 | + |
| 55 | +Deno.test("parser", () => { |
| 56 | + const space = match(/\s*/, "space"); |
| 57 | + const parser = sequence( |
| 58 | + match(/toki/, '"toki"').skip(space), |
| 59 | + matchString("pona").skip(space), |
| 60 | + match(/a/, '"a"').skip(end), |
| 61 | + ) |
| 62 | + .generateParser(); |
| 63 | + assertArrayIncludes(parser("toki pona a").unwrap(), [["toki", "pona", "a"]]); |
| 64 | +}); |
0 commit comments