From daba5db44a27644f8793a576e3982793eb47db9e Mon Sep 17 00:00:00 2001 From: Gustavo Massaccesi Date: Wed, 29 May 2019 10:30:04 -0300 Subject: [PATCH] simplify code and test for print-pair-curly-braces After the change that makes printing of struct ignore print-pair-curly-braces it is possible to simplify the code in io/print and the associated tests. --- pkgs/racket-test-core/tests/racket/print.rktl | 25 +++++++------------ racket/src/io/print/list.rkt | 12 +++------ 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/pkgs/racket-test-core/tests/racket/print.rktl b/pkgs/racket-test-core/tests/racket/print.rktl index a060b83e1b..5fdca3ee1a 100644 --- a/pkgs/racket-test-core/tests/racket/print.rktl +++ b/pkgs/racket-test-core/tests/racket/print.rktl @@ -472,14 +472,7 @@ (test-print/all (list (cons x x)) "{{#0=#(struct:s) . #0#}}" "{{#0=#(struct:s) . #0#}}" "{{#0=#(struct:s) . #0#}}" "(list (cons #0=(s) #0#))" "{{#0=#(struct:s) . #0#}}") (test-print/all (list x x) - "{#0=#(struct:s) #0#}" "{#0=#(struct:s) #0#}" "{#0=#(struct:s) #0#}" "(list #0=(s) #0#)" "{#0=#(struct:s) #0#}") - (test-print/all (b 1 2) - "#(struct:b 1 2)" "#(struct:b 1 2)" "#(struct:b 1 2)" "(b 1 2)" "#(struct:b 1 2)") - (test-print/all (c 1 2) - "#s(c 1 2)" "#s(c 1 2)" "#s(c 1 2)" "'#s(c 1 2)" "#s(c 1 2)") - (test-print/all (c x x) - "#s(c #0=#(struct:s) #0#)" "#s(c #0=#(struct:s) #0#)" "#s(c #0=#(struct:s) #0#)" "(c #0=(s) #0#)" "#s(c #0=#(struct:s) #0#)")) - + "{#0=#(struct:s) #0#}" "{#0=#(struct:s) #0#}" "{#0=#(struct:s) #0#}" "(list #0=(s) #0#)" "{#0=#(struct:s) #0#}")) (parameterize ([print-pair-curly-braces #f]) (test-print/all (cons 1 2) "(1 . 2)" "(1 . 2)" "(1 . 2)" "'(1 . 2)" "(1 . 2)") @@ -496,16 +489,16 @@ (test-print/all (list (cons x x)) "((#0=#(struct:s) . #0#))" "((#0=#(struct:s) . #0#))" "((#0=#(struct:s) . #0#))" "(list (cons #0=(s) #0#))" "((#0=#(struct:s) . #0#))") (test-print/all (list x x) - "(#0=#(struct:s) #0#)" "(#0=#(struct:s) #0#)" "(#0=#(struct:s) #0#)" "(list #0=(s) #0#)" "(#0=#(struct:s) #0#)") - (test-print/all (b 1 2) - "#(struct:b 1 2)" "#(struct:b 1 2)" "#(struct:b 1 2)" "(b 1 2)" "#(struct:b 1 2)") - (test-print/all (c 1 2) - "#s(c 1 2)" "#s(c 1 2)" "#s(c 1 2)" "'#s(c 1 2)" "#s(c 1 2)") - (test-print/all (c x x) - "#s(c #0=#(struct:s) #0#)" "#s(c #0=#(struct:s) #0#)" "#s(c #0=#(struct:s) #0#)" "(c #0=(s) #0#)" "#s(c #0=#(struct:s) #0#)")) + "(#0=#(struct:s) #0#)" "(#0=#(struct:s) #0#)" "(#0=#(struct:s) #0#)" "(list #0=(s) #0#)" "(#0=#(struct:s) #0#)")) + (test-print/all (a 1 2) "#" "#" "#" "#" "#") - + (test-print/all (b 1 2) + "#(struct:b 1 2)" "#(struct:b 1 2)" "#(struct:b 1 2)" "(b 1 2)" "#(struct:b 1 2)") + (test-print/all (c 1 2) + "#s(c 1 2)" "#s(c 1 2)" "#s(c 1 2)" "'#s(c 1 2)" "#s(c 1 2)") + (test-print/all (c x x) + "#s(c #0=#(struct:s) #0#)" "#s(c #0=#(struct:s) #0#)" "#s(c #0=#(struct:s) #0#)" "(c #0=(s) #0#)" "#s(c #0=#(struct:s) #0#)") (void)))) ;; ---------------------------------------- diff --git a/racket/src/io/print/list.rkt b/racket/src/io/print/list.rkt index eafbce6908..930dfc3918 100644 --- a/racket/src/io/print/list.rkt +++ b/racket/src/io/print/list.rkt @@ -13,15 +13,9 @@ (and (eq? mode PRINT-MODE/UNQUOTED) (not alt-list-constructor) (not (uninterrupted-list? v graph)))) - (define curly? (cond - [(eq? mode PRINT-MODE/UNQUOTED) - (and (not unquoted-pairs?) - alt-list-constructor - (eq? (string-ref alt-list-constructor 0) #\{))] - [alt-list-prefix - (eq? (string-ref alt-list-prefix 0) #\{)] - [else - (config-get config print-pair-curly-braces)])) + (define curly? (and (not (eq? mode PRINT-MODE/UNQUOTED)) + (not alt-list-prefix) + (config-get config print-pair-curly-braces))) (define (abbreviation v) (and (eq? mode PRINT-MODE/QUOTED) (pair? v)