diff options
Diffstat (limited to 'src/sexpr/parser_test.cpp')
-rw-r--r-- | src/sexpr/parser_test.cpp | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/src/sexpr/parser_test.cpp b/src/sexpr/parser_test.cpp index 846d425..bbaf5eb 100644 --- a/src/sexpr/parser_test.cpp +++ b/src/sexpr/parser_test.cpp @@ -20,32 +20,18 @@ #include <gtest/gtest.h> +#include "../tests/fdhack.hpp" + #include "../poison.hpp" namespace tmwa { -static -io::FD string_pipe(ZString sz) -{ - io::FD rfd, wfd; - if (-1 == io::FD::pipe(rfd, wfd)) - return io::FD(); - if (sz.size() != wfd.write(sz.c_str(), sz.size())) - { - rfd.close(); - wfd.close(); - return io::FD(); - } - wfd.close(); - return rfd; -} - TEST(sexpr, parser) { sexpr::SExpr s; io::LineSpan span; - sexpr::Lexer lexer("<parser-test1>"_s, string_pipe(" foo( ) 123\"\" \n"_s)); + sexpr::Lexer lexer(io::from_string, "<parser-test1>"_s, " foo( ) 123\"\" \n"_s); EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::TOKEN); @@ -70,7 +56,7 @@ TEST(sexpr, parser) TEST(sexpr, parselist) { sexpr::SExpr s; - sexpr::Lexer lexer("<parser-test1>"_s, string_pipe("(foo)(bar)\n"_s)); + sexpr::Lexer lexer(io::from_string, "<parser-test1>"_s, "(foo)(bar)\n"_s); EXPECT_TRUE(sexpr::parse(lexer, s)); EXPECT_EQ(s._type, sexpr::LIST); @@ -90,6 +76,7 @@ TEST(sexpr, parselist) TEST(sexpr, parsebad) { + QuietFd q; for (LString bad : { "(\n"_s, ")\n"_s, @@ -105,7 +92,7 @@ TEST(sexpr, parsebad) { sexpr::SExpr s; io::LineSpan span; - sexpr::Lexer lexer("<parse-bad>"_s, string_pipe(bad)); + sexpr::Lexer lexer(io::from_string, "<parse-bad>"_s, bad); EXPECT_FALSE(sexpr::parse(lexer, s)); EXPECT_EQ(lexer.peek(), sexpr::TOK_ERROR); } |