diff --git a/libnixf/src/Parse/Lexer.cpp b/libnixf/src/Parse/Lexer.cpp index c619fd8d4..e3a423fce 100644 --- a/libnixf/src/Parse/Lexer.cpp +++ b/libnixf/src/Parse/Lexer.cpp @@ -66,8 +66,9 @@ std::optional Lexer::consumeOneOf(std::string_view Chars) { if (eof()) return std::nullopt; if (Chars.find(peekUnwrap()) != std::string_view::npos) { + char Ret = peekUnwrap(); consume(); - return peek(); + return Ret; } return std::nullopt; } diff --git a/libnixf/test/Parse/Lexer.cpp b/libnixf/test/Parse/Lexer.cpp index 70a861262..5e638e3f2 100644 --- a/libnixf/test/Parse/Lexer.cpp +++ b/libnixf/test/Parse/Lexer.cpp @@ -114,6 +114,26 @@ TEST_F(LexerTest, FloatLeadingZero) { ASSERT_EQ(std::string(Diags[0].args()[0]), "00"); } +TEST_F(LexerTest, FloatNoExp_little) { + Lexer Lexer("0.33e", Diags); + auto P = Lexer.lex(); + ASSERT_EQ(P.kind(), tok_float); + ASSERT_EQ(P.view(), "0.33e"); + ASSERT_FALSE(Diags.empty()); + ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_FloatNoExp); + ASSERT_EQ(std::string(Diags[0].args()[0]), "e"); +} + +TEST_F(LexerTest, FloatNoExp_big) { + Lexer Lexer("0.33E", Diags); + auto P = Lexer.lex(); + ASSERT_EQ(P.kind(), tok_float); + ASSERT_EQ(P.view(), "0.33E"); + ASSERT_FALSE(Diags.empty()); + ASSERT_EQ(Diags[0].kind(), Diagnostic::DK_FloatNoExp); + ASSERT_EQ(std::string(Diags[0].args()[0]), "E"); +} + TEST_F(LexerTest, lexString) { Lexer Lexer(R"("aa bb \\ \t \" \n ${}")", Diags); const TokenKind Match[] = {