diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2022-08-02 11:57:39 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2022-08-08 11:22:32 +0200 |
| commit | f687e27e0385c7f9bab8d967293061158fc3f504 (patch) | |
| tree | 13ea17d05751f61e8f3b6c6ad057a076ec739488 /tests/read-print.scm | |
| parent | 3eb3901d7f1d4aae134cb64aa703af67c3c27cdf (diff) | |
read-print: Read and render vertical space.
* guix/read-print.scm (<vertical-space>, vertical-space?)
(vertical-space, vertical-space-height): New variables.
(combine-vertical-space, canonicalize-vertical-space)
(read-vertical-space): New procedures.
(read-with-comments): Use it in the #\newline case.
(pretty-print-with-comments): Add #:format-vertical-space and honor it.
Add case for 'vertical-space?'.
* guix/scripts/style.scm (format-package-definition): Pass
#:format-vertical-space to 'object->string*'.
* tests/read-print.scm ("read-with-comments: list with blank line")
("read-with-comments: list with multiple blank lines")
("read-with-comments: top-level blank lines")
("pretty-print-with-comments, canonicalize-vertical-space"): New tests.
Add a couple of additional round-trip tests.
Diffstat (limited to 'tests/read-print.scm')
| -rw-r--r-- | tests/read-print.scm | 76 |
1 files changed, 75 insertions, 1 deletions
diff --git a/tests/read-print.scm b/tests/read-print.scm index e9ba1127d4f..f915b7e2d21 100644 --- a/tests/read-print.scm +++ b/tests/read-print.scm | |||
| @@ -19,7 +19,8 @@ | |||
| 19 | (define-module (tests-style) | 19 | (define-module (tests-style) |
| 20 | #:use-module (guix read-print) | 20 | #:use-module (guix read-print) |
| 21 | #:use-module (guix gexp) ;for the reader extensions | 21 | #:use-module (guix gexp) ;for the reader extensions |
| 22 | #:use-module (srfi srfi-64)) | 22 | #:use-module (srfi srfi-64) |
| 23 | #:use-module (ice-9 match)) | ||
| 23 | 24 | ||
| 24 | (define-syntax-rule (test-pretty-print str args ...) | 25 | (define-syntax-rule (test-pretty-print str args ...) |
| 25 | "Test equality after a round-trip where STR is passed to | 26 | "Test equality after a round-trip where STR is passed to |
| @@ -40,6 +41,35 @@ | |||
| 40 | (call-with-input-string "(a . b)" | 41 | (call-with-input-string "(a . b)" |
| 41 | read-with-comments)) | 42 | read-with-comments)) |
| 42 | 43 | ||
| 44 | (test-equal "read-with-comments: list with blank line" | ||
| 45 | `(list with ,(vertical-space 1) blank line) | ||
| 46 | (call-with-input-string "\ | ||
| 47 | (list with | ||
| 48 | |||
| 49 | blank line)\n" | ||
| 50 | read-with-comments)) | ||
| 51 | |||
| 52 | (test-equal "read-with-comments: list with multiple blank lines" | ||
| 53 | `(list with ,(comment ";multiple\n" #t) | ||
| 54 | ,(vertical-space 3) blank lines) | ||
| 55 | (call-with-input-string "\ | ||
| 56 | (list with ;multiple | ||
| 57 | |||
| 58 | |||
| 59 | |||
| 60 | blank lines)\n" | ||
| 61 | read-with-comments)) | ||
| 62 | |||
| 63 | (test-equal "read-with-comments: top-level blank lines" | ||
| 64 | (list (vertical-space 2) '(a b c) (vertical-space 2)) | ||
| 65 | (call-with-input-string " | ||
| 66 | |||
| 67 | (a b c)\n\n" | ||
| 68 | (lambda (port) | ||
| 69 | (list (read-with-comments port) | ||
| 70 | (read-with-comments port) | ||
| 71 | (read-with-comments port))))) | ||
| 72 | |||
| 43 | (test-pretty-print "(list 1 2 3 4)") | 73 | (test-pretty-print "(list 1 2 3 4)") |
| 44 | (test-pretty-print "((a . 1) (b . 2))") | 74 | (test-pretty-print "((a . 1) (b . 2))") |
| 45 | (test-pretty-print "(a b c . boom)") | 75 | (test-pretty-print "(a b c . boom)") |
| @@ -181,6 +211,24 @@ mnopqrstuvwxyz.\")" | |||
| 181 | `(cons \"--without-any-problem\" | 211 | `(cons \"--without-any-problem\" |
| 182 | ,flags)))") | 212 | ,flags)))") |
| 183 | 213 | ||
| 214 | (test-pretty-print "\ | ||
| 215 | (vertical-space one: | ||
| 216 | |||
| 217 | two: | ||
| 218 | |||
| 219 | |||
| 220 | three: | ||
| 221 | |||
| 222 | |||
| 223 | |||
| 224 | end)") | ||
| 225 | |||
| 226 | (test-pretty-print "\ | ||
| 227 | (vertical-space one | ||
| 228 | |||
| 229 | ;; Comment after blank line. | ||
| 230 | two)") | ||
| 231 | |||
| 184 | (test-equal "pretty-print-with-comments, canonicalize-comment" | 232 | (test-equal "pretty-print-with-comments, canonicalize-comment" |
| 185 | "\ | 233 | "\ |
| 186 | (list abc | 234 | (list abc |
| @@ -206,4 +254,30 @@ mnopqrstuvwxyz.\")" | |||
| 206 | #:format-comment | 254 | #:format-comment |
| 207 | canonicalize-comment))))) | 255 | canonicalize-comment))))) |
| 208 | 256 | ||
| 257 | (test-equal "pretty-print-with-comments, canonicalize-vertical-space" | ||
| 258 | "\ | ||
| 259 | (list abc | ||
| 260 | |||
| 261 | def | ||
| 262 | |||
| 263 | ;; last one | ||
| 264 | ghi)" | ||
| 265 | (let ((sexp (call-with-input-string | ||
| 266 | "\ | ||
| 267 | (list abc | ||
| 268 | |||
| 269 | |||
| 270 | |||
| 271 | def | ||
| 272 | |||
| 273 | |||
| 274 | ;; last one | ||
| 275 | ghi)" | ||
| 276 | read-with-comments))) | ||
| 277 | (call-with-output-string | ||
| 278 | (lambda (port) | ||
| 279 | (pretty-print-with-comments port sexp | ||
| 280 | #:format-vertical-space | ||
| 281 | canonicalize-vertical-space))))) | ||
| 282 | |||
| 209 | (test-end) | 283 | (test-end) |
