3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-07-26 22:17:55 +00:00

libparse: LibertyExpression unit test

This commit is contained in:
Emil J. Tywoniak 2025-07-15 12:53:30 +02:00
parent 21e68ec9be
commit c7a3abbcc4

View file

@ -0,0 +1,88 @@
#include <gtest/gtest.h>
#include "passes/techmap/libparse.h"
YOSYS_NAMESPACE_BEGIN
namespace RTLIL {
class TechmapLibparseTest : public testing::Test {
protected:
TechmapLibparseTest() {
if (log_files.empty()) log_files.emplace_back(stdout);
}
void checkAll(std::initializer_list<std::string> expressions, std::string expected) {
for (const auto& e : expressions) {
auto helper = LibertyExpression::Lexer(e);
auto tree_s = LibertyExpression::parse(helper).str();
EXPECT_EQ(tree_s, expected);
}
}
};
TEST_F(TechmapLibparseTest, LibertyExpressionSpace)
{
checkAll({
"x",
"x ",
" x",
" x ",
" x ",
}, "(pin \"x\")");
checkAll({
"x y",
" x y ",
"x (y)",
" x (y) ",
"(x) y",
" (x) y ",
"x & y",
"x&y",
"x &y",
"x& y",
" x&y ",
"x & (y)",
"x&(y)",
"x &(y)",
"x& (y)",
" x&(y) ",
"(x) & y",
"(x)&y",
"(x) &y",
"(x)& y",
" (x)&y ",
}, "(and (pin \"x\")\n"
" (pin \"y\"))"
);
checkAll({
"x ^ y",
"x^y",
"x ^y",
"x^ y",
" x^y ",
}, "(xor (pin \"x\")\n"
" (pin \"y\"))"
);
checkAll({
"x !y",
" x !y ",
"x & !y",
"x&!y",
"x &!y",
"x& !y",
" x&!y ",
"x y'",
" x y' ",
"x & y'",
"x&y'",
"x &y'",
"x& y'",
" x&y' ",
}, "(and (pin \"x\")\n"
" (not (pin \"y\")))"
);
}
}
YOSYS_NAMESPACE_END