#!/bin/sh
# test that matches starting in the middle of a multibyte char aren't rejected
# too greedily.
# Derived from https://savannah.gnu.org/bugs/?23814
. "${srcdir=.}/init.sh"; path_prepend_ ../src

# Add "." to PATH for the use of get-mb-cur-max.
path_prepend_ .

locale=ja_JP.EUC-JP

make_input () {
  echo "$1" | tr AB '\244\263'
}

euc_grep () {
  pat=$(make_input "$1")
  LC_ALL=$locale grep "$pat"
}

case $(get-mb-cur-max $locale) in
  2|3) ;;
  *) skip_test_ 'EUC-JP locale not found' ;;
esac

fail=0

# Does EUC-JP work at all?
make_input BABA |euc_grep AB && fail=1

# Whole line rejected after matching in the middle of a multibyte char?
make_input BABAAB |euc_grep AB || fail=1

Exit $fail
