]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - t/test.sh
aedbff09d350623626a03b886ae09d34321aaec8
[config/dotfiles.git] / 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  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 -e
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 EOF
59 git add test.txt
60 git commit -m 'Initial commit.' > /dev/null
61
62 cat > test.txt <<EOF
63 Tests
64 ====
65
66 Short sentence with words!
67
68 Longer sentence even more words, ain't that nice!
69
70 And other one, just testing.
71
72 option: new value
73 option-two: new-value-two
74 option-three: "value-three"
75
76 function testme() {
77     firstCall();
78     while (a != b) {
79         if (!second_var) {
80             third_call() && fourth_call() \\
81                 || fifth_call();
82         }
83     }
84     return 42;
85 }
86 EOF
87
88
89 git_diff '' empty
90
91 git_diff '[^[:space:]]+' nonspaces
92
93 git_diff '[a-zA-Z0-9_]|[^a-zA-Z0-9_]'    word-nonword
94 git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]'   words-nonword
95 git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]+'  words-nonwords
96 git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_ ]+' words-nonwordspaces
97
98 git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]+|[ ]+'  words-nonwords-spaces
99 git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_ ]+|[ ]+' words-nonwordspaces-spaces
100
101
102 # Remove test directory after successful testing.
103 rm -rf ../test