Skip to content

Commit db2ba4d

Browse files
committed
Make expandrange able to output a single value
- Allow ranges with a unique value (as the range is already inclusive) - Make invalid step value a soft fail Changelog: Allow expandrange to output a single value
1 parent 0a2e3af commit db2ba4d

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

libpromises/evalfunction.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4558,9 +4558,10 @@ static FnCallResult FnCallExpandRange(EvalContext *ctx, ARG_UNUSED const Policy
45584558
sscanf(template, "%[^[\[][%d-%d]%[^\n]", before, &from, &to, after);
45594559
}
45604560

4561-
if (step_size < 1 || abs(from-to) < step_size)
4561+
if (step_size < 1)
45624562
{
4563-
FatalError(ctx, "EXPANDRANGE Step size cannot be less than 1 or greater than the interval");
4563+
Log(LOG_LEVEL_ERR, "%s: Step size cannot be less than 1", fp->name);
4564+
return FnFailure();
45644565
}
45654566

45664567
if (from == CF_NOINT || to == CF_NOINT)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# data_regextract() test
2+
3+
body common control
4+
{
5+
inputs => { "../../default.cf.sub" };
6+
bundlesequence => { default("$(this.promise_filename)") };
7+
}
8+
9+
bundle agent test
10+
{
11+
vars:
12+
"case1" slist => expandrange("case1[1-3]", 1);
13+
"case1s" string => format("%S", "case1");
14+
"case2" slist => expandrange("case2[1-10]", 3);
15+
"case2s" string => format("%S", "case2");
16+
"case3" slist => expandrange("case3[1-1]", 3);
17+
"case3s" string => format("%S", "case3");
18+
"case4" slist => expandrange("case4[1-2]", 3);
19+
"case4s" string => format("%S", "case4");
20+
}
21+
22+
bundle agent check
23+
{
24+
vars:
25+
"actual" string => "
26+
1 $(test.case1s)
27+
2 $(test.case2s)
28+
3 $(test.case3s)
29+
4 $(test.case4s)
30+
";
31+
32+
"expected" string => '
33+
1 { \"case11\", \"case12\", \"case13\" }
34+
2 { \"case21\", \"case24\", \"case27\", \"case210\" }
35+
3 { \"case31\" }
36+
4 { \"case41\" }
37+
';
38+
39+
methods:
40+
"" usebundle => dcs_check_strcmp($(actual), $(expected),
41+
$(this.promise_filename),
42+
"no");
43+
}

0 commit comments

Comments
 (0)