aboutsummaryrefslogtreecommitdiffstats
path: root/t/100-increment-decrement.t
blob: 4b7d1a717de5fd160558082fe440edbb76fa4289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/usr/bin/env perl -w

# Copyright (c) 2021  Teddy Wing
#
# This file is part of Incdec.
#
# Incdec is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Incdec is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Incdec. If not, see <https://www.gnu.org/licenses/>.


use strict;

use Test::More;

use lib './';
use incdec;

my @want;
my @got;

@want = incdec::incdec('test 12', 1);
@got = ('test 13', 5);
is_deeply(
	\@want,
	\@got,
	'increments an integer'
);

@want = incdec::incdec('test 12 0', 1);
@got = ('test 13 0', 5);
is_deeply(
	\@want,
	\@got,
	'increments the first integer'
);

@want = incdec::incdec('test 12 0', 1, 6);
@got = ('test 13 0', 5);
is_deeply(
	\@want,
	\@got,
	'increments the first integer with point at position 6'
);

@want = incdec::incdec('test 19 0', 1, 6);
@got = ('test 20 0', 5);
is_deeply(
	\@want,
	\@got,
	'increments the first integer with point at position 6'
);

@want = incdec::incdec('test 12 0', 1, 7);
@got = ('test 12 1', 8);
is_deeply(
	\@want,
	\@got,
	'increments the second integer with point at position 7'
);

@want = incdec::incdec('test 12 19 555', 1, 9);
@got = ('test 12 20 555', 8);
is_deeply(
	\@want,
	\@got,
	'increments the second double-digit integer with point at position 9'
);

@want = incdec::incdec('test 12 19 555', 1, 12);
@got = ('test 12 19 556', 11);
is_deeply(
	\@want,
	\@got,
	'increments the third triple-digit integer with point at position 12'
);

@want = incdec::incdec('test 12 19 555', 7, 9);
@got = ('test 12 26 555', 8);
is_deeply(
	\@want,
	\@got,
	'increments the second double-digit integer by 7 with point at position 9'
);

@want = incdec::incdec('test 12 19 555 64', 1, 16);
@got = ('test 12 19 555 65', 15);
is_deeply(
	\@want,
	\@got,
	'increments the fourth double-digit integer with point at position 16'
);

@want = incdec::incdec('test 12 19 555 64', 1, 17, 1);
@got = ('test 12 19 555 65', 15);
is_deeply(
	\@want,
	\@got,
	'increments the fourth double-digit integer with point at position 17 backward'
);

@want = incdec::incdec('test 12 19 555 64', 1, 13, 1);
@got = ('test 12 19 556 64', 11);
is_deeply(
	\@want,
	\@got,
	'increments the third triple-digit integer with point at position 13 backward'
);

@want = incdec::incdec('test 12 19 555 64', 1, 14, 1);
@got = ('test 12 19 556 64', 11);
is_deeply(
	\@want,
	\@got,
	'increments the third triple-digit integer with point at position 14 backward'
);

@want = incdec::incdec('test 12 982 4 ', 1, 14, 1);
@got = ('test 12 982 5 ', 12);
is_deeply(
	\@want,
	\@got,
	'increments the third integer with point at position 14 backward'
);

@want = incdec::incdec('test -1 ', 1, 7, 1);
@got = ('test 0 ', 5);
is_deeply(
	\@want,
	\@got,
	'increments the negative integer with point at position 7 backward'
);

@want = incdec::incdec('test -1 ', -1, 7, 1);
@got = ('test -2 ', 5);
is_deeply(
	\@want,
	\@got,
	'decrements the negative integer with point at position 7 backward'
);

@want = incdec::incdec('test 1 -2', 1, 8, 1);
@got = ('test 1 -1', 7);
is_deeply(
	\@want,
	\@got,
	'increments the second negative integer with point at position 8 backward'
);

@want = incdec::incdec('test 1 -2', -1, 8, 1);
@got = ('test 1 -3', 7);
is_deeply(
	\@want,
	\@got,
	'decrements the second negative integer with point at position 8 backward'
);

@want = incdec::incdec('test 12', -1);
@got = ('test 11', 5);
is_deeply(
	\@want,
	\@got,
	'decrements the first integer'
);

@want = incdec::incdec('test 12', -1, 7, 1);
@got = ('test 11', 5);
is_deeply(
	\@want,
	\@got,
	'decrements the first integer with point at position 7 backward'
);

@want = incdec::incdec('test 12 982 4', -1, 11, 1);
@got = ('test 12 981 4', 8);
is_deeply(
	\@want,
	\@got,
	'decrements the second integer with point at position 11 backward'
);

@want = incdec::incdec('test 12 982 4', -1, 9, 1);
@got = ('test 12 981 4', 8);
is_deeply(
	\@want,
	\@got,
	'decrements the second integer with point at position 9 backward'
);

@want = incdec::incdec('test 12 982 4', -5, 8, 1);
@got = ('test 12 977 4', 8);
is_deeply(
	\@want,
	\@got,
	'decrements the second integer by 5 with point at position 8 backward'
);

@want = incdec::incdec('test 12 1 4', -2, 9, 1);
@got = ('test 12 -1 4', 8);
is_deeply(
	\@want,
	\@got,
	'decrements the second integer by 2 with point at position 9 backward'
);

@want = incdec::incdec("sed -n '39,54p' Alice\'s\ Adventures\ in\ Wonderland.txt ", 1, 3, 1);
@got = ("sed -n '40,54p' Alice\'s\ Adventures\ in\ Wonderland.txt ", 0);
is_deeply(
	\@want,
	\@got,
	'increments the first integer with point at position 3 backward'
);

@want = incdec::incdec("sed -n '39,54p' Alice\'s\ Adventures\ in\ Wonderland.txt ", 1, 8, 1);
@got = ("sed -n '40,54p' Alice\'s\ Adventures\ in\ Wonderland.txt ", 8);
is_deeply(
	\@want,
	\@got,
	'increments the first integer with point at position 8 backward'
);

@want = incdec::incdec("sed -n '39,54p' Alice\'s\ Adventures\ in\ Wonderland.txt ", -1, 10, 1);
@got = ("sed -n '38,54p' Alice\'s\ Adventures\ in\ Wonderland.txt ", 8);
is_deeply(
	\@want,
	\@got,
	'decrements the first integer with point at position 10 backward'
);

@want = incdec::incdec("sed -n '39,54p' Alice\'s\ Adventures\ in\ Wonderland.txt ", 1, 3, 0);
@got = ("sed -n '40,54p' Alice\'s\ Adventures\ in\ Wonderland.txt ", 8);
is_deeply(
	\@want,
	\@got,
	'increments the first integer with point at position 3'
);

done_testing;