send-email: improve RFC2047 quote parsing
[git/jrn.git] / t / t4018-diff-funcname.sh
blob4bd2a1c838e9a522c4376860e726455d3cdb92b0
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='Test custom diff function name patterns'
8 . ./test-lib.sh
10 LF='
12 cat >Beer.java <<\EOF
13 public class Beer
15 int special;
16 public static void main(String args[])
18 String s=" ";
19 for(int x = 99; x > 0; x--)
21 System.out.print(x + " bottles of beer on the wall "
22 + x + " bottles of beer\n"
23 + "Take one down, pass it around, " + (x - 1)
24 + " bottles of beer on the wall.\n");
26 System.out.print("Go to the store, buy some more,\n"
27 + "99 bottles of beer on the wall.\n");
30 EOF
31 sed 's/beer\\/beer,\\/' <Beer.java >Beer-correct.java
32 cat >Beer.perl <<\EOT
33 package Beer;
35 use strict;
36 use warnings;
37 use parent qw(Exporter);
38 our @EXPORT_OK = qw(round finalround);
40 sub other; # forward declaration
42 # hello
44 sub round {
45 my ($n) = @_;
46 print "$n bottles of beer on the wall ";
47 print "$n bottles of beer\n";
48 print "Take one down, pass it around, ";
49 $n = $n - 1;
50 print "$n bottles of beer on the wall.\n";
53 sub finalround
55 print "Go to the store, buy some more\n";
56 print "99 bottles of beer on the wall.\n");
59 sub withheredocument {
60 print <<"EOF"
61 decoy here-doc
62 EOF
63 # some lines of context
64 # to pad it out
65 print "hello\n";
68 __END__
70 =head1 NAME
72 Beer - subroutine to output fragment of a drinking song
74 =head1 SYNOPSIS
76 use Beer qw(round finalround);
78 sub song {
79 for (my $i = 99; $i > 0; $i--) {
80 round $i;
82 finalround;
85 song;
87 =cut
88 EOT
89 sed -e '
90 s/hello/goodbye/
91 s/beer\\/beer,\\/
92 s/more\\/more,\\/
93 s/song;/song();/
94 ' <Beer.perl >Beer-correct.perl
96 test_config () {
97 git config "$1" "$2" &&
98 test_when_finished "git config --unset $1"
101 test_expect_funcname () {
102 lang=${2-java}
103 test_expect_code 1 git diff --no-index -U1 \
104 "Beer.$lang" "Beer-correct.$lang" >diff &&
105 grep "^@@.*@@ $1" diff
108 for p in bibtex cpp csharp fortran html java matlab objc pascal perl php python ruby tex
110 test_expect_success "builtin $p pattern compiles" '
111 echo "*.java diff=$p" >.gitattributes &&
112 test_expect_code 1 git diff --no-index \
113 Beer.java Beer-correct.java 2>msg &&
114 ! grep fatal msg &&
115 ! grep error msg
117 test_expect_success "builtin $p wordRegex pattern compiles" '
118 echo "*.java diff=$p" >.gitattributes &&
119 test_expect_code 1 git diff --no-index --word-diff \
120 Beer.java Beer-correct.java 2>msg &&
121 ! grep fatal msg &&
122 ! grep error msg
124 done
126 test_expect_success 'default behaviour' '
127 rm -f .gitattributes &&
128 test_expect_funcname "public class Beer\$"
131 test_expect_success 'set up .gitattributes declaring drivers to test' '
132 cat >.gitattributes <<-\EOF
133 *.java diff=java
134 *.perl diff=perl
138 test_expect_success 'preset java pattern' '
139 test_expect_funcname "public static void main("
142 test_expect_success 'preset perl pattern' '
143 test_expect_funcname "sub round {\$" perl
146 test_expect_success 'perl pattern accepts K&R style brace placement, too' '
147 test_expect_funcname "sub finalround\$" perl
150 test_expect_success 'but is not distracted by end of <<here document' '
151 test_expect_funcname "sub withheredocument {\$" perl
154 test_expect_success 'perl pattern is not distracted by sub within POD' '
155 test_expect_funcname "=head" perl
158 test_expect_success 'perl pattern gets full line of POD header' '
159 test_expect_funcname "=head1 SYNOPSIS\$" perl
162 test_expect_success 'perl pattern is not distracted by forward declaration' '
163 test_expect_funcname "package Beer;\$" perl
166 test_expect_success 'custom pattern' '
167 test_config diff.java.funcname "!static
168 !String
169 [^ ].*s.*" &&
170 test_expect_funcname "int special;\$"
173 test_expect_success 'last regexp must not be negated' '
174 test_config diff.java.funcname "!static" &&
175 test_expect_code 128 git diff --no-index Beer.java Beer-correct.java 2>msg &&
176 grep ": Last expression must not be negated:" msg
179 test_expect_success 'pattern which matches to end of line' '
180 test_config diff.java.funcname "Beer\$" &&
181 test_expect_funcname "Beer\$"
184 test_expect_success 'alternation in pattern' '
185 test_config diff.java.funcname "Beer$" &&
186 test_config diff.java.xfuncname "^[ ]*((public|static).*)$" &&
187 test_expect_funcname "public static void main("
190 test_done