Fix "grep -w"
[git/dscho.git] / t / t7002-grep.sh
blob00a7d762ce6867d4f14d8157ddee4daec3dea0f6
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='git grep -w
9 . ./test-lib.sh
11 test_expect_success setup '
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
26 for H in HEAD ''
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" '
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
44 test_expect_success "grep -w $L (x)" '
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
52 test_expect_success "grep -w $L (y-1)" '
54 echo ${HC}y:1:y yy
55 } >expected &&
56 git grep -n -w -e "^y" $H >actual &&
57 diff expected actual
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
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
83 done
85 test_done