]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - vcs/t/test.sh
Move to vcs/ in preparation for merge into new dotfiles repository
[config/dotfiles.git] / vcs / t / test.sh
1 #!/bin/sh
2
3 # Small test file to check different --word-diff-regex settings in Git.
4
5 # Copyright (C) 2012-2014  Simon Ruderich
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20
21 set -eu
22
23 git_diff() {
24     git diff --color=never --word-diff=plain --word-diff-regex="$1" \
25         | grep -v '^index ' >"result-$2.txt"
26     diff -u "../expected-$2.txt" "result-$2.txt"
27 }
28
29
30 # Setup test directory/files.
31 mkdir test
32 cd test
33
34 git init >/dev/null
35 cat >test.txt <<EOF
36 Tests
37 =====
38
39 Simple sentence with a few words.
40
41 Longer sentence with even more words .. ain't that nice?
42
43 And another one, just testing.
44
45 option: value
46 option-two: value-two
47 option-three: value-three
48
49 function testme() {
50     first_call();
51     if (a == b) {
52         if (!second_call()) {
53             third_call();
54         }
55     }
56     return 42;
57 }
58
59 allow = \$! \$? \$.
60 allow = \$! \$? \$.
61 allow = \$! \$? \$.
62 EOF
63 git add test.txt
64 git commit -m 'Initial commit.' >/dev/null
65
66 cat >test.txt <<EOF
67 Tests
68 ====
69
70 Short sentence with words!
71
72 Longer sentence even more words, ain't that nice!
73
74 And other one, just testing.
75
76 option: new value
77 option-two: new-value-two
78 option-three: "value-three"
79
80 function testme() {
81     firstCall();
82     while (a != b) {
83         if (!second_var) {
84             third_call() && fourth_call() \\
85                 || fifth_call();
86         }
87     }
88     return 42;
89 }
90
91 allow = \$0 \$! \$? \$.
92 allow = \$! \$?
93 allow = \$0 \$! \$?
94 EOF
95
96
97 git_diff '' empty
98
99 git_diff '[^[:space:]]+' nonspaces
100
101 git_diff '[a-zA-Z0-9_]|[^a-zA-Z0-9_]'    word-nonword
102 git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]'   words-nonword
103 git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]+'  words-nonwords
104 git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_ ]+' words-nonwordspaces
105
106 git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]+|[ ]+'  words-nonwords-spaces
107 git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_ ]+|[ ]+' words-nonwordspaces-spaces
108
109
110 # Remove test directory after successful testing.
111 rm -rf ../test