t / t4034-diff-words.shon commit color-words: enable REG_NEWLINE to help user (bf82940)
   1#!/bin/sh
   2
   3test_description='word diff colors'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8
   9        git config diff.color.old red
  10        git config diff.color.new green
  11
  12'
  13
  14decrypt_color () {
  15        sed \
  16                -e 's/.\[1m/<WHITE>/g' \
  17                -e 's/.\[31m/<RED>/g' \
  18                -e 's/.\[32m/<GREEN>/g' \
  19                -e 's/.\[36m/<BROWN>/g' \
  20                -e 's/.\[m/<RESET>/g'
  21}
  22
  23word_diff () {
  24        test_must_fail git diff --no-index "$@" pre post > output &&
  25        decrypt_color < output > output.decrypted &&
  26        test_cmp expect output.decrypted
  27}
  28
  29cat > pre <<\EOF
  30h(4)
  31
  32a = b + c
  33EOF
  34
  35cat > post <<\EOF
  36h(4),hh[44]
  37
  38a = b + c
  39
  40aa = a
  41
  42aeff = aeff * ( aaa )
  43EOF
  44
  45cat > expect <<\EOF
  46<WHITE>diff --git a/pre b/post<RESET>
  47<WHITE>index 330b04f..5ed8eff 100644<RESET>
  48<WHITE>--- a/pre<RESET>
  49<WHITE>+++ b/post<RESET>
  50<BROWN>@@ -1,3 +1,7 @@<RESET>
  51<RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET>
  52<RESET>
  53a = b + c<RESET>
  54
  55<GREEN>aa = a<RESET>
  56
  57<GREEN>aeff = aeff * ( aaa )<RESET>
  58EOF
  59
  60test_expect_success 'word diff with runs of whitespace' '
  61
  62        word_diff --color-words
  63
  64'
  65
  66cat > expect <<\EOF
  67<WHITE>diff --git a/pre b/post<RESET>
  68<WHITE>index 330b04f..5ed8eff 100644<RESET>
  69<WHITE>--- a/pre<RESET>
  70<WHITE>+++ b/post<RESET>
  71<BROWN>@@ -1,3 +1,7 @@<RESET>
  72h(4),<GREEN>hh<RESET>[44]
  73<RESET>
  74a = b + c<RESET>
  75
  76<GREEN>aa = a<RESET>
  77
  78<GREEN>aeff = aeff * ( aaa<RESET> )
  79EOF
  80
  81test_expect_success 'word diff with a regular expression' '
  82
  83        word_diff --color-words="[a-z]+"
  84
  85'
  86
  87echo 'aaa (aaa)' > pre
  88echo 'aaa (aaa) aaa' > post
  89
  90cat > expect <<\EOF
  91<WHITE>diff --git a/pre b/post<RESET>
  92<WHITE>index c29453b..be22f37 100644<RESET>
  93<WHITE>--- a/pre<RESET>
  94<WHITE>+++ b/post<RESET>
  95<BROWN>@@ -1 +1 @@<RESET>
  96aaa (aaa) <GREEN>aaa<RESET>
  97EOF
  98
  99test_expect_success 'test parsing words for newline' '
 100
 101        word_diff --color-words="a+"
 102
 103'
 104
 105echo '(:' > pre
 106echo '(' > post
 107
 108cat > expect <<\EOF
 109<WHITE>diff --git a/pre b/post<RESET>
 110<WHITE>index 289cb9d..2d06f37 100644<RESET>
 111<WHITE>--- a/pre<RESET>
 112<WHITE>+++ b/post<RESET>
 113<BROWN>@@ -1 +1 @@<RESET>
 114(<RED>:<RESET>
 115EOF
 116
 117test_expect_success 'test when words are only removed at the end' '
 118
 119        word_diff --color-words=.
 120
 121'
 122
 123test_done