summaryrefslogtreecommitdiffstats
path: root/llparse/test/fixtures
diff options
context:
space:
mode:
Diffstat (limited to 'llparse/test/fixtures')
-rw-r--r--llparse/test/fixtures/extra.c84
-rw-r--r--llparse/test/fixtures/index.ts52
2 files changed, 136 insertions, 0 deletions
diff --git a/llparse/test/fixtures/extra.c b/llparse/test/fixtures/extra.c
new file mode 100644
index 0000000..79cdff9
--- /dev/null
+++ b/llparse/test/fixtures/extra.c
@@ -0,0 +1,84 @@
+#include "fixture.h"
+
+int llparse__print_zero(llparse_t* s, const char* p, const char* endp) {
+ if (llparse__in_bench)
+ return 0;
+ llparse__print(p, endp, "0");
+ return 0;
+}
+
+
+int llparse__print_one(llparse_t* s, const char* p, const char* endp) {
+ if (llparse__in_bench)
+ return 0;
+ llparse__print(p, endp, "1");
+ return 0;
+}
+
+
+int llparse__print_off(llparse_t* s, const char* p, const char* endp) {
+ if (llparse__in_bench)
+ return 0;
+ llparse__print(p, endp, "");
+ return 0;
+}
+
+
+int llparse__print_match(llparse_t* s, const char* p, const char* endp,
+ int value) {
+ if (llparse__in_bench)
+ return 0;
+ llparse__print(p, endp, "match=%d", value);
+ return 0;
+}
+
+
+int llparse__on_dot(llparse_t* s, const char* p, const char* endp) {
+ if (llparse__in_bench)
+ return 0;
+ return llparse__print_span("dot", p, endp);
+}
+
+
+int llparse__on_dash(llparse_t* s, const char* p, const char* endp) {
+ if (llparse__in_bench)
+ return 0;
+ return llparse__print_span("dash", p, endp);
+}
+
+
+int llparse__on_underscore(llparse_t* s, const char* p,
+ const char* endp) {
+ if (llparse__in_bench)
+ return 0;
+ return llparse__print_span("underscore", p, endp);
+}
+
+
+/* A span callback, really */
+int llparse__please_fail(llparse_t* s, const char* p, const char* endp) {
+ s->reason = "please fail";
+ if (llparse__in_bench)
+ return 1;
+ return 1;
+}
+
+
+/* A span callback, really */
+static int llparse__pause_once_counter;
+
+int llparse__pause_once(llparse_t* s, const char* p, const char* endp) {
+ if (!llparse__in_bench)
+ llparse__print_span("pause", p, endp);
+
+ if (llparse__pause_once_counter != 0)
+ return 0;
+ llparse__pause_once_counter = 1;
+
+ return LLPARSE__ERROR_PAUSE;
+}
+
+
+int llparse__test_init() {
+ llparse__pause_once_counter = 0;
+}
diff --git a/llparse/test/fixtures/index.ts b/llparse/test/fixtures/index.ts
new file mode 100644
index 0000000..d8a7336
--- /dev/null
+++ b/llparse/test/fixtures/index.ts
@@ -0,0 +1,52 @@
+import { source } from 'llparse-frontend';
+import { Fixture, FixtureResult } from 'llparse-test-fixture';
+import * as path from 'path';
+
+import { LLParse } from '../../src/api';
+
+export { ERROR_PAUSE } from 'llparse-test-fixture';
+
+const fixtures = new Fixture({
+ buildDir: path.join(__dirname, '..', 'tmp'),
+ extra: [
+ '-msse4.2',
+ '-DLLPARSE__TEST_INIT=llparse__test_init',
+ path.join(__dirname, 'extra.c'),
+ ],
+});
+
+export function build(llparse: LLParse, node: source.node.Node, outFile: string)
+ : Promise<FixtureResult> {
+ return fixtures.build(llparse.build(node, {
+ c: {
+ header: outFile,
+ },
+ }), outFile);
+}
+
+export function printMatch(p: LLParse, next: source.node.Node)
+ : source.node.Node {
+ const code = p.code.value('llparse__print_match');
+ const res = p.invoke(code, next);
+ return res;
+}
+
+export function printOff(p: LLParse, next: source.node.Node): source.node.Node {
+ const code = p.code.match('llparse__print_off');
+ return p.invoke(code, next);
+}
+
+export const NUM_SELECT: { readonly [key: string]: number } = {
+ 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9,
+};
+
+export const NUM: ReadonlyArray<string> = [
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+];
+
+export const ALPHA: ReadonlyArray<string> = [
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+ 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+];