From bcb098e8eb18637b6999789585a38ff9168de9d5 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 3 Jul 2022 14:37:10 -0700 Subject: Add a diff library. I was hesitant to add a diff library, but it was surprisingly easy. A straightforward application of dynamic programming. --- csc/compare-test.csc | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 csc/compare-test.csc (limited to 'csc/compare-test.csc') diff --git a/csc/compare-test.csc b/csc/compare-test.csc new file mode 100644 index 0000000..6df177f --- /dev/null +++ b/csc/compare-test.csc @@ -0,0 +1,82 @@ +(import (scheme base) + (only (csc match) + define-match-record-type) + (only (csc testing) + assert-equal + test) + (csc compare)) + + +(test diff-list + (assert-equal + " ( + 1 + -2 + 3 + +3.5 + 4 + ) +" + (diff '(1 2 3 4) '(1 3 3.5 4)))) + + +(define-match-record-type + (make-test-type a b) + test-type? + %test-type + (a test-type-a) + (b test-type-b)) + + +(test diff-record + (assert-equal + " ( + (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 + ) + ) + ) +" + (diff "line-one\nline-two\nline-three" "line-one\nline-three"))) + + +(test diff-vector + (assert-equal + " ( + (type . + vector + ) + (value . + ( + 1 + -2 + 3 + ) + ) + ) +" + (diff #(1 2 3) #(1 3)))) -- cgit v1.3.1