tree-sitter/spec/runtime/stack_spec.cc

53 lines
1.1 KiB
C++
Raw Normal View History

2014-06-23 18:50:03 -07:00
#include "runtime/runtime_spec_helper.h"
#include "runtime/length.h"
#include "runtime/tree.h"
#include "runtime/stack.h"
START_TEST
2014-06-04 13:46:18 -07:00
enum { sym1, sym2, hidden_sym };
describe("stacks", [&]() {
2014-08-06 13:00:35 -07:00
TSStack stack;
before_each([&]() {
stack = ts_stack_make();
});
after_each([&]() {
ts_stack_delete(&stack);
});
it("starts out empty", [&]() {
AssertThat(stack.size, Equals<size_t>(0));
AssertThat(ts_stack_top_state(&stack), Equals(0));
AssertThat(ts_stack_top_node(&stack), Equals((TSTree *)nullptr));
});
describe("pushing a symbol", [&]() {
TSTree *node1;
2014-06-09 21:14:38 -07:00
before_each([&]() {
node1 = ts_tree_make_leaf(
sym1,
ts_length_make(0, 0),
ts_length_make(1, 1),
0);
2014-08-06 13:00:35 -07:00
ts_stack_push(&stack, 5, node1);
});
2014-06-09 21:14:38 -07:00
after_each([&]() {
2014-08-06 13:00:35 -07:00
ts_tree_release(node1);
});
2014-06-09 21:14:38 -07:00
2014-08-06 13:00:35 -07:00
it("adds the symbol to the stack", [&]() {
AssertThat(stack.size, Equals<size_t>(1));
AssertThat(ts_stack_top_state(&stack), Equals(5));
AssertThat(ts_stack_top_node(&stack), Equals(node1));
});
2014-08-06 13:00:35 -07:00
});
});
END_TEST