Adding simple test fot cf grammar
This commit is contained in:
parent
0a886bd8a8
commit
e6d9439ba9
2 changed files with 60 additions and 1 deletions
|
|
@ -1,4 +1,62 @@
|
|||
|
||||
int main() {
|
||||
#include "NewPlacement.hpp"
|
||||
#include "Testing.hpp"
|
||||
#include "Parser.hpp"
|
||||
|
||||
using namespace tp;
|
||||
|
||||
TEST_DEF(Simple) {
|
||||
|
||||
String source = R"(
|
||||
Start Body
|
||||
Body : [ Function ] | List | &;
|
||||
List : [ LIST ];
|
||||
)";
|
||||
|
||||
auto state = CfGrammar::initializeCfGrammarParser();
|
||||
|
||||
CfGrammar grammar;
|
||||
|
||||
if (!grammar.parse(state, source)) {
|
||||
TEST(0 && "Parsing is failed\n");
|
||||
CfGrammar::deinitializeCfGrammarParser(state);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!grammar.compile()) {
|
||||
TEST(0 && "Compilation is failed\n");
|
||||
CfGrammar::deinitializeCfGrammarParser(state);
|
||||
return;
|
||||
}
|
||||
|
||||
CfGrammar::deinitializeCfGrammarParser(state);
|
||||
|
||||
printf("Grammar accepted.\n");
|
||||
|
||||
List<CfGrammar::Sentence> sentences;
|
||||
grammar.generateSentences(sentences);
|
||||
|
||||
TEST_ASSERT(sentences.length() == 3);
|
||||
TEST_ASSERT(sentences.first()->data.terms.length() == 1);
|
||||
TEST_ASSERT(sentences.last()->data.terms.length() == 1);
|
||||
|
||||
TEST(sentences.first()->data.terms.first()->data.id == "Function");
|
||||
TEST(sentences.last()->data.terms.first()->data.id == "LIST");
|
||||
|
||||
printf("Example sentences formed from grammar: \n");
|
||||
for (auto sentence : sentences) tp::CfGrammar::printSentence(sentence.data());
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
tp::ModuleManifest* deps[] = { &tp::gModuleParser, nullptr };
|
||||
tp::ModuleManifest testModule("CommandLineTest", nullptr, nullptr, deps);
|
||||
|
||||
if (!testModule.initialize()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
testSimple();
|
||||
|
||||
testModule.deinitialize();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -61,4 +61,5 @@ namespace tp {
|
|||
void Name##FunctorBody()
|
||||
|
||||
#define TEST(expr) if (!(expr)) tp::gTesting.addFailedCheck({ #expr, __FILE__, __LINE__ })
|
||||
#define TEST_ASSERT(expr) TEST(expr); if (!(expr)) return
|
||||
#define TEST_EQUAL(l, r) if (!((l) == (r))) tp::gTesting.addFailedCheck({ #l" == "#r, __FILE__, __LINE__ })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue