diff options
| author | Arun Isaac | 2025-10-03 17:46:50 +0100 |
|---|---|---|
| committer | Arun Isaac | 2025-10-03 19:31:48 +0100 |
| commit | c99f6841d17930271e56843e5e46bd5b38cec1b1 (patch) | |
| tree | d5dbdb1f939d97bb2d6f9cfa67cce171d8f0e3b1 /bin/run64 | |
| parent | d9b8f73b749dad723f81409349abc0664c6ebe7a (diff) | |
| download | run64-c99f6841d17930271e56843e5e46bd5b38cec1b1.tar.gz run64-c99f6841d17930271e56843e5e46bd5b38cec1b1.tar.lz run64-c99f6841d17930271e56843e5e46bd5b38cec1b1.zip | |
bin: Pretty print actual and expected values.
Diffstat (limited to 'bin/run64')
| -rwxr-xr-x | bin/run64 | 73 |
1 files changed, 68 insertions, 5 deletions
diff --git a/bin/run64 b/bin/run64 index 6565acb..ae80e13 100755 --- a/bin/run64 +++ b/bin/run64 @@ -100,6 +100,68 @@ given string in an ANSI escape code." (display (color (string-append "== " text))) (newline)) +(define (pretty-print obj column) + "Pretty print OBJ. COLUMN is the current column the cursor is in, starting at 0." + (define (print-list-with-opener lst column opener) + ;; Open the list. + (display opener) + (let ((child-column (+ (string-length opener) column))) + (chibi:match lst + ;; If an empty list, close without doing anything else. + (() + (display ")")) + ((head tail ...) + ;; Print first element without any column. + (print head child-column) + ;; Print the rest of the elements after a newline and column each. + (for-each (lambda (element) + (newline) + (display (make-string child-column #\space)) + (print element child-column)) + tail) + ;; Close the list. + (display ")"))))) + + (define (print obj column) + (cond + ;; Lists + ((list? obj) + (print-list-with-opener obj column "(")) + ;; Vectors + ((vector? obj) + (print-list-with-opener (vector->list obj) column "#(")) + ;; Pairs that are not lists + ((pair? obj) + (if (or (vector? (car obj)) + (vector? (cdr obj)) + (list? (car obj)) + (list? (cdr obj))) + ;; Print pairs with lists or vectors on several lines. + (let ((child-column (+ (string-length "(") + column))) + (display "(") + (print (car obj) child-column) + (newline) + (display (make-string child-column #\space)) + (display ".") + (newline) + (display (make-string child-column #\space)) + (print (cdr obj) child-column) + (display ")")) + ;; Print pairs with only atoms on a single line. + (begin + (display "(") + (print (car obj) column) + (display " . ") + (print (cdr obj) column) + (display ")")))) + ;; Atoms + (else + (write obj)))) + + (print obj column) + (newline)) + (define (main args) (let ((runner (make-runner))) (headline "test session starts" bold) @@ -158,12 +220,13 @@ given string in an ANSI escape code." ;; actual values. (else (newline) - (display (red "Actual value: ")) - (write (assq-ref failure 'actual-value)) - (newline) - (display (red "Expected value: ")) - (write (assq-ref failure 'expected-value)) + (display (red "Actual: ")) + (pretty-print (assq-ref failure 'actual-value) + (string-length "Actual: ")) (newline) + (display (red "Expected: ")) + (pretty-print (assq-ref failure 'expected-value) + (string-length "Expected: ")) (newline))))))) (test-runner-aux-value runner)) (newline)) |
