Subject: Re: [PATCH v15 05/13] ref-filter: implement an `align` atom

From: Matthieu Moy <[email-masked]>
Date: Wed, 02 Sep 2015 10:41:30 +0200

Karthik Nayak <[email-masked]> writes:

> +test_expect_success 'alignment with format quote' '
> +	cat >expect <<-EOF &&
> +	refname is ${sq}           ${sq}\\${sq}${sq}master${sq}\\${sq}${sq}           ${sq}|
> +	refname is ${sq}            ${sq}\\${sq}${sq}side${sq}\\${sq}${sq}            ${sq}|
> +	refname is ${sq}          ${sq}\\${sq}${sq}odd/spot${sq}\\${sq}${sq}          ${sq}|
> +	refname is ${sq}         ${sq}\\${sq}${sq}double-tag${sq}\\${sq}${sq}         ${sq}|
> +	refname is ${sq}            ${sq}\\${sq}${sq}four${sq}\\${sq}${sq}            ${sq}|
> +	refname is ${sq}            ${sq}\\${sq}${sq}one${sq}\\${sq}${sq}             ${sq}|
> +	refname is ${sq}         ${sq}\\${sq}${sq}signed-tag${sq}\\${sq}${sq}         ${sq}|
> +	refname is ${sq}           ${sq}\\${sq}${sq}three${sq}\\${sq}${sq}            ${sq}|
> +	refname is ${sq}            ${sq}\\${sq}${sq}two${sq}\\${sq}${sq}             ${sq}|
> +	EOF
> +	git for-each-ref --shell --format="refname is %(align:30,middle)${sq}%(refname:short)${sq}%(end)|" >actual &&
> +	test_cmp expect actual
> +'

Someone (Eric IIRC) suggested using double-quotes around the last
argument of test_expect_success. Even though I'm the one who suggested
this ${sq}, I have to agree with this suggestion. The result looks like

test_expect_success 'alignment with quote' "
	cat >expect <<-\EOF &&
	refname is '               '\\'''master'\\''
	...
"

Because you used "" at the toplevel, ' is not a special character
anymore. You do have to be careful with \\ though, but adding before EOF
as I did should do the trick. Untested.

You don't have test for nested alignment with quotes. I think it
deserves to be tested, if only to cast in stone that the current
behavior is your intention.

Perhaps just adding --shell to the test below would be OK to avoid the
proliferation of tests :

> +test_expect_success 'nested alignment' '
> +	cat >expect <<-\EOF &&
> +	|         master               |
> +	|           side               |
> +	|       odd/spot               |
> +	|     double-tag               |
> +	|           four               |
> +	|            one               |
> +	|     signed-tag               |
> +	|          three               |
> +	|            two               |
> +	EOF
> +	git for-each-ref --format="|%(align:30,left)%(align:15,right)%(refname:short)%(end)%(end)|" >actual &&
> +	test_cmp expect actual
> +'
> +
>  test_done

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/