Skip to content

Commit

Permalink
libnixf/test/Parse: split binop tests from Expr
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Feb 9, 2024
1 parent 38ce0de commit 6353666
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
1 change: 1 addition & 0 deletions libnixf/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ test('unit/libnixf/Parse',
'test/Parse/ParseAttrs.cpp',
'test/Parse/ParseExpr.cpp',
'test/Parse/ParseLambda.cpp',
'test/Parse/ParseOp.cpp',
'test/Parse/ParseSimple.cpp',
dependencies: [ nixf, gtest_main ],
include_directories: [ 'src/Parse' ] # Private headers
Expand Down
19 changes: 0 additions & 19 deletions libnixf/test/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <gtest/gtest.h>

#include "Parser.h"
#include "nixf/Basic/Nodes/Op.h"

namespace {

Expand Down Expand Up @@ -235,22 +234,4 @@ TEST(Parser, ExprDispatch_r_curly_id_ellipsis) {
ASSERT_EQ(AST->kind(), Node::NK_ExprLambda);
}

TEST(Parser, ExprOp) {
auto Src = R"(1 + 2 * 3)"sv;

std::vector<Diagnostic> Diags;
Parser P(Src, Diags);
auto AST = P.parseExpr();

ASSERT_TRUE(AST);
ASSERT_EQ(AST->kind(), Node::NK_ExprBinOp);

auto &BinOp = *static_cast<ExprBinOp *>(AST.get());

ASSERT_TRUE(BinOp.lhs());
ASSERT_TRUE(BinOp.rhs());
ASSERT_EQ(BinOp.rhs()->kind(), Node::NK_ExprBinOp);
ASSERT_EQ(BinOp.lhs()->kind(), Node::NK_ExprInt);
}

} // namespace
30 changes: 30 additions & 0 deletions libnixf/test/Parse/ParseOp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <gtest/gtest.h>

#include "Parser.h"

#include "nixf/Basic/Nodes/Op.h"

namespace {

using namespace nixf;
using namespace std::string_view_literals;

TEST(Parser, ExprOp) {
auto Src = R"(1 + 2 * 3 + 2.1)"sv;

std::vector<Diagnostic> Diags;
Parser P(Src, Diags);
auto AST = P.parseExpr();

ASSERT_TRUE(AST);
ASSERT_EQ(AST->kind(), Node::NK_ExprBinOp);

auto &BinOp = *static_cast<ExprBinOp *>(AST.get());

ASSERT_TRUE(BinOp.lhs());
ASSERT_TRUE(BinOp.rhs());
ASSERT_EQ(BinOp.rhs()->kind(), Node::NK_ExprFloat);
ASSERT_EQ(BinOp.lhs()->kind(), Node::NK_ExprBinOp);
}

} // namespace

0 comments on commit 6353666

Please sign in to comment.