treesitter: implement strings completely (#3007)

follow up to #2902
This commit is contained in:
mx42
2023-07-27 20:34:17 +00:00
committed by GitHub
parent bbf896e165
commit 56a011f356
18 changed files with 242 additions and 64 deletions
+18 -7
View File
@@ -5,6 +5,7 @@
#include <tree_sitter/api.h>
#include <tree_sitter/parser.h>
#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
@@ -35,7 +36,9 @@ auto main(int argc, char** argv) -> int {
auto* parser = ts_parser_new();
ts_parser_set_language(parser, tree_sitter_carbon());
std::vector<std::string> failed;
bool fail_tests = std::getenv("FAIL_TESTS") != nullptr;
std::vector<std::string> incorrect;
for (int i = 1; i < argc; i++) {
std::string file_path = argv[i];
std::string source = ReadFile(file_path);
@@ -48,19 +51,27 @@ auto main(int argc, char** argv) -> int {
char* node_debug = ts_node_string(root);
std::cout << file_path << ":\n" << node_debug << "\n";
if (has_error) {
failed.push_back(file_path);
if (has_error ^ fail_tests) {
incorrect.push_back(file_path);
}
free(node_debug);
ts_tree_delete(tree);
}
ts_parser_delete(parser);
for (const auto& file : failed) {
std::cout << "FAILED " << file << "\n";
for (const auto& file : incorrect) {
if (fail_tests) {
std::cout << "INCORRECTLY PASSING " << file << "\n";
} else {
std::cout << "FAILED " << file << "\n";
}
}
if (!failed.empty()) {
std::cout << failed.size() << " tests failing.\n";
if (!incorrect.empty()) {
if (fail_tests) {
std::cout << incorrect.size() << " tests incorrectly passing.\n";
} else {
std::cout << incorrect.size() << " tests failing.\n";
}
return 1;
}
}