-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be07efb
commit c7fff2a
Showing
10 changed files
with
73 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <iostream> | ||
#include <catch2/catch_all.hpp> | ||
|
||
#include <include/calyx.h> | ||
#include <registry.h> | ||
|
||
using namespace calyx; | ||
|
||
TEST_CASE("Evaluate start rule") | ||
{ | ||
Registry registry; | ||
ErrorHolder errs; | ||
const Options& ops = registry.getOptions(); | ||
String_t atom = ops.fromString("atom"); | ||
String_t start = ops.fromString("start"); | ||
|
||
registry.defineRule( | ||
start, | ||
std::vector { atom }, | ||
errs | ||
); | ||
|
||
REQUIRE_FALSE(errs.hasError()); | ||
|
||
std::optional<Expansion> exp = registry.evaluate(start, errs); | ||
|
||
REQUIRE_FALSE(errs.hasError()); | ||
REQUIRE(exp.has_value()); | ||
REQUIRE(exp->getSymbol() == Exp::RESULT); | ||
REQUIRE(exp->flatten(ops) == atom); | ||
} | ||
|
||
TEST_CASE("Evaluate recursive rules") | ||
{ | ||
Registry registry; | ||
ErrorHolder errs; | ||
const Options& ops = registry.getOptions(); | ||
String_t start = ops.fromString("start"); | ||
String_t prod = ops.fromString("{atom}"); | ||
String_t atom = ops.fromString("atom"); | ||
|
||
registry.defineRule(start, std::vector { prod }, errs); | ||
REQUIRE_FALSE(errs.hasError()); | ||
registry.defineRule(atom, std::vector { atom }, errs); | ||
REQUIRE_FALSE(errs.hasError()); | ||
|
||
std::optional<Expansion> exp = registry.evaluate(start, errs); | ||
|
||
REQUIRE_FALSE(errs.hasError()); | ||
REQUIRE(exp.has_value()); | ||
REQUIRE(exp->getSymbol() == Exp::RESULT); | ||
REQUIRE(exp->flatten(ops) == atom); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters