tree-sitter/spec/compiler/compile_examples.cc

47 lines
1.3 KiB
C++
Raw Normal View History

2014-06-23 18:50:03 -07:00
#include "compiler/compiler_spec_helper.h"
#include <fstream>
static string src_dir() {
2014-08-06 13:00:35 -07:00
const char * dir = getenv("TREESITTER_DIR");
if (!dir) dir = getenv("PWD");
return dir;
}
2014-03-28 13:51:32 -07:00
namespace tree_sitter_examples {
2014-08-06 13:00:35 -07:00
extern const Grammar arithmetic;
extern const Grammar javascript;
extern const Grammar json;
extern const Grammar golang;
} // namespace tree_sitter_examples
START_TEST
describe("compiling the example grammars", []() {
string example_parser_dir = src_dir() + "/spec/fixtures/parsers/";
2014-08-06 13:00:35 -07:00
auto compile_grammar = [&](const Grammar &grammar, string language) {
it(("compiles the " + language + " grammar").c_str(), [&]() {
ofstream file(example_parser_dir + language + ".c");
2014-05-01 23:28:40 -07:00
2014-08-06 13:00:35 -07:00
auto result = compile(grammar, language);
string code = get<0>(result);
vector<Conflict> conflicts = get<1>(result);
const GrammarError *error = get<2>(result);
2014-08-06 13:00:35 -07:00
AssertThat(error, Equals((GrammarError *)nullptr));
2014-08-06 13:00:35 -07:00
file << get<0>(result);
file.close();
});
};
2014-03-24 09:14:29 -07:00
2014-08-06 13:00:35 -07:00
compile_grammar(tree_sitter_examples::arithmetic, "arithmetic");
compile_grammar(tree_sitter_examples::json, "json");
compile_grammar(tree_sitter_examples::javascript, "javascript");
compile_grammar(tree_sitter_examples::golang, "golang");
});
END_TEST