Skip to content

Commit

Permalink
add specs for altg vs -1
Browse files Browse the repository at this point in the history
initially meant for gh-13
  • Loading branch information
jmettraux committed Jul 14, 2015
1 parent 72e3adf commit 8135584
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
4 changes: 1 addition & 3 deletions spec/fabr_alt_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ describe "fabr_alt()"
static fabr_tree *_talterr(fabr_input *i)
{
fabr_tree *r = calloc(1, sizeof(fabr_tree));
r->result = -1;
r->parter = "_talterr";
r->offset = i->offset;
r->result = -1; r->parter = "_talterr"; r->offset = i->offset;

return r;
}
Expand Down
31 changes: 31 additions & 0 deletions spec/fabr_altg_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ describe "fabr_altg()"
static fabr_tree *_x2(fabr_input *i) { return fabr_str("x2", i, "xx"); }
static fabr_tree *_3x(fabr_input *i) { return fabr_str("3x", i, "xxx"); }

static fabr_tree *_xerr(fabr_input *i)
{
fabr_tree *r = calloc(1, sizeof(fabr_tree));
r->result = -1; r->parter = "_xerr"; r->offset = i->offset;

return r;
}

context "greedy=0"
{
it "takes the first succesful result"
Expand Down Expand Up @@ -117,6 +125,29 @@ describe "fabr_altg()"
" [ \"2x\", 1, 0, 2, null, \"str\", 2, \"xx\" ]\n"
"] ]");
}
it "propagates -1 (error)"
{
i.string = "xx";
t = fabr_altg("e", &i, _2x, _1x, _xerr, NULL);

ensure(fabr_tree_to_string(t, i.string, 0) ===f ""
"[ \"e\", -1, 0, 0, null, \"altg\", 0, [\n"
" [ \"2x\", 1, 0, 2, null, \"str\", 2, \"xx\" ],\n"
" [ \"1x\", 0, 0, 1, null, \"str\", 1, [] ],\n"
" [ null, -1, 0, 0, null, \"_xerr\", 0, [] ]\n"
"] ]");
}

it "propagates -1 (error) immediately"
{
i.string = "xx";
t = fabr_altg("e", &i, _xerr, _2x, _1x, NULL);

ensure(fabr_tree_to_string(t, i.string, 0) ===f ""
"[ \"e\", -1, 0, 0, null, \"altg\", 0, [\n"
" [ null, -1, 0, 0, null, \"_xerr\", 0, [] ]\n"
"] ]");
}
}
}

0 comments on commit 8135584

Please sign in to comment.