summaryrefslogtreecommitdiff
path: root/test/diff.test
diff options
context:
space:
mode:
Diffstat (limited to 'test/diff.test')
-rw-r--r--test/diff.test162
1 files changed, 162 insertions, 0 deletions
diff --git a/test/diff.test b/test/diff.test
new file mode 100644
index 0000000..4b02329
--- /dev/null
+++ b/test/diff.test
@@ -0,0 +1,162 @@
+#
+# Copyright (c) 2016 D. Richard Hipp
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the Simplified BSD License (also
+# known as the "2-Clause License" or "FreeBSD License".)
+#
+# This program is distributed in the hope that it will be useful,
+# but without any warranty; without even the implied warranty of
+# merchantability or fitness for a particular purpose.
+#
+# Author contact information:
+# drh@hwaci.com
+# http://www.hwaci.com/drh/
+#
+############################################################################
+#
+# Tests for the diff command.
+#
+
+require_no_open_checkout
+
+test_setup; set rootDir [file normalize [pwd]]
+
+###################################
+# Tests of binary file detection. #
+###################################
+
+file mkdir .fossil-settings
+write_file [file join .fossil-settings binary-glob] "*"
+
+write_file file0.dat ""; # no content.
+write_file file1.dat "test file 1 (one line no term)."
+write_file file2.dat "test file 2 (NUL character).\0"
+write_file file3.dat "test file 3 (long line).[string repeat x 32768]"
+write_file file4.dat "test file 4 (long line).[string repeat y 32768]\ntwo"
+write_file file5.dat "[string repeat z 32768]\ntest file 5 (long line)."
+
+fossil add $rootDir
+fossil commit -m "c1"
+
+###############################################################################
+
+fossil ls
+test diff-ls-1 {[normalize_result] eq \
+"file0.dat\nfile1.dat\nfile2.dat\nfile3.dat\nfile4.dat\nfile5.dat"}
+
+###############################################################################
+
+write_file file0.dat "\0"
+fossil diff file0.dat
+
+test diff-file0-1 {[normalize_result] eq {Index: file0.dat
+==================================================================
+--- file0.dat
++++ file0.dat
+cannot compute difference between binary files}}
+
+###############################################################################
+
+write_file file1.dat [string repeat z 32768]
+fossil diff file1.dat
+
+test diff-file1-1 {[normalize_result] eq {Index: file1.dat
+==================================================================
+--- file1.dat
++++ file1.dat
+cannot compute difference between binary files}}
+
+###############################################################################
+
+write_file file2.dat "test file 2 (no NUL character)."
+fossil diff file2.dat
+
+test diff-file2-1 {[normalize_result] eq {Index: file2.dat
+==================================================================
+--- file2.dat
++++ file2.dat
+cannot compute difference between binary files}}
+
+###############################################################################
+
+write_file file3.dat "test file 3 (not a long line)."
+fossil diff file3.dat
+
+test diff-file3-1 {[normalize_result] eq {Index: file3.dat
+==================================================================
+--- file3.dat
++++ file3.dat
+cannot compute difference between binary files}}
+
+###############################################################################
+
+write_file file4.dat "test file 4 (not a long line).\ntwo"
+fossil diff file4.dat
+
+test diff-file4-1 {[normalize_result] eq {Index: file4.dat
+==================================================================
+--- file4.dat
++++ file4.dat
+cannot compute difference between binary files}}
+
+###############################################################################
+
+write_file file5.dat "[string repeat 0 16]\ntest file 5 (not a long line)."
+fossil diff file5.dat
+
+test diff-file5-1 {[normalize_result] eq {Index: file5.dat
+==================================================================
+--- file5.dat
++++ file5.dat
+cannot compute difference between binary files}}
+
+###############################################################################
+
+write_file file6a.dat "{\n \"abc\": {\n \"def\": false,\n \"ghi\": false\n }\n}\n"
+write_file file6b.dat "{\n \"abc\": {\n \"def\": false,\n \"ghi\": false\n },\n \"jkl\": {\n \"mno\": {\n \"pqr\": false\n }\n }\n}\n"
+fossil xdiff -y -W 16 file6a.dat file6b.dat
+test diff-file-6-1 {[normalize_result] eq {========== file6a.dat ===== versus ===== file6b.dat =====
+ 1 { 1 {
+ 2 "abc": { 2 "abc": {
+ 3 "def": false, 3 "def": false,
+ 4 "ghi": false 4 "ghi": false
+ > 5 },
+ > 6 "jkl": {
+ > 7 "mno": {
+ > 8 "pqr": false
+ > 9 }
+ 5 } 10 }
+ 6 } 11 }}}
+
+###############################################################################
+
+fossil rm file1.dat
+fossil diff -v file1.dat
+
+test diff-deleted-file-1 {[normalize_result] eq {DELETED file1.dat
+Index: file1.dat
+==================================================================
+--- file1.dat
++++ /dev/null
+@@ -1,1 +0,0 @@
+-test file 1 (one line no term).}}
+
+###############################################################################
+
+write_file file6.dat "test file 6 (one line no term)."
+fossil add file6.dat
+
+fossil diff -v file6.dat
+
+test diff-added-file-1 {[normalize_result] eq {ADDED file6.dat
+Index: file6.dat
+==================================================================
+--- /dev/null
++++ file6.dat
+@@ -0,0 +1,1 @@
++test file 6 (one line no term).}}
+
+###############################################################################
+
+test_cleanup