diff options
| author | sanine <sanine.not@pm.me> | 2025-10-27 10:52:01 -0500 | 
|---|---|---|
| committer | sanine <sanine.not@pm.me> | 2025-10-27 10:52:01 -0500 | 
| commit | 8f63364c2b1ec54e104c189db43805917800b789 (patch) | |
| tree | 8329eb5a9955667f1aa8d2e22110062d841379c7 /expression.test.c | |
| parent | 11f8fd4418a068c76fc7c810967a6bf285ee74b6 (diff) | |
implement basic grammatical expansionc-version
Diffstat (limited to 'expression.test.c')
| -rw-r--r-- | expression.test.c | 61 | 
1 files changed, 61 insertions, 0 deletions
| diff --git a/expression.test.c b/expression.test.c new file mode 100644 index 0000000..234347d --- /dev/null +++ b/expression.test.c @@ -0,0 +1,61 @@ +#define LILY_IMPLEMENTATION +#include "lily-test.h" +#include "expression.h" + + +LILY_FILE_BEGIN(expression_suite) + + +enum simple_symbol_t { +  START, +  SIMPLE_NUM_NONTERMINALS, +  A, B, C, +}; + +LILY_TEST("expand basic expression") { +  li_grammar_t *grammar = li_grammar_alloc(SIMPLE_NUM_NONTERMINALS); +  REQUIRE_NEQ(grammar, NULL, "%p"); + +  int err; + +  int rule0[] = { A, START, B }; +  err = li_grammar_rule_add(grammar, START, 3, rule0); +  CHECK_EQ(err, 0, "%d"); +  int rule1[] = { C }; +  err = li_grammar_rule_add(grammar, START, 1, rule1); +  CHECK_EQ(err, 0, "%d"); + +  int buf[32]; size_t bufsz = 32; int stack[32]; +  uint8_t rand[] = { 1, 1, 1, 0 }; + +  err = li_grammar_rule_expand(grammar, buf, &bufsz, stack, 32, START, rand, 4); + +  REQUIRE_EQ(err, 0, "%d"); +  CHECK_EQ(bufsz, 7, "%lu"); + +  CHECK_EQ(buf[0], A, "%d"); +  CHECK_EQ(buf[1], A, "%d"); +  CHECK_EQ(buf[2], A, "%d"); + +  CHECK_EQ(buf[3], C, "%d"); + +  CHECK_EQ(buf[4], B, "%d"); +  CHECK_EQ(buf[5], B, "%d"); +  CHECK_EQ(buf[6], B, "%d"); + +  li_grammar_free(grammar); +} +#include LILY_PUSH_TEST() + + +#define LILY_FILE_END +#include LILY_REGISTER_TESTS() + + + +int main() { +  lily_begin(); +  expression_suite(); +  lily_finish(); +  return 0; +} | 
