tree-sitter/spec/compiler/lr/item_spec.cpp

33 lines
1,016 B
C++
Raw Normal View History

#include "spec_helper.h"
2014-01-04 15:30:05 -08:00
#include "item.h"
#include "../../fixtures/grammars/arithmetic.h"
using namespace tree_sitter::lr;
START_TEST
describe("items", []() {
2013-12-28 23:26:20 -08:00
describe("construction", [&]() {
it("finds the item at the start of a rule", [&]() {
2013-12-28 23:26:20 -08:00
Grammar grammar = test_grammars::arithmetic();
Item item = Item::at_beginning_of_rule("expression", grammar);
2013-11-13 20:22:06 -08:00
AssertThat(item, Equals(Item("expression", grammar.rule("expression"), 0)));
});
});
2013-12-28 23:26:20 -08:00
describe("transitions", [&]() {
it("computes the possible advancements", [&]() {
auto char1 = rules::character('a');
auto char2 = rules::character('b');
Item item = Item("my-rule", rules::seq({ char1, char2 }), 2);
AssertThat(
item.transitions(),
Equals(transition_map<rules::Rule, Item>({
{ char1, make_shared<Item>("my-rule", char2, 3) }
})));
});
});
});
END_TEST