Code

00a7d762ce6867d4f14d8157ddee4daec3dea0f6
[git.git] / t / t7002-grep.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Junio C Hamano
4 #
6 test_description='git grep -w
7 '
9 . ./test-lib.sh
11 test_expect_success setup '
12         {
13                 echo foo mmap bar
14                 echo foo_mmap bar
15                 echo foo_mmap bar mmap
16                 echo foo mmap bar_mmap
17                 echo foo_mmap bar mmap baz
18         } >file &&
19         echo x x xx x >x &&
20         echo y yy >y &&
21         echo zzz > z &&
22         git add file x y z &&
23         git commit -m initial
24 '
26 for H in HEAD ''
27 do
28         case "$H" in
29         HEAD)   HC='HEAD:' L='HEAD' ;;
30         '')     HC= L='in working tree' ;;
31         esac
33         test_expect_success "grep -w $L" '
34                 {
35                         echo ${HC}file:1:foo mmap bar
36                         echo ${HC}file:3:foo_mmap bar mmap
37                         echo ${HC}file:4:foo mmap bar_mmap
38                         echo ${HC}file:5:foo_mmap bar mmap baz
39                 } >expected &&
40                 git grep -n -w -e mmap $H >actual &&
41                 diff expected actual
42         '
44         test_expect_success "grep -w $L (x)" '
45                 {
46                         echo ${HC}x:1:x x xx x
47                 } >expected &&
48                 git grep -n -w -e "x xx* x" $H >actual &&
49                 diff expected actual
50         '
52         test_expect_success "grep -w $L (y-1)" '
53                 {
54                         echo ${HC}y:1:y yy
55                 } >expected &&
56                 git grep -n -w -e "^y" $H >actual &&
57                 diff expected actual
58         '
60         test_expect_success "grep -w $L (y-2)" '
61                 : >expected &&
62                 if git grep -n -w -e "^y y" $H >actual
63                 then
64                         echo should not have matched
65                         cat actual
66                         false
67                 else
68                         diff expected actual
69                 fi
70         '
72         test_expect_success "grep -w $L (z)" '
73                 : >expected &&
74                 if git grep -n -w -e "^z" $H >actual
75                 then
76                         echo should not have matched
77                         cat actual
78                         false
79                 else
80                         diff expected actual
81                 fi
82         '
83 done
85 test_done