Several tests for regex-configured word splits via command line and gitattributes. For good measure we also do a basic test of the default --color-words since it was so far not covered at all. Signed-off-by: Thomas Rast <trast@xxxxxxxxxxxxxxx> --- t/t4033-diff-color-words.sh | 90 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 90 insertions(+), 0 deletions(-) create mode 100755 t/t4033-diff-color-words.sh diff --git a/t/t4033-diff-color-words.sh b/t/t4033-diff-color-words.sh new file mode 100755 index 0000000..536cdac --- /dev/null +++ b/t/t4033-diff-color-words.sh @@ -0,0 +1,90 @@ +#!/bin/sh + + +test_description='diff --color-words' +. ./test-lib.sh + +cat <<EOF > test_a +foo_bar_baz +a qu_ux b c +alpha beta gamma delta +EOF + +cat <<EOF > test_b +foo_baz_baz +a qu_new_ux b c +alpha 4 2 delta +EOF + +# t4026-diff-color.sh tests the color escapes, so we assume they do +# not change + +munge () { + tail -n +5 | tr '\033' '!' +} + +cat <<EOF > expect-plain +![36m@@ -1,3 +1,3 @@![m +![31mfoo_bar_baz![m![32mfoo_baz_baz![m +a ![m![31mqu_ux ![m![32mqu_new_ux ![mb ![mc![m +alpha ![m![31mbeta ![m![31mgamma ![m![32m4 ![m![32m2 ![mdelta![m +EOF + +test_expect_success 'default settings' ' + git diff --no-index --color-words test_a test_b | + munge > actual-plain && + test_cmp expect-plain actual-plain +' + +test_expect_success 'trivial regex yields same as default' ' + git diff --no-index --color-words="\\S+" test_a test_b | + munge > actual-trivial && + test_cmp expect-plain actual-trivial +' + +cat <<EOF > expect-chars +![36m@@ -1,3 +1,3 @@![m +f![mo![mo![m_![mb![ma![m![31mr![m![32mz![m_![mb![ma![mz![m +a ![mq![mu![m_![m![32mn![m![32me![m![32mw![m![32m_![mu![mx ![mb ![mc![m +a![ml![mp![mh![ma ![m![31mb![m![31me![m![31mt![m![31ma ![m![31mg![m![31ma![m![31mm![m![31mm![m![31ma ![m![32m4 ![m![32m2 ![md![me![ml![mt![ma![m +EOF + +test_expect_success 'character by character regex' ' + git diff --no-index --color-words="\\S" test_a test_b | + munge > actual-chars && + test_cmp expect-chars actual-chars +' + +cat <<EOF > expect-nontrivial +![36m@@ -1,3 +1,3 @@![m +foo![m_![m![31mbar![m![32mbaz![m_![mbaz![m +a ![mqu![m_![m![32mnew![m![32m_![mux ![mb ![mc![m +alpha ![m![31mbeta ![m![31mgamma ![m![32m4![m![32m ![m![32m2![m![32m ![mdelta![m +EOF + +test_expect_success 'nontrivial regex' ' + git diff --no-index --color-words="[a-z]+|_" test_a test_b | + munge > actual-nontrivial && + test_cmp expect-nontrivial actual-nontrivial +' + +test_expect_success 'set a diff driver' ' + git config diff.testdriver.wordregex "\\S" && + cat <<EOF > .gitattributes +test_* diff=testdriver +EOF +' + +test_expect_success 'use default supplied by driver' ' + git diff --no-index --color-words test_a test_b | + munge > actual-chars-2 && + test_cmp expect-chars actual-chars-2 +' + +test_expect_success 'option overrides default' ' + git diff --no-index --color-words="[a-z]+|_" test_a test_b | + munge > actual-nontrivial-2 && + test_cmp expect-nontrivial actual-nontrivial-2 +' + +test_done -- 1.6.1.269.g0769 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html