From d9a651a17e4abb63a24b764f6a850a0df74bd156 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Tue, 12 Jul 2022 22:55:12 -0700 Subject: Slightly improve diff formatting. --- csc/compare-test.csc | 76 ++++++++++++++++++++++++++-------------------------- csc/compare.csc | 26 +++++++++--------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/csc/compare-test.csc b/csc/compare-test.csc index 6df177f..68ea5e6 100644 --- a/csc/compare-test.csc +++ b/csc/compare-test.csc @@ -9,13 +9,13 @@ (test diff-list (assert-equal - " ( - 1 - -2 - 3 - +3.5 - 4 - ) + " ( + 1 + - 2 + 3 + + 3.5 + 4 + ) " (diff '(1 2 3 4) '(1 3 3.5 4)))) @@ -30,53 +30,53 @@ (test diff-record (assert-equal - " ( - (a . - 5 - ) - (b . - -5 - +6 - ) - (type . - + " ( + (a . + 5 + ) + (b . + - 5 + + 6 + ) + (type . + + ) ) - ) " (diff (make-test-type 5 5) (make-test-type 5 6) (cons test-type? %test-type)))) (test diff-multiline-string (assert-equal - " ( - (type . - string - ) - (value . - ( - line-one - -line-two - line-three + " ( + (type . + string + ) + (value . + ( + line-one + - line-two + line-three + ) ) ) - ) " (diff "line-one\nline-two\nline-three" "line-one\nline-three"))) (test diff-vector (assert-equal - " ( - (type . - vector - ) - (value . - ( - 1 - -2 - 3 + " ( + (type . + vector + ) + (value . + ( + 1 + - 2 + 3 + ) ) ) - ) " (diff #(1 2 3) #(1 3)))) diff --git a/csc/compare.csc b/csc/compare.csc index cbf8b6d..ab7e3c1 100644 --- a/csc/compare.csc +++ b/csc/compare.csc @@ -77,17 +77,17 @@ (define (pretty w x indent) (cond ((list? x) - (fprintf w "{}(\n" indent) + (fprintf w "{} (\n" indent) (loop with new-indent = (string-append indent " ") for v in x do (pretty w v new-indent)) - (fprintf w "{})\n" indent)) + (fprintf w "{} )\n" indent)) ((and (pair? x) (symbol? (car x))) - (fprintf w "{}({} .\n" indent (car x)) + (fprintf w "{} ({} .\n" indent (car x)) (pretty w (cdr x) (string-append indent " ")) - (fprintf w "{})\n" indent)) - (else (fprintf w "{}{}\n" indent x)))) + (fprintf w "{} )\n" indent)) + (else (fprintf w "{} {}\n" indent x)))) (define (diff* w x y indent) @@ -99,13 +99,13 @@ (and (string? x) (string? y))) (if (equal? x y) (begin - (fprintf w "{} {}\n" indent x) + (fprintf w "{} {}\n" indent x) #t) (begin - (fprintf w "{}-{}\n{}+{}\n" indent x indent y) + (fprintf w "{}- {}\n{}+ {}\n" indent x indent y) #f))) ((and (alist? x) (alist? y)) - (fprintf w "{} (\n" indent) + (fprintf w "{} (\n" indent) (let ((key-lcs (lcs (map car x) (map car y) symbol=?)) (indent* (string-append indent " ")) (equal #t)) @@ -123,10 +123,10 @@ (set! equal #f) else if (symbol=? (caar x) (caar y) (car key-lcs)) - do (fprintf w "{} ({} .\n" indent* (car key-lcs)) + do (fprintf w "{} ({} .\n" indent* (car key-lcs)) (set! equal (and (diff* w (cdar x) (cdar y) (string-append indent* " ")) equal)) - (fprintf w "{} )\n" indent*) + (fprintf w "{} )\n" indent*) (set! x (cdr x)) (set! y (cdr y)) (set! key-lcs (cdr key-lcs)) @@ -138,10 +138,10 @@ do (pretty w (car x) (string-append indent* "-")) (set! x (cdr x)) (set! equal #f)) - (fprintf w "{} )\n" indent) + (fprintf w "{} )\n" indent) equal)) ((and (list? x) (list? y)) - (fprintf w "{} (\n" indent) + (fprintf w "{} (\n" indent) (let* ((common (lcs x y equal?)) (indent* (string-append indent " ")) (equal #t)) @@ -181,7 +181,7 @@ (set! x (cdr x)) (set! y (cdr y)) (set! equal #f)) - (fprintf w "{} )\n" indent) + (fprintf w "{} )\n" indent) equal)))) -- cgit v1.3.1