Skip to content

Commit 48746ab

Browse files
authored
Merge pull request #5719 from btriller/CFE-2930
getindices() now returns positional index from a list
2 parents 5d5d8ab + 565538c commit 48746ab

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

libpromises/evalfunction.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3121,7 +3121,7 @@ static FnCallResult FnCallGetIndices(EvalContext *ctx, ARG_UNUSED const Policy *
31213121
EvalContextVariableGet(ctx, ref, &type);
31223122

31233123
/* A variable holding a data container. */
3124-
if (type == CF_DATA_TYPE_CONTAINER)
3124+
if (DataTypeToRvalType(type) == RVAL_TYPE_CONTAINER || DataTypeToRvalType(type) == RVAL_TYPE_LIST)
31253125
{
31263126
json = VarRefValueToJson(ctx, fp, ref, NULL, 0, true, &allocated);
31273127
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
body common control
2+
{
3+
inputs => { "../../default.cf.sub" };
4+
bundlesequence => { default("$(this.promise_filename)") };
5+
version => "1.0";
6+
}
7+
8+
#######################################################
9+
10+
bundle agent test
11+
{
12+
13+
meta:
14+
"description" -> { "CFE-2930" }
15+
string => "Test that getindices() returns the correct indices from a list";
16+
17+
vars:
18+
"list" slist => { "beta", "alpha", "gamma" };
19+
"getindices_list" slist => getindices( list );
20+
}
21+
22+
#######################################################
23+
bundle agent check
24+
{
25+
vars:
26+
"expected_value" string => "beta";
27+
"first_index" string => nth( "test.getindices_list", 0 );
28+
29+
reports:
30+
"$(this.promise_filename) Pass"
31+
if => and( strcmp( $(first_index), 0 ), strcmp( nth( "test.list", $(first_index) ), $(expected_value) ) );
32+
33+
"$(this.promise_filename) FAIL"
34+
unless => and( strcmp( $(first_index), 0 ), strcmp( nth( "test.list", $(first_index) ), $(expected_value) ) );
35+
}

tests/acceptance/02_classes/02_functions/getindices_returns_positonal_indices_from_list.cf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ bundle agent test
1414
"description" -> { "CFE-2930" }
1515
string => "Test that getindices() returns the positional indices from a list";
1616

17-
"test_soft_fail"
18-
string => "any",
19-
meta => { "CFE-2930" };
20-
2117
vars:
2218
"list" slist => { "beta", "alpha", "gamma" };
2319
"getindices_list" slist => getindices( list );

0 commit comments

Comments
 (0)