| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='grep icase on non-English locales' |
| 4 | |
| 5 | . ./lib-gettext.sh |
| 6 | |
| 7 | doalarm () { |
| 8 | perl -e 'alarm shift; exec @ARGV' -- "$@" |
| 9 | } |
| 10 | |
| 11 | test_expect_success GETTEXT_LOCALE 'setup' ' |
| 12 | test_write_lines "TILRAUN: Halló Heimur!" >file && |
| 13 | git add file && |
| 14 | LC_ALL="$is_IS_locale" && |
| 15 | export LC_ALL |
| 16 | ' |
| 17 | |
| 18 | test_expect_success GETTEXT_LOCALE 'setup REGEX_LOCALE prerequisite' ' |
| 19 | # This "test-tool" invocation is identical... |
| 20 | if test-tool regex "HALLÓ" "Halló" ICASE |
| 21 | then |
| 22 | test_set_prereq REGEX_LOCALE |
| 23 | else |
| 24 | |
| 25 | # ... to this one, but this way "test_must_fail" will |
| 26 | # tell a segfault or abort() from the regexec() test |
| 27 | # itself |
| 28 | test_must_fail test-tool regex "HALLÓ" "Halló" ICASE |
| 29 | fi |
| 30 | ' |
| 31 | |
| 32 | test_expect_success REGEX_LOCALE 'grep literal string, no -F' ' |
| 33 | git grep -i "TILRAUN: Halló Heimur!" && |
| 34 | git grep -i "TILRAUN: HALLÓ HEIMUR!" |
| 35 | ' |
| 36 | |
| 37 | test_expect_success GETTEXT_LOCALE,PCRE 'grep pcre utf-8 icase' ' |
| 38 | git grep --perl-regexp "TILRAUN: H.lló Heimur!" && |
| 39 | git grep --perl-regexp -i "TILRAUN: H.lló Heimur!" && |
| 40 | git grep --perl-regexp -i "TILRAUN: H.LLÓ HEIMUR!" |
| 41 | ' |
| 42 | |
| 43 | test_expect_success GETTEXT_LOCALE,PCRE 'grep pcre utf-8 string with "+"' ' |
| 44 | test_write_lines "TILRAUN: Hallóó Heimur!" >file2 && |
| 45 | git add file2 && |
| 46 | git grep -l --perl-regexp "TILRAUN: H.lló+ Heimur!" >actual && |
| 47 | echo file >expected && |
| 48 | echo file2 >>expected && |
| 49 | test_cmp expected actual |
| 50 | ' |
| 51 | |
| 52 | test_expect_success REGEX_LOCALE 'grep literal string, with -F' ' |
| 53 | git grep -i -F "TILRAUN: Halló Heimur!" && |
| 54 | git grep -i -F "TILRAUN: HALLÓ HEIMUR!" |
| 55 | ' |
| 56 | |
| 57 | test_expect_success REGEX_LOCALE 'grep string with regex, with -F' ' |
| 58 | test_write_lines "TILRAUN: Halló Heimur [abc]!" >file3 && |
| 59 | git add file3 && |
| 60 | git grep -i -F "TILRAUN: Halló Heimur [abc]!" file3 |
| 61 | ' |
| 62 | |
| 63 | test_expect_success REGEX_LOCALE 'pickaxe -i on non-ascii' ' |
| 64 | git commit -m first && |
| 65 | git log --format=%f -i -S"TILRAUN: HALLÓ HEIMUR!" >actual && |
| 66 | echo first >expected && |
| 67 | test_cmp expected actual |
| 68 | ' |
| 69 | |
| 70 | test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: setup invalid UTF-8 data' ' |
| 71 | printf "\\200\\n" >invalid-0x80 && |
| 72 | echo "ævar" >expected && |
| 73 | cat expected >>invalid-0x80 && |
| 74 | git add invalid-0x80 && |
| 75 | |
| 76 | # Test for PCRE2_MATCH_INVALID_UTF bug |
| 77 | # https://bugs.exim.org/show_bug.cgi?id=2642 |
| 78 | printf "\\345Aæ\\n" >invalid-0xe5 && |
| 79 | git add invalid-0xe5 |
| 80 | ' |
| 81 | |
| 82 | test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep ASCII from invalid UTF-8 data' ' |
| 83 | git grep -h "var" invalid-0x80 >actual && |
| 84 | test_cmp expected actual && |
| 85 | git grep -h "(*NO_JIT)var" invalid-0x80 >actual && |
| 86 | test_cmp expected actual |
| 87 | ' |
| 88 | |
| 89 | test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep ASCII from invalid UTF-8 data (PCRE2 bug #2642)' ' |
| 90 | git grep -h "Aæ" invalid-0xe5 >actual && |
| 91 | test_cmp invalid-0xe5 actual && |
| 92 | git grep -h "(*NO_JIT)Aæ" invalid-0xe5 >actual && |
| 93 | test_cmp invalid-0xe5 actual |
| 94 | ' |
| 95 | |
| 96 | test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-ASCII from invalid UTF-8 data' ' |
| 97 | git grep -h "æ" invalid-0x80 >actual && |
| 98 | test_cmp expected actual && |
| 99 | git grep -h "(*NO_JIT)æ" invalid-0x80 >actual && |
| 100 | test_cmp expected actual |
| 101 | ' |
| 102 | |
| 103 | test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-ASCII from invalid UTF-8 data (PCRE2 bug #2642)' ' |
| 104 | git grep -h "Aæ" invalid-0xe5 >actual && |
| 105 | test_cmp invalid-0xe5 actual && |
| 106 | git grep -h "(*NO_JIT)Aæ" invalid-0xe5 >actual && |
| 107 | test_cmp invalid-0xe5 actual |
| 108 | ' |
| 109 | |
| 110 | test_lazy_prereq PCRE2_MATCH_INVALID_UTF ' |
| 111 | test-tool pcre2-config has-PCRE2_MATCH_INVALID_UTF |
| 112 | ' |
| 113 | |
| 114 | test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-ASCII from invalid UTF-8 data with -i' ' |
| 115 | test_might_fail git grep -hi "Æ" invalid-0x80 >actual && |
| 116 | test_might_fail git grep -hi "(*NO_JIT)Æ" invalid-0x80 >actual |
| 117 | ' |
| 118 | |
| 119 | test_expect_success GETTEXT_LOCALE,LIBPCRE2,PCRE2_MATCH_INVALID_UTF 'PCRE v2: grep non-ASCII from invalid UTF-8 data with -i' ' |
| 120 | git grep -hi "Æ" invalid-0x80 >actual && |
| 121 | test_cmp expected actual && |
| 122 | git grep -hi "(*NO_JIT)Æ" invalid-0x80 >actual && |
| 123 | test_cmp expected actual |
| 124 | ' |
| 125 | |
| 126 | test_expect_success GETTEXT_LOCALE,LIBPCRE2,PCRE2_MATCH_INVALID_UTF 'PCRE v2: grep non-ASCII from invalid UTF-8 data with -i (PCRE2 bug #2642)' ' |
| 127 | git grep -hi "Æ" invalid-0xe5 >actual && |
| 128 | test_cmp invalid-0xe5 actual && |
| 129 | git grep -hi "(*NO_JIT)Æ" invalid-0xe5 >actual && |
| 130 | test_cmp invalid-0xe5 actual && |
| 131 | |
| 132 | # Only the case of grepping the ASCII part in a way that |
| 133 | # relies on -i fails |
| 134 | git grep -hi "aÆ" invalid-0xe5 >actual && |
| 135 | test_cmp invalid-0xe5 actual && |
| 136 | git grep -hi "(*NO_JIT)aÆ" invalid-0xe5 >actual && |
| 137 | test_cmp invalid-0xe5 actual |
| 138 | ' |
| 139 | |
| 140 | test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-literal ASCII from UTF-8' ' |
| 141 | git grep --perl-regexp -h -o -e ll. file >actual && |
| 142 | echo "lló" >expected && |
| 143 | test_cmp expected actual |
| 144 | ' |
| 145 | |
| 146 | test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep avoid endless loop bug' ' |
| 147 | echo " Halló" >leading-whitespace && |
| 148 | git add leading-whitespace && |
| 149 | doalarm 1 git grep --perl-regexp "^\s" leading-whitespace |
| 150 | ' |
| 151 | |
| 152 | test_done |