Add some assertions to the fixture grammar tests

This commit is contained in:
Max Brunsfeld 2017-12-07 11:43:51 -08:00
parent 5d676de051
commit 90629bd45a
2 changed files with 10 additions and 9 deletions

View file

@ -52,10 +52,10 @@ bool operator==(const std::vector<Tree *> &vec, const TreeArray &array) {
}
void assert_consistent_tree_sizes(TSNode node) {
size_t child_count = ts_node_child_count(node);
size_t named_child_count = ts_node_named_child_count(node);
size_t start_byte = ts_node_start_byte(node);
size_t end_byte = ts_node_end_byte(node);
uint32_t child_count = ts_node_child_count(node);
uint32_t named_child_count = ts_node_named_child_count(node);
uint32_t start_byte = ts_node_start_byte(node);
uint32_t end_byte = ts_node_end_byte(node);
TSPoint start_point = ts_node_start_point(node);
TSPoint end_point = ts_node_end_point(node);
@ -69,7 +69,7 @@ void assert_consistent_tree_sizes(TSNode node) {
size_t actual_named_child_count = 0;
for (size_t i = 0; i < child_count; i++) {
TSNode child = ts_node_child(node, i);
size_t child_start_byte = ts_node_start_byte(child);
uint32_t child_start_byte = ts_node_start_byte(child);
TSPoint child_start_point = ts_node_start_point(child);
AssertThat(child_start_byte, !IsLessThan(last_child_end_byte));
@ -83,10 +83,6 @@ void assert_consistent_tree_sizes(TSNode node) {
last_child_end_point = ts_node_end_point(child);
}
if (actual_named_child_count != named_child_count) {
puts("UH OH");
}
AssertThat(actual_named_child_count, Equals(named_child_count));
if (child_count > 0) {

View file

@ -5,6 +5,7 @@
#include "helpers/file_helpers.h"
#include "helpers/tree_helpers.h"
#include "runtime/alloc.h"
#include "helpers/record_alloc.h"
START_TEST
@ -34,6 +35,8 @@ for (auto &language_name : test_languages) {
for (auto &entry : read_test_language_corpus(language_name)) {
it(("parses " + entry.description).c_str(), [&]() {
record_alloc::start();
if (!language) {
string external_scanner_path = join_path({directory_path, "scanner.c"});
if (!file_exists(external_scanner_path)) external_scanner_path = "";
@ -56,6 +59,7 @@ for (auto &language_name : test_languages) {
ts_document_parse(document);
TSNode root_node = ts_document_root_node(document);
AssertThat(ts_node_end_byte(root_node), Equals(entry.input.size()));
assert_consistent_tree_sizes(root_node);
const char *node_string = ts_node_string(root_node, document);
string result(node_string);
@ -63,6 +67,7 @@ for (auto &language_name : test_languages) {
ts_document_free(document);
AssertThat(result, Equals(entry.tree_string));
AssertThat(record_alloc::outstanding_allocation_indices(), IsEmpty());
});
}
});