From 619e053918ed4e5687ffc331570e27c89431b051 Mon Sep 17 00:00:00 2001 From: Markus Felten Date: Fri, 5 Apr 2019 21:26:26 +0200 Subject: [PATCH] fix: accept string as first arg of first() too --- src/functions.mjs | 2 +- tests/basics-test.mjs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/functions.mjs b/src/functions.mjs index 51e8fb2d..fc980147 100644 --- a/src/functions.mjs +++ b/src/functions.mjs @@ -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); diff --git a/tests/basics-test.mjs b/tests/basics-test.mjs index 0b89c0ad..36161033 100644 --- a/tests/basics-test.mjs +++ b/tests/basics-test.mjs @@ -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"]));