]> ruderich.org/simon Gitweb - config/dotfiles.git/blobdiff - vcs/t/test.sh
Move to vcs/ in preparation for merge into new dotfiles repository
[config/dotfiles.git] / vcs / t / test.sh
diff --git a/vcs/t/test.sh b/vcs/t/test.sh
new file mode 100755 (executable)
index 0000000..6f1084b
--- /dev/null
@@ -0,0 +1,111 @@
+#!/bin/sh
+
+# Small test file to check different --word-diff-regex settings in Git.
+
+# Copyright (C) 2012-2014  Simon Ruderich
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# 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.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+set -eu
+
+git_diff() {
+    git diff --color=never --word-diff=plain --word-diff-regex="$1" \
+        | grep -v '^index ' >"result-$2.txt"
+    diff -u "../expected-$2.txt" "result-$2.txt"
+}
+
+
+# Setup test directory/files.
+mkdir test
+cd test
+
+git init >/dev/null
+cat >test.txt <<EOF
+Tests
+=====
+
+Simple sentence with a few words.
+
+Longer sentence with even more words .. ain't that nice?
+
+And another one, just testing.
+
+option: value
+option-two: value-two
+option-three: value-three
+
+function testme() {
+    first_call();
+    if (a == b) {
+        if (!second_call()) {
+            third_call();
+        }
+    }
+    return 42;
+}
+
+allow = \$! \$? \$.
+allow = \$! \$? \$.
+allow = \$! \$? \$.
+EOF
+git add test.txt
+git commit -m 'Initial commit.' >/dev/null
+
+cat >test.txt <<EOF
+Tests
+====
+
+Short sentence with words!
+
+Longer sentence even more words, ain't that nice!
+
+And other one, just testing.
+
+option: new value
+option-two: new-value-two
+option-three: "value-three"
+
+function testme() {
+    firstCall();
+    while (a != b) {
+        if (!second_var) {
+            third_call() && fourth_call() \\
+                || fifth_call();
+        }
+    }
+    return 42;
+}
+
+allow = \$0 \$! \$? \$.
+allow = \$! \$?
+allow = \$0 \$! \$?
+EOF
+
+
+git_diff '' empty
+
+git_diff '[^[:space:]]+' nonspaces
+
+git_diff '[a-zA-Z0-9_]|[^a-zA-Z0-9_]'    word-nonword
+git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]'   words-nonword
+git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]+'  words-nonwords
+git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_ ]+' words-nonwordspaces
+
+git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]+|[ ]+'  words-nonwords-spaces
+git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_ ]+|[ ]+' words-nonwordspaces-spaces
+
+
+# Remove test directory after successful testing.
+rm -rf ../test