(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" #< pointers2" (let* ((text1 (call-with-input-file "pointers1" read-lines)) (text2 (call-with-input-file "pointers2" read-lines)) (hunks (textdiff text1 text2 3))) (test "normal format" #<Filer (without login) 9c8 <
  • WaitleSQL
  • --- >
  • Filer (without login)
  • 14d12 < EOF (call-with-output-string (lambda (out) ((format 'normal) out hunks)))) (test "ed format" #<Filer (without login) . 7d EOF (call-with-output-string (lambda (out) ((format 'ed) out hunks)))) (test "rcs format" #<Filer (without login) d14 1 EOF (call-with-output-string (lambda (out) ((format 'rcs) out hunks)))) (test "context format" #< -
  • Filer (without login)
  • Filer (with login)
  • !
  • WaitleSQL
  • Have fun!!! - --- 4,15 ---- here is some useful pointers. Have fun!!! EOF (call-with-output-string (lambda (out) ((format 'context) out hunks "pointers1" "" "pointers2" "")))) )) (define hunks (let ((large0 (call-with-input-file "large0" read-lines)) (large1 (call-with-input-file "large1" read-lines))) (textdiff large0 large1 3))) (test-group "s-expression patch" (let* ((spatch (textdiff->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)