reviewing project state, doing some tests.
This commit is contained in:
1 parent
f044c6d5eb
commit
61d53362e8
15 files changed
+530
-155
No files matched your search
+44
-16
@@ -3,27 +3,55 @@
|
||||
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
||||
#include "gen.hpp"
|
||||
|
||||
global int g_failures = 0;
|
||||
|
||||
internal void expect(int condition, gen::Str name) {
|
||||
if (condition == false) { gen::log_fmt("FAIL %S\n", name); ++ g_failures; }
|
||||
}
|
||||
|
||||
internal void expect_fragments(gen::Str text, gen::Str label) {
|
||||
expect(text.Ptr != nullptr && text.Len > 0, label);
|
||||
expect(gen::str_contains(text, txt("baseline_message")), label);
|
||||
expect(gen::str_contains(text, txt("char")), label);
|
||||
expect(gen::str_contains(text, txt("const")), label);
|
||||
expect(gen::str_contains(text, txt("*")), label);
|
||||
expect(gen::str_contains(text, txt("GENCPP_BASELINE")), label);
|
||||
}
|
||||
|
||||
internal void expect_variable(gen::CodeVar var, gen::Str label) {
|
||||
expect(var.ast != nullptr, label); if (var.ast == nullptr) return;
|
||||
expect(var->Type == gen::CT_Variable, label);
|
||||
expect(gen::str_contains(var->Name, txt("baseline_message")), label);
|
||||
expect(var->ValueType.ast != nullptr, label);
|
||||
expect(var->Value.ast != nullptr, label);
|
||||
if (var->Value.ast != nullptr) {
|
||||
expect(gen::str_contains(var->Value->Content, txt("GENCPP_BASELINE")), label);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace gen;
|
||||
Context ctx = {};
|
||||
gen::init( & ctx);
|
||||
Context ctx = {}; init(&ctx);
|
||||
|
||||
Builder src_hello = builder_open("gen/hello.cpp");
|
||||
CodeVar hello_var = parse_variable( code(
|
||||
constexpr char const* hello_gencpp_str = "HELLO GENCPP !";
|
||||
));
|
||||
src_hello.print(hello_var);
|
||||
src_hello.write();
|
||||
Opts_def_type type_opts = {};
|
||||
type_opts.specifiers = def_specifiers(args(Spec_Const, Spec_Ptr));
|
||||
CodeTypename type = def_type(name(char), type_opts);
|
||||
Opts_def_variable opts = {}; opts.value = untyped_str(code("\"GENCPP_BASELINE\""));
|
||||
CodeVar upfront = def_variable(type, name(baseline_message), opts);
|
||||
expect_variable(upfront, txt("cpp upfront"));
|
||||
expect_fragments(strbuilder_to_str(code_to_strbuilder((Code)upfront)), txt("cpp upfront serialized"));
|
||||
|
||||
CodeBody body = parse_file("gen/hello.cpp");
|
||||
for ( Code code : body ) switch (code->Type) {
|
||||
case CT_Variable:
|
||||
CodeVar var = cast(CodeVar, code);
|
||||
log_fmt("%S", var->Value);
|
||||
break;
|
||||
}
|
||||
Code untyped = code_str(char const* baseline_message = "GENCPP_BASELINE";); expect(untyped.ast != nullptr, txt("cpp untyped"));
|
||||
Str untyped_text = strbuilder_to_str(code_to_strbuilder(untyped)); expect_fragments(untyped_text, txt("cpp untyped content"));
|
||||
CodeVar parsed_untyped = parse_variable(untyped_text); expect_variable(parsed_untyped, txt("cpp untyped reparsed"));
|
||||
|
||||
gen::deinit(& ctx);
|
||||
CodeVar parsed = parse_variable(code(char const* baseline_message = "GENCPP_BASELINE"; ));
|
||||
expect_variable(parsed, txt("cpp parsed"));
|
||||
expect_fragments(strbuilder_to_str(code_to_strbuilder((Code)parsed)), txt("cpp parsed serialized"));
|
||||
|
||||
deinit(&ctx);
|
||||
if (g_failures != 0) { log_fmt("cpp baseline smoke failed: %d\n", g_failures); return 1; }
|
||||
log_fmt("cpp baseline smoke passed\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user