#!/bin/sh test_description='word diff colors' . ./test-lib.sh test_expect_success setup ' git config diff.color.old red git config diff.color.new green ' decrypt_color () { sed \ -e 's/.\[1m//g' \ -e 's/.\[31m//g' \ -e 's/.\[32m//g' \ -e 's/.\[36m//g' \ -e 's/.\[m//g' } word_diff () { test_must_fail git diff --no-index "$@" pre post > output && decrypt_color < output > output.decrypted && test_cmp expect output.decrypted } cat > pre <<\EOF h(4) a = b + c EOF cat > post <<\EOF h(4),hh[44] a = b + c aa = a aeff = aeff * ( aaa ) EOF cat > expect <<\EOF diff --git a/pre b/post index 330b04f..5ed8eff 100644 --- a/pre +++ b/post @@ -1,3 +1,7 @@ h(4)h(4),hh[44] a = b + c aa = a aeff = aeff * ( aaa ) EOF test_expect_success 'word diff with runs of whitespace' ' word_diff --color-words ' cat > expect <<\EOF diff --git a/pre b/post index 330b04f..5ed8eff 100644 --- a/pre +++ b/post @@ -1,3 +1,7 @@ h(4),hh[44] a = b + c aa = a aeff = aeff * ( aaa ) EOF test_expect_success 'word diff with a regular expression' ' word_diff --color-words="[a-z]+" ' test_expect_success 'set a diff driver' ' git config diff.testdriver.wordregex "[^[:space:]]" && cat < .gitattributes pre diff=testdriver post diff=testdriver EOF ' test_expect_success 'option overrides default' ' word_diff --color-words="[a-z]+" ' cat > expect <<\EOF diff --git a/pre b/post index 330b04f..5ed8eff 100644 --- a/pre +++ b/post @@ -1,3 +1,7 @@ h(4),hh[44] a = b + c aa = a aeff = aeff * ( aaa ) EOF test_expect_success 'use default supplied by driver' ' word_diff --color-words ' echo 'aaa (aaa)' > pre echo 'aaa (aaa) aaa' > post cat > expect <<\EOF diff --git a/pre b/post index c29453b..be22f37 100644 --- a/pre +++ b/post @@ -1 +1 @@ aaa (aaa) aaa EOF test_expect_success 'test parsing words for newline' ' word_diff --color-words="a+" ' echo '(:' > pre echo '(' > post cat > expect <<\EOF diff --git a/pre b/post index 289cb9d..2d06f37 100644 --- a/pre +++ b/post @@ -1 +1 @@ (: EOF test_expect_success 'test when words are only removed at the end' ' word_diff --color-words=. ' test_done