00a7d762ce6867d4f14d8157ddee4daec3dea0f6
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Junio C Hamano
   4#
   5
   6test_description='git grep -w
   7'
   8
   9. ./test-lib.sh
  10
  11test_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'
  25
  26for H in HEAD ''
  27do
  28        case "$H" in
  29        HEAD)   HC='HEAD:' L='HEAD' ;;
  30        '')     HC= L='in working tree' ;;
  31        esac
  32
  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        '
  43
  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        '
  51
  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        '
  59
  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        '
  71
  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        '
  83done
  84
  85test_done