[goos] support improper lists in pretty printer (#1001)

This commit is contained in:
water111
2021-12-09 20:56:50 -05:00
committed by GitHub
parent 1cac684f1b
commit fe9c5c10d1
2 changed files with 39 additions and 9 deletions
+20 -2
View File
@@ -102,10 +102,10 @@ TEST(PrettyPrinter2, Debugging) {
}
namespace {
std::string pretty_print_v2(const std::string& str) {
std::string pretty_print_v2(const std::string& str, int line_length = 110) {
auto obj =
pretty_print::get_pretty_printer_reader().read_from_string(str).as_pair()->cdr.as_pair()->car;
return pretty_print::to_string(obj);
return pretty_print::to_string(obj, line_length);
}
} // namespace
@@ -240,3 +240,21 @@ TEST(PrettyPrint2, ParenWayOutToTheRight) {
)
))");
}
TEST(PrettyPrint2, ImproperList) {
std::string code = "( ( a . b) ( c . d ) ( e f . g) . #f )";
EXPECT_EQ(pretty_print_v2(code), "((a . b) (c . d) (e f . g) . #f)");
}
TEST(PrettyPrint2, ImproperListMultiLine) {
std::string code =
"( ( asdfasfdasdf . b) ( casdfsadfasdf . dsadfasfdsf ) ( esdfasdf fdasfsadf . gdfasfd) . "
"#f )";
EXPECT_EQ(pretty_print_v2(code, 40),
"((asdfasfdasdf . b)\n"
" (casdfsadfasdf . dsadfasfdsf)\n"
" (esdfasdf fdasfsadf . gdfasfd)\n"
" .\n"
" #f\n"
" )");
}