From 90629bd45a16f8432501294c4b8b52e17762747c Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 7 Dec 2017 11:43:51 -0800 Subject: [PATCH] Add some assertions to the fixture grammar tests --- test/helpers/tree_helpers.cc | 14 +++++--------- test/integration/test_grammars.cc | 5 +++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/helpers/tree_helpers.cc b/test/helpers/tree_helpers.cc index 1d94bc65..bae33cf7 100644 --- a/test/helpers/tree_helpers.cc +++ b/test/helpers/tree_helpers.cc @@ -52,10 +52,10 @@ bool operator==(const std::vector &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) { diff --git a/test/integration/test_grammars.cc b/test/integration/test_grammars.cc index 94934a71..ded662df 100644 --- a/test/integration/test_grammars.cc +++ b/test/integration/test_grammars.cc @@ -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()); }); } });