1#!/bin/sh
2# Test --{hex,numeric}-suffixes[=from]
3
4# Copyright (C) 2012-2018 Free Software Foundation, Inc.
5
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ split
21
22printf '1\n2\n3\n4\n5\n' > in || framework_failure_
23
24printf '%s\n' 1 2 > exp-0 || framework_failure_
25printf '%s\n' 3 4 > exp-1 || framework_failure_
26printf '%s\n' 5   > exp-2 || framework_failure_
27
28for mode in 'numeric' 'hex'; do
29
30  for start in 0 9; do
31    mode_option="--$mode-suffixes"
32    # check with and without specified start value
33    test $start != '0' && mode_option="$mode_option=$start"
34    split $mode_option --lines=2 in || fail=1
35
36    test $mode = 'hex' && format=x || format=d
37    for i in $(seq $start $(($start+2))); do
38      compare exp-$(($i-$start)) x$(printf %02$format $i) || fail=1
39    done
40  done
41
42  # Check that split failed when suffix length is not large enough for
43  # the numerical suffix start value
44  returns_ 1 split -a 3 --$mode-suffixes=1000 in 2>/dev/null || fail=1
45
46  # check invalid --$mode-suffixes start values are flagged
47  returns_ 1 split --$mode-suffixes=-1 in 2> /dev/null || fail=1
48  returns_ 1 split --$mode-suffixes=one in 2> /dev/null || fail=1
49done
50
51Exit $fail
52