diff --git a/libnixf/lib/Parse/test/Lexer.cpp b/libnixf/lib/Parse/test/Lexer.cpp index b000808be..3908574a6 100644 --- a/libnixf/lib/Parse/test/Lexer.cpp +++ b/libnixf/lib/Parse/test/Lexer.cpp @@ -60,7 +60,7 @@ TEST_F(LexerTest, Trivia1) { Lexer Lexer(Src, Diag); auto P = Lexer.lex(); ASSERT_EQ(P.kind(), tok_int); - // ASSERT_EQ(P.view(), "3"); + ASSERT_EQ(P.view(), "3"); ASSERT_TRUE(Diag.diags().empty()); } @@ -72,7 +72,7 @@ TEST_F(LexerTest, TriviaLComment) { Diag); auto P = Lexer.lex(); ASSERT_EQ(P.kind(), tok_int); - // ASSERT_EQ(P.view(), "3"); + ASSERT_EQ(P.view(), "3"); ASSERT_TRUE(Diag.diags().empty()); } @@ -83,7 +83,7 @@ aaa Lexer Lexer(Src, Diag); auto P = Lexer.lex(); ASSERT_EQ(P.kind(), tok_eof); - // ASSERT_EQ(P.view(), ""); + ASSERT_EQ(P.view(), ""); ASSERT_TRUE(Diag.diags().empty()); } @@ -94,7 +94,7 @@ aaa Lexer Lexer(Src, Diag); auto P = Lexer.lex(); ASSERT_EQ(P.kind(), tok_eof); - // ASSERT_EQ(P.view(), ""); + ASSERT_EQ(P.view(), ""); ASSERT_TRUE(!Diag.diags().empty()); ASSERT_EQ(std::string(Diag.diags()[0]->message()), "unterminated /* comment"); @@ -106,7 +106,7 @@ TEST_F(LexerTest, FloatLeadingZero) { Lexer Lexer("00.33", Diag); auto P = Lexer.lex(); ASSERT_EQ(P.kind(), tok_float); - // ASSERT_EQ(P.view(), "00.33"); + ASSERT_EQ(P.view(), "00.33"); ASSERT_FALSE(Diag.diags().empty()); ASSERT_EQ(std::string(Diag.diags()[0]->message()), "float begins with extra zeros `{}` is nixf extension"); diff --git a/libnixf/lib/Parse/test/Parser.cpp b/libnixf/lib/Parse/test/Parser.cpp index 0dce8ed83..98fd9fbe0 100644 --- a/libnixf/lib/Parse/test/Parser.cpp +++ b/libnixf/lib/Parse/test/Parser.cpp @@ -2,6 +2,7 @@ #include "nixf/Basic/Diagnostic.h" #include "nixf/Basic/DiagnosticEngine.h" +#include "nixf/Basic/Range.h" #include "nixf/Parse/Nodes.h" #include "nixf/Parse/Parser.h" @@ -29,7 +30,8 @@ TEST(Parser, Float) { ASSERT_EQ(Expr->kind(), Node::NK_ExprFloat); ASSERT_EQ(static_cast(Expr.get())->value(), 1.0); ASSERT_EQ(Diags.diags().size(), 0); - // ASSERT_EQ(Expr->range().view(), Src); + ASSERT_EQ(Expr->range().begin(), Point(0, 0, 0)); + ASSERT_EQ(Expr->range().end(), Point(0, 3, 3)); } TEST(Parser, FloatLeading) { @@ -39,13 +41,12 @@ TEST(Parser, FloatLeading) { ASSERT_TRUE(Expr); ASSERT_EQ(Expr->kind(), Node::NK_ExprFloat); ASSERT_EQ(static_cast(Expr.get())->value(), 1.0); - // ASSERT_EQ(Expr->range().view(), Src); // Check the diagnostic. ASSERT_EQ(Diags.diags().size(), 1); auto &D = Diags.diags()[0]; - // ASSERT_EQ(D->range().Begin, Src.begin() + 0); - // ASSERT_EQ(D->range().End, Src.begin() + 2); + ASSERT_EQ(Expr->range().begin(), Point(0, 0, 0)); + ASSERT_EQ(Expr->range().end(), Point(0, 4, 4)); ASSERT_EQ(D->kind(), Diagnostic::DK_FloatLeadingZero); ASSERT_EQ(D->args().size(), 1); ASSERT_EQ(D->args()[0], "01"); @@ -59,7 +60,8 @@ TEST(Parser, FloatLeading00) { ASSERT_EQ(Expr->kind(), Node::NK_ExprFloat); ASSERT_EQ(static_cast(Expr.get())->value(), 0.5); ASSERT_EQ(Diags.diags().size(), 1); - // ASSERT_EQ(Expr->range().view(), Src); + ASSERT_EQ(Expr->range().begin(), Point(0, 0, 0)); + ASSERT_EQ(Expr->range().end(), Point(0, 4, 4)); } TEST(Parser, StringSimple) { @@ -69,10 +71,12 @@ TEST(Parser, StringSimple) { ASSERT_TRUE(Expr); ASSERT_EQ(Expr->kind(), Node::NK_ExprString); auto Parts = static_cast(Expr.get())->parts(); - // ASSERT_EQ(Parts->range().view(), "aaa"); + ASSERT_EQ(Parts->range().begin(), Point(0, 1, 1)); + ASSERT_EQ(Parts->range().end(), Point(0, 4, 4)); ASSERT_EQ(Parts->fragments().size(), 1); ASSERT_EQ(Diags.diags().size(), 0); - // ASSERT_EQ(Expr->range().view(), Src); + ASSERT_EQ(Expr->range().begin(), Point(0, 0, 0)); + ASSERT_EQ(Expr->range().end(), Point(0, 5, 5)); } TEST(Parser, StringMissingDQuote) { @@ -82,14 +86,15 @@ TEST(Parser, StringMissingDQuote) { ASSERT_TRUE(Expr); ASSERT_EQ(Expr->kind(), Node::NK_ExprString); auto Parts = static_cast(Expr.get())->parts(); - // ASSERT_EQ(Parts->range().view(), "aaa"); + ASSERT_EQ(Parts->range().begin(), Point(0, 1, 1)); + ASSERT_EQ(Parts->range().end(), Point(0, 4, 4)); ASSERT_EQ(Parts->fragments().size(), 1); // Check the diagnostic. ASSERT_EQ(Diags.diags().size(), 1); auto &D = Diags.diags()[0]; - // ASSERT_EQ(D->range().Begin, Src.begin() + 4); - // ASSERT_EQ(D->range().End, Src.begin() + 4); + ASSERT_EQ(Expr->range().begin(), Point(0, 0, 0)); + ASSERT_EQ(Expr->range().end(), Point(0, 4, 4)); ASSERT_EQ(D->kind(), Diagnostic::DK_Expected); ASSERT_EQ(D->args().size(), 1); ASSERT_EQ(D->args()[0], "\""); @@ -97,8 +102,8 @@ TEST(Parser, StringMissingDQuote) { // Check the note. ASSERT_EQ(D->notes().size(), 1); auto &N = D->notes()[0]; - // ASSERT_EQ(N->range().Begin, Src.begin() + 0); - // ASSERT_EQ(N->range().End, Src.begin() + 1); + ASSERT_EQ(N->range().begin(), Point(0, 0, 0)); + ASSERT_EQ(N->range().end(), Point(0, 1, 1)); ASSERT_EQ(N->kind(), Note::NK_ToMachThis); ASSERT_EQ(N->args().size(), 1); ASSERT_EQ(N->args()[0], "\""); @@ -106,11 +111,9 @@ TEST(Parser, StringMissingDQuote) { // Check fix-it hints. ASSERT_EQ(D->fixes().size(), 1); const auto &F = D->fixes()[0]; - // ASSERT_EQ(F.oldRange().Begin, Src.begin() + 4); - // ASSERT_EQ(F.oldRange().End, Src.begin() + 4); + ASSERT_EQ(F.oldRange().begin(), Point(0, 4, 4)); + ASSERT_EQ(F.oldRange().end(), Point(0, 4, 4)); ASSERT_EQ(F.newText(), "\""); - - // ASSERT_EQ(Expr->range().view(), Src); } TEST(Parser, StringInterpolation) { @@ -120,7 +123,8 @@ TEST(Parser, StringInterpolation) { ASSERT_TRUE(Expr); ASSERT_EQ(Expr->kind(), Node::NK_ExprString); auto Parts = static_cast(Expr.get())->parts(); - // ASSERT_EQ(Parts->range().view(), "aaa ${1} bbb"); + ASSERT_EQ(Parts->range().begin(), Point(0, 1, 1)); + ASSERT_EQ(Parts->range().end(), Point(0, 13, 13)); ASSERT_EQ(Parts->fragments().size(), 3); ASSERT_EQ(Parts->fragments()[0].kind(), InterpolablePart::SPK_Escaped); @@ -128,7 +132,8 @@ TEST(Parser, StringInterpolation) { ASSERT_EQ(Parts->fragments()[2].kind(), InterpolablePart::SPK_Escaped); ASSERT_EQ(Diags.diags().size(), 0); - // ASSERT_EQ(Expr->range().view(), Src); + ASSERT_EQ(Expr->range().begin(), Point(0, 0, 0)); + ASSERT_EQ(Expr->range().end(), Point(0, 14, 14)); } TEST(Parser, IndentedString) { @@ -151,8 +156,8 @@ TEST(Parser, IndentedString) { // Check the diagnostic. ASSERT_EQ(Diags.diags().size(), 1); auto &D = Diags.diags()[0]; - // ASSERT_EQ(D->range().Begin, Src.begin() + 39); - // ASSERT_EQ(D->range().End, Src.begin() + 39); + ASSERT_EQ(D->range().begin(), Point(7, 3, 39)); + ASSERT_EQ(D->range().end(), Point(7, 3, 39)); ASSERT_EQ(D->kind(), Diagnostic::DK_Expected); ASSERT_EQ(D->args().size(), 1); ASSERT_EQ(D->args()[0], "''"); @@ -160,8 +165,8 @@ TEST(Parser, IndentedString) { // Check the note. ASSERT_EQ(D->notes().size(), 1); auto &N = D->notes()[0]; - // ASSERT_EQ(N->range().Begin, Src.begin() + 0); - // ASSERT_EQ(N->range().End, Src.begin() + 2); + ASSERT_EQ(N->range().begin(), Point(0, 0, 0)); + ASSERT_EQ(N->range().end(), Point(0, 2, 2)); ASSERT_EQ(N->kind(), Note::NK_ToMachThis); ASSERT_EQ(N->args().size(), 1); ASSERT_EQ(N->args()[0], "''"); @@ -169,8 +174,8 @@ TEST(Parser, IndentedString) { // Check fix-it hints. ASSERT_EQ(D->fixes().size(), 1); const auto &F = D->fixes()[0]; - // ASSERT_EQ(F.oldRange().Begin, Src.begin() + 39); - // ASSERT_EQ(F.oldRange().End, Src.begin() + 39); + ASSERT_EQ(F.oldRange().begin(), Point(7, 3, 39)); + ASSERT_EQ(F.oldRange().end(), Point(7, 3, 39)); ASSERT_EQ(F.newText(), "''"); }