Skip to content

Commit

Permalink
fix: accept string as first arg of first() too
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Apr 5, 2019
1 parent 14e41a5 commit 619e053
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const functions = {
},

first: {
arguments: ["object|number|undefined"],
arguments: ["string|object|number|undefined"],
returns: "object?",
apply: (context, args) => {
args = args.filter(e => e !== undefined && e.value !== undefined);
Expand Down
5 changes: 3 additions & 2 deletions tests/basics-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ test("wrong argument type", async t =>
test("length (string)", async t => t.is(await expand("${length('abc')}"), 3));
test("length (array)", async t => t.is(await expand("${length([1,2,3])}"), 3));

test("first", async t => t.is(await expand("${first(1,2,3)}"), 1));
test.only("first missing", async t => t.is(await expand("${first(env.MISSING,'b')}"), 'b'));
test("first number", async t => t.is(await expand("${first(1,2,3)}"), 1));
test("first string", async t => t.is(await expand("${first('a','b')}"), 'a'));
test("first missing", async t => t.is(await expand("${first(env.MISSING,'b')}"), 'b'));

test("split", async t =>
t.deepEqual(await expand("${split('1,2,3,4',',')}"), ["1", "2", "3", "4"]));
Expand Down

0 comments on commit 619e053

Please sign in to comment.