diff --git a/.mapping.json b/.mapping.json index 12b431428..c2a5e9121 100644 --- a/.mapping.json +++ b/.mapping.json @@ -15057,6 +15057,7 @@ "site/server/src/redis.js":"divkit/public/site/server/src/redis.js", "site/server/src/runTs.js":"divkit/public/site/server/src/runTs.js", "site/server/src/runTsWorker.js":"divkit/public/site/server/src/runTsWorker.js", + "test_data/expression_test_data/function_signatures_array.json":"divkit/public/test_data/expression_test_data/function_signatures_array.json", "test_data/expression_test_data/function_signatures_color.json":"divkit/public/test_data/expression_test_data/function_signatures_color.json", "test_data/expression_test_data/function_signatures_datetime.json":"divkit/public/test_data/expression_test_data/function_signatures_datetime.json", "test_data/expression_test_data/function_signatures_interval.json":"divkit/public/test_data/expression_test_data/function_signatures_interval.json", diff --git a/client/web/divkit/src/expressions/funcs/array.ts b/client/web/divkit/src/expressions/funcs/array.ts index 6d026a2ae..1ac8e58f1 100644 --- a/client/web/divkit/src/expressions/funcs/array.ts +++ b/client/web/divkit/src/expressions/funcs/array.ts @@ -1,4 +1,5 @@ -import { ARRAY, BOOLEAN, COLOR, INTEGER, NUMBER, STRING, URL } from '../const'; +import { toBigInt } from '../bigint'; +import { ARRAY, BOOLEAN, COLOR, DICT, INTEGER, NUMBER, STRING, URL } from '../const'; import type { ArrayValue, BooleanValue, ColorValue, EvalContext, EvalTypes, EvalValue, IntegerValue, NumberValue, StringValue, UrlValue } from '../eval'; import { checkIntegerOverflow, transformColorValue } from '../utils'; import { registerFunc } from './funcs'; @@ -88,7 +89,7 @@ function getArrayOptArray(ctx: EvalContext, array: ArrayValue, index: IntegerVal } catch (_err) { // ignore error return { - type: 'array', + type: ARRAY, value: [] } as unknown as EvalValue; } @@ -100,12 +101,19 @@ function getArrayOptDict(ctx: EvalContext, array: ArrayValue, index: IntegerValu } catch (_err) { // ignore error return { - type: 'dict', + type: DICT, value: {} } as unknown as EvalValue; } } +function len(_ctx: EvalContext, array: ArrayValue): EvalValue { + return { + type: INTEGER, + value: toBigInt(array.value.length) + }; +} + export function registerArray(): void { registerFunc('getArrayString', [ ARRAY, @@ -266,4 +274,8 @@ export function registerArray(): void { ARRAY, INTEGER ], getArrayOptDict); + + registerFunc('len', [ + ARRAY + ], len); } diff --git a/test_data/expression_test_data/function_signatures_array.json b/test_data/expression_test_data/function_signatures_array.json new file mode 100644 index 000000000..382afb53c --- /dev/null +++ b/test_data/expression_test_data/function_signatures_array.json @@ -0,0 +1,736 @@ +{ + "signatures": [ + { + "name": "getArrayString(array, integer) string", + "function_name": "getArrayString", + "doc": "Returns a string value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "string", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayNumber(array, integer) number", + "function_name": "getArrayNumber", + "doc": "Returns a number value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "number", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayInteger(array, integer) integer", + "function_name": "getArrayInteger", + "doc": "Returns an integer value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "integer", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayBoolean(array, integer) boolean", + "function_name": "getArrayBoolean", + "doc": "Returns a boolean property from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "boolean", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayColor(array, integer) color", + "function_name": "getArrayColor", + "doc": "Returns a color property from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "color", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayOptString(array, integer, string) string", + "function_name": "getArrayOptString", + "doc": "Returns an optional string property from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "string", + "doc": "Fallback value if value by index not exists or it's is not a string." + } + ], + "result_type": "string", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayOptNumber(array, integer, number) number", + "function_name": "getArrayOptNumber", + "doc": "Returns an optional number property from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "number", + "doc": "Fallback value if value by index not exists or it's is not a number." + } + ], + "result_type": "number", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayOptInteger(array, integer, integer) integer", + "function_name": "getArrayOptInteger", + "doc": "Returns an optional integer property from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "integer", + "doc": "Fallback value if property does not exist or a property value is not an integer." + } + ], + "result_type": "integer", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayOptBoolean(array, integer, boolean) boolean", + "function_name": "getArrayOptBoolean", + "doc": "Returns an optional boolean value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "boolean", + "doc": "Fallback value if value by index not exists or it's is not a boolean." + } + ], + "result_type": "boolean", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayOptColor(array, integer, color) color", + "function_name": "getArrayOptColor", + "doc": "Returns an optional color value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "color", + "doc": "Fallback value if value by index not exists or it's is not a color." + } + ], + "result_type": "color", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayOptColor(array, integer, string) color", + "function_name": "getArrayOptColor", + "doc": "Returns an optional color value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "string", + "doc": "Fallback value if value by index not exists or it's is not a color." + } + ], + "result_type": "color", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayUrl(array, integer) url", + "function_name": "getArrayUrl", + "doc": "Returns an url value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "url", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getArrayOptUrl(array, integer, url) url", + "function_name": "getArrayOptUrl", + "doc": "Returns an optional url value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "url", + "doc": "Fallback value if value by index not exists or it's is not a url." + } + ], + "result_type": "url", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getArrayOptUrl(array, integer, string) url", + "function_name": "getArrayOptUrl", + "doc": "Returns an optional url value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "string", + "doc": "Fallback value if value by index not exists or it's is not a url." + } + ], + "result_type": "url", + "platforms": [ + "android", + "ios", + "web" + ] + }, + { + "name": "getStringFromArray(array, integer) string", + "function_name": "getStringFromArray", + "doc": "Returns a string value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "string", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getNumberFromArray(array, integer) number", + "function_name": "getNumberFromArray", + "doc": "Returns a number value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "number", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getIntegerFromArray(array, integer) integer", + "function_name": "getIntegerFromArray", + "doc": "Returns an integer value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "integer", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getBooleanFromArray(array, integer) boolean", + "function_name": "getBooleanFromArray", + "doc": "Returns a boolean property from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "boolean", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getColorFromArray(array, integer) color", + "function_name": "getColorFromArray", + "doc": "Returns a color property from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "color", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getOptStringFromArray(array, integer, string) string", + "function_name": "getOptStringFromArray", + "doc": "Returns an optional string property from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "string", + "doc": "Fallback value if value by index not exists or it's is not a string." + } + ], + "result_type": "string", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getOptNumberFromArray(array, integer, number) number", + "function_name": "getOptNumberFromArray", + "doc": "Returns an optional number property from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "number", + "doc": "Fallback value if value by index not exists or it's is not a number." + } + ], + "result_type": "number", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getOptIntegerFromArray(array, integer, integer) integer", + "function_name": "getOptIntegerFromArray", + "doc": "Returns an optional integer property from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "integer", + "doc": "Fallback value if property does not exist or a property value is not an integer." + } + ], + "result_type": "integer", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getOptBooleanFromArray(array, integer, boolean) boolean", + "function_name": "getOptBooleanFromArray", + "doc": "Returns an optional boolean value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "boolean", + "doc": "Fallback value if value by index not exists or it's is not a boolean." + } + ], + "result_type": "boolean", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getOptColorFromArray(array, integer, color) color", + "function_name": "getOptColorFromArray", + "doc": "Returns an optional color value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "color", + "doc": "Fallback value if value by index not exists or it's is not a color." + } + ], + "result_type": "color", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getOptColorFromArray(array, integer, string) color", + "function_name": "getOptColorFromArray", + "doc": "Returns an optional color value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "string", + "doc": "Fallback value if value by index not exists or it's is not a color." + } + ], + "result_type": "color", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getUrlFromArray(array, integer) url", + "function_name": "getUrlFromArray", + "doc": "Returns an url value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "url", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getOptUrlFromArray(array, integer, url) url", + "function_name": "getOptUrlFromArray", + "doc": "Returns an optional url value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "url", + "doc": "Fallback value if value by index not exists or it's is not a url." + } + ], + "result_type": "url", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getOptUrlFromArray(array, integer, string) url", + "function_name": "getOptUrlFromArray", + "doc": "Returns an optional url value from array.", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + }, + { + "type": "string", + "doc": "Fallback value if value by index not exists or it's is not a url." + } + ], + "result_type": "url", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getArrayFromArray(array, integer) array", + "function_name": "getArrayFromArray", + "doc": "Returns an array value from array", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "array", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getOptArrayFromArray(array, integer) array", + "function_name": "getOptArrayFromArray", + "doc": "Returns an array value from array if exist or empty array otherwise", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "array", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getDictFromArray(array, integer) dict", + "function_name": "getDictFromArray", + "doc": "Returns an dict value from array", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "dict", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "getOptDictFromArray(array, integer) dict", + "function_name": "getOptDictFromArray", + "doc": "Returns an dict value from array if exist or empty dict otherwise", + "arguments": [ + { + "type": "array", + "doc": "Array." + }, + { + "type": "integer", + "doc": "Index at array." + } + ], + "result_type": "dict", + "platforms": [ + "android", + "web" + ] + }, + { + "name": "len(array) integer", + "function_name": "len", + "doc": "Gets the length of array. Returns integer value.", + "arguments": [ + { + "type": "array", + "doc": "Array value to get length of." + } + ], + "result_type": "integer", + "platforms": [ + "web" + ] + } + ] +} diff --git a/test_data/expression_test_data/function_signatures_std.json b/test_data/expression_test_data/function_signatures_std.json index 5f816d7db..c8c4854b1 100644 --- a/test_data/expression_test_data/function_signatures_std.json +++ b/test_data/expression_test_data/function_signatures_std.json @@ -1072,723 +1072,6 @@ "web" ] }, - { - "name": "getArrayString(array, integer) string", - "function_name": "getArrayString", - "doc": "Returns a string value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "string", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayNumber(array, integer) number", - "function_name": "getArrayNumber", - "doc": "Returns a number value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "number", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayInteger(array, integer) integer", - "function_name": "getArrayInteger", - "doc": "Returns an integer value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "integer", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayBoolean(array, integer) boolean", - "function_name": "getArrayBoolean", - "doc": "Returns a boolean property from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "boolean", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayColor(array, integer) color", - "function_name": "getArrayColor", - "doc": "Returns a color property from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "color", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayOptString(array, integer, string) string", - "function_name": "getArrayOptString", - "doc": "Returns an optional string property from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "string", - "doc": "Fallback value if value by index not exists or it's is not a string." - } - ], - "result_type": "string", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayOptNumber(array, integer, number) number", - "function_name": "getArrayOptNumber", - "doc": "Returns an optional number property from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "number", - "doc": "Fallback value if value by index not exists or it's is not a number." - } - ], - "result_type": "number", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayOptInteger(array, integer, integer) integer", - "function_name": "getArrayOptInteger", - "doc": "Returns an optional integer property from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "integer", - "doc": "Fallback value if property does not exist or a property value is not an integer." - } - ], - "result_type": "integer", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayOptBoolean(array, integer, boolean) boolean", - "function_name": "getArrayOptBoolean", - "doc": "Returns an optional boolean value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "boolean", - "doc": "Fallback value if value by index not exists or it's is not a boolean." - } - ], - "result_type": "boolean", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayOptColor(array, integer, color) color", - "function_name": "getArrayOptColor", - "doc": "Returns an optional color value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "color", - "doc": "Fallback value if value by index not exists or it's is not a color." - } - ], - "result_type": "color", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayOptColor(array, integer, string) color", - "function_name": "getArrayOptColor", - "doc": "Returns an optional color value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "string", - "doc": "Fallback value if value by index not exists or it's is not a color." - } - ], - "result_type": "color", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayUrl(array, integer) url", - "function_name": "getArrayUrl", - "doc": "Returns an url value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "url", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getArrayOptUrl(array, integer, url) url", - "function_name": "getArrayOptUrl", - "doc": "Returns an optional url value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "url", - "doc": "Fallback value if value by index not exists or it's is not a url." - } - ], - "result_type": "url", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getArrayOptUrl(array, integer, string) url", - "function_name": "getArrayOptUrl", - "doc": "Returns an optional url value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "string", - "doc": "Fallback value if value by index not exists or it's is not a url." - } - ], - "result_type": "url", - "platforms": [ - "android", - "ios", - "web" - ] - }, - { - "name": "getStringFromArray(array, integer) string", - "function_name": "getStringFromArray", - "doc": "Returns a string value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "string", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getNumberFromArray(array, integer) number", - "function_name": "getNumberFromArray", - "doc": "Returns a number value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "number", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getIntegerFromArray(array, integer) integer", - "function_name": "getIntegerFromArray", - "doc": "Returns an integer value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "integer", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getBooleanFromArray(array, integer) boolean", - "function_name": "getBooleanFromArray", - "doc": "Returns a boolean property from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "boolean", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getColorFromArray(array, integer) color", - "function_name": "getColorFromArray", - "doc": "Returns a color property from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "color", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getOptStringFromArray(array, integer, string) string", - "function_name": "getOptStringFromArray", - "doc": "Returns an optional string property from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "string", - "doc": "Fallback value if value by index not exists or it's is not a string." - } - ], - "result_type": "string", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getOptNumberFromArray(array, integer, number) number", - "function_name": "getOptNumberFromArray", - "doc": "Returns an optional number property from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "number", - "doc": "Fallback value if value by index not exists or it's is not a number." - } - ], - "result_type": "number", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getOptIntegerFromArray(array, integer, integer) integer", - "function_name": "getOptIntegerFromArray", - "doc": "Returns an optional integer property from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "integer", - "doc": "Fallback value if property does not exist or a property value is not an integer." - } - ], - "result_type": "integer", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getOptBooleanFromArray(array, integer, boolean) boolean", - "function_name": "getOptBooleanFromArray", - "doc": "Returns an optional boolean value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "boolean", - "doc": "Fallback value if value by index not exists or it's is not a boolean." - } - ], - "result_type": "boolean", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getOptColorFromArray(array, integer, color) color", - "function_name": "getOptColorFromArray", - "doc": "Returns an optional color value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "color", - "doc": "Fallback value if value by index not exists or it's is not a color." - } - ], - "result_type": "color", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getOptColorFromArray(array, integer, string) color", - "function_name": "getOptColorFromArray", - "doc": "Returns an optional color value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "string", - "doc": "Fallback value if value by index not exists or it's is not a color." - } - ], - "result_type": "color", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getUrlFromArray(array, integer) url", - "function_name": "getUrlFromArray", - "doc": "Returns an url value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "url", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getOptUrlFromArray(array, integer, url) url", - "function_name": "getOptUrlFromArray", - "doc": "Returns an optional url value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "url", - "doc": "Fallback value if value by index not exists or it's is not a url." - } - ], - "result_type": "url", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getOptUrlFromArray(array, integer, string) url", - "function_name": "getOptUrlFromArray", - "doc": "Returns an optional url value from array.", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - }, - { - "type": "string", - "doc": "Fallback value if value by index not exists or it's is not a url." - } - ], - "result_type": "url", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getArrayFromArray(array, integer) array", - "function_name": "getArrayFromArray", - "doc": "Returns an array value from array", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "array", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getOptArrayFromArray(array, integer) array", - "function_name": "getOptArrayFromArray", - "doc": "Returns an array value from array if exist or empty array otherwise", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "array", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getDictFromArray(array, integer) dict", - "function_name": "getDictFromArray", - "doc": "Returns an dict value from array", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "dict", - "platforms": [ - "android", - "web" - ] - }, - { - "name": "getOptDictFromArray(array, integer) dict", - "function_name": "getOptDictFromArray", - "doc": "Returns an dict value from array if exist or empty dict otherwise", - "arguments": [ - { - "type": "array", - "doc": "Array." - }, - { - "type": "integer", - "doc": "Index at array." - } - ], - "result_type": "dict", - "platforms": [ - "android", - "web" - ] - }, { "name": "getStoredIntegerValue(string, integer) integer", "function_name": "getStoredIntegerValue", diff --git a/test_data/expression_test_data/functions_array.json b/test_data/expression_test_data/functions_array.json index 1469d423e..f3807c6ca 100644 --- a/test_data/expression_test_data/functions_array.json +++ b/test_data/expression_test_data/functions_array.json @@ -809,6 +809,67 @@ "android", "web" ] + }, + { + "name": "len(array) => 0", + "expression": "@{len(array)}", + "expected": { + "type": "integer", + "value": 0 + }, + "variables": [ + { + "type": "array", + "name": "array", + "value": [ + ] + } + ], + "platforms": [ + "web" + ] + }, + { + "name": "len(array) => 1", + "expression": "@{len(array)}", + "expected": { + "type": "integer", + "value": 1 + }, + "variables": [ + { + "type": "array", + "name": "array", + "value": [ + 1 + ] + } + ], + "platforms": [ + "web" + ] + }, + { + "name": "len(array) => 3", + "expression": "@{len(array)}", + "expected": { + "type": "integer", + "value": 3 + }, + "variables": [ + { + "type": "array", + "name": "array", + "value": [ + 1, + "a", + true + ] + } + ], + "platforms": [ + "web" + ] } ] }