(require-extension ports npdiff format-textdiff patch test) (define format make-format-textdiff) (test-group "empty input sequences" (let ((empty (with-input-from-string "" read-lines)) (abc (with-input-from-string "abc" read-lines))) (let ((hunks1 (textdiff empty abc 3)) (hunks2 (textdiff abc empty 3))) (test-group "diff empty -> abc" (test "normal format" #< abc EOF (call-with-output-string (lambda (out) ((format 'normal) out hunks1)))) (test "ed format" #< empty" (test "normal format" #< text2" (let* ((text1 (call-with-input-file "text1" read-lines)) (text2 (call-with-input-file "text2" read-lines)) (hunks (textdiff text1 text2 3))) (test "normal format" #< w 3,4c4,6 < c < d --- > x > y > z 6,7d7 < f < g EOF (call-with-output-string (lambda (out) ((format 'normal) out hunks)))) (test "ed format" #<sexp hunks)) (large1 (with-input-from-file "large1" read-string))) (test "large0 -> large1" large1 (with-output-to-string (lambda () (with-input-from-file "large0" (lambda () (apply-patch spatch)))))))) (test-group "normal diff patch" (let* ((npatch (call-with-output-string (lambda (out) ((format 'normal) out hunks)))) (large1 (with-input-from-file "large1" read-string))) (test "large0 -> large1" large1 (with-output-to-string (lambda () (with-input-from-file "large0" (lambda () (apply-patch (with-input-from-string npatch make-patch))))))))) (define patch-files (list "large0.patch.ed" "large0.patch.rcs" "large0.patch.context")) (define patch-procs (list (lambda (port) ((format 'ed) port hunks)) (lambda (port) ((format 'rcs) port hunks)) (lambda (port) ((format 'context) port hunks "large0" "Sun Jun 3 18:28:06 2007" "large1" "Sun Jun 3 18:28:06 2007")))) (for-each (lambda (patch-file f) (call-with-output-file patch-file f)) patch-files patch-procs)