From 15b414d1efc319b40b7b295b30cdedee11df27b6 Mon Sep 17 00:00:00 2001 From: "LAPTOP-S0QU96IH\\david" Date: Tue, 30 May 2023 11:55:57 +0200 Subject: [PATCH] Added simple expression functions --- src/features/expressions/index.ts | 124 ++++++++++++++++++ .../should-include-word-in-string.json | 5 + .../should-not-include-word-in-string.json | 5 + .../string-list-include-number.json | 5 + .../functions/contains/case-sensitivity.json | 5 + .../functions/contains/exact-match.json | 5 + .../functions/contains/not-match.json | 5 + .../functions/contains/partial-match.json | 5 + .../functions/endsWith/case-sensitivity.json | 5 + .../functions/endsWith/ends-with-number.json | 5 + .../functions/endsWith/ends-with.json | 5 + .../functions/endsWith/exact-match.json | 5 + .../functions/endsWith/not-ends-with.json | 5 + .../endsWith/number-ends-with-number.json | 5 + .../should-return-selected-language.json | 8 ++ ...lowercase-number-should-return-string.json | 5 + .../lowerCase/should-lowercase-string.json | 5 + .../should-lowercase-whole-string.json | 5 + .../should-lowercase-whole-word.json | 5 + .../notContains/case-sensitivity.json | 5 + .../functions/notContains/exact-match.json | 5 + .../functions/notContains/not-match.json | 5 + ...arest-integer-with-decimal-as-strings.json | 5 + .../round/nearest-integer-with-decimal.json | 5 + .../functions/round/nearest-integer.json | 5 + .../round/round-negative-number.json | 5 + .../functions/round/round-strings.json | 5 + .../startsWith/case-sensitivity.json | 5 + .../functions/startsWith/exact-match.json | 5 + .../functions/startsWith/not-starts-with.json | 5 + .../startsWith/number-starts-with-number.json | 5 + .../startsWith/number-starts-with-string.json | 5 + .../startsWith/start-with-number.json | 5 + .../functions/startsWith/start-with.json | 5 + .../functions/stringLength/empty-string.json | 5 + .../stringLength/length-of-number.json | 5 + .../functions/stringLength/string-length.json | 5 + .../stringLength/whitespace-length.json | 5 + ...ould-return-key-name-if-key-not-exist.json | 5 + .../upperCase/should-uppercase-string.json | 5 + .../should-uppercase-whole-string.json | 5 + .../should-uppercase-whole-word.json | 5 + ...uppercase-number-should-return-string.json | 5 + 43 files changed, 337 insertions(+) create mode 100644 src/features/expressions/shared-tests/functions/commaContains/should-include-word-in-string.json create mode 100644 src/features/expressions/shared-tests/functions/commaContains/should-not-include-word-in-string.json create mode 100644 src/features/expressions/shared-tests/functions/commaContains/string-list-include-number.json create mode 100644 src/features/expressions/shared-tests/functions/contains/case-sensitivity.json create mode 100644 src/features/expressions/shared-tests/functions/contains/exact-match.json create mode 100644 src/features/expressions/shared-tests/functions/contains/not-match.json create mode 100644 src/features/expressions/shared-tests/functions/contains/partial-match.json create mode 100644 src/features/expressions/shared-tests/functions/endsWith/case-sensitivity.json create mode 100644 src/features/expressions/shared-tests/functions/endsWith/ends-with-number.json create mode 100644 src/features/expressions/shared-tests/functions/endsWith/ends-with.json create mode 100644 src/features/expressions/shared-tests/functions/endsWith/exact-match.json create mode 100644 src/features/expressions/shared-tests/functions/endsWith/not-ends-with.json create mode 100644 src/features/expressions/shared-tests/functions/endsWith/number-ends-with-number.json create mode 100644 src/features/expressions/shared-tests/functions/language/should-return-selected-language.json create mode 100644 src/features/expressions/shared-tests/functions/lowerCase/lowercase-number-should-return-string.json create mode 100644 src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-string.json create mode 100644 src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-whole-string.json create mode 100644 src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-whole-word.json create mode 100644 src/features/expressions/shared-tests/functions/notContains/case-sensitivity.json create mode 100644 src/features/expressions/shared-tests/functions/notContains/exact-match.json create mode 100644 src/features/expressions/shared-tests/functions/notContains/not-match.json create mode 100644 src/features/expressions/shared-tests/functions/round/nearest-integer-with-decimal-as-strings.json create mode 100644 src/features/expressions/shared-tests/functions/round/nearest-integer-with-decimal.json create mode 100644 src/features/expressions/shared-tests/functions/round/nearest-integer.json create mode 100644 src/features/expressions/shared-tests/functions/round/round-negative-number.json create mode 100644 src/features/expressions/shared-tests/functions/round/round-strings.json create mode 100644 src/features/expressions/shared-tests/functions/startsWith/case-sensitivity.json create mode 100644 src/features/expressions/shared-tests/functions/startsWith/exact-match.json create mode 100644 src/features/expressions/shared-tests/functions/startsWith/not-starts-with.json create mode 100644 src/features/expressions/shared-tests/functions/startsWith/number-starts-with-number.json create mode 100644 src/features/expressions/shared-tests/functions/startsWith/number-starts-with-string.json create mode 100644 src/features/expressions/shared-tests/functions/startsWith/start-with-number.json create mode 100644 src/features/expressions/shared-tests/functions/startsWith/start-with.json create mode 100644 src/features/expressions/shared-tests/functions/stringLength/empty-string.json create mode 100644 src/features/expressions/shared-tests/functions/stringLength/length-of-number.json create mode 100644 src/features/expressions/shared-tests/functions/stringLength/string-length.json create mode 100644 src/features/expressions/shared-tests/functions/stringLength/whitespace-length.json create mode 100644 src/features/expressions/shared-tests/functions/text/should-return-key-name-if-key-not-exist.json create mode 100644 src/features/expressions/shared-tests/functions/upperCase/should-uppercase-string.json create mode 100644 src/features/expressions/shared-tests/functions/upperCase/should-uppercase-whole-string.json create mode 100644 src/features/expressions/shared-tests/functions/upperCase/should-uppercase-whole-word.json create mode 100644 src/features/expressions/shared-tests/functions/upperCase/uppercase-number-should-return-string.json diff --git a/src/features/expressions/index.ts b/src/features/expressions/index.ts index caa623159d..5a9a1700eb 100644 --- a/src/features/expressions/index.ts +++ b/src/features/expressions/index.ts @@ -12,6 +12,7 @@ import { import { ExprContext } from 'src/features/expressions/ExprContext'; import { ExprVal } from 'src/features/expressions/types'; import { addError, asExpression, canBeExpression } from 'src/features/expressions/validation'; +import { getTextResourceByKey } from 'src/language/sharedLanguage'; import { dataSourcesFromState, resolvedLayoutsFromState } from 'src/utils/layout/hierarchy'; import { LayoutNode } from 'src/utils/layout/LayoutNode'; import { LayoutPage } from 'src/utils/layout/LayoutPage'; @@ -44,6 +45,8 @@ export interface EvalExprInObjArgs { deleteNonExpressions?: boolean; } +const altinnWindow = window as unknown as IAltinnWindow; + /** * Magic key used to indicate a config value for all possible values in an object */ @@ -509,6 +512,127 @@ export const ExprFunctions = { args: [ExprVal.String] as const, returns: ExprVal.Any, }), + round: defineFunc({ + impl(number, decimalPoints: number | null): number | null { + if (number === null) { + throw new LookupNotFound(this, `"Value" parameter cannot be null.`); + } + + if (decimalPoints !== undefined && decimalPoints !== null) { + const factor = 10 ** decimalPoints; + return Math.round(number * factor) / factor; + } + + return Math.round(number); + }, + args: [ExprVal.Number, ExprVal.Number] as const, + returns: ExprVal.Number, + }), + text: defineFunc({ + impl(key): string | null { + if (key === null) { + throw new LookupNotFound(this, `"Key" parameter cannot be null.`); + } + const state = altinnWindow.reduxStore.getState(); + return getTextResourceByKey(key, state.textResources.resources); + }, + args: [ExprVal.String] as const, + returns: ExprVal.String, + }), + language: defineFunc({ + impl(): string { + const state = altinnWindow.reduxStore.getState(); + return state.profile.selectedAppLanguage || state.profile.profile.profileSettingPreference.language; + }, + args: [] as const, + returns: ExprVal.String, + }), + contains: defineFunc({ + impl(string: string, stringToContain: string): boolean { + if (string === null || stringToContain === null) { + throw new LookupNotFound(this, `"string" or "stringToContain" parameter cannot be null.`); + } + + return string.includes(stringToContain); + }, + args: [ExprVal.String, ExprVal.String] as const, + returns: ExprVal.Boolean, + }), + notContains: defineFunc({ + impl(string: string, stringToNotContain: string): boolean { + if (string === null || stringToNotContain === null) { + throw new LookupNotFound(this, `"string" or "stringToNotContain" parameter cannot be null.`); + } + return !string.includes(stringToNotContain); + }, + args: [ExprVal.String, ExprVal.String] as const, + returns: ExprVal.Boolean, + }), + endsWith: defineFunc({ + impl(string: string, stringToMatch: string): boolean { + if (string === null || stringToMatch === null) { + throw new LookupNotFound(this, `"string" or "stringToMatch" parameter cannot be null.`); + } + return string.endsWith(stringToMatch); + }, + args: [ExprVal.String, ExprVal.String] as const, + returns: ExprVal.Boolean, + }), + startsWith: defineFunc({ + impl(string: string, stringToMatch: string): boolean { + if (string === null || stringToMatch === null) { + throw new LookupNotFound(this, `"string" or "stringToMatch" parameter cannot be null.`); + } + + return string.startsWith(stringToMatch); + }, + args: [ExprVal.String, ExprVal.String] as const, + returns: ExprVal.Boolean, + }), + stringLength: defineFunc({ + impl(string: string): number { + if (string === null) { + throw new LookupNotFound(this, `"string" parameter cannot be null.`); + } + + return string.length; + }, + args: [ExprVal.String] as const, + returns: ExprVal.Number, + }), + commaContains: defineFunc({ + impl(commaSeparatedString: string, stringToMatch: string): boolean { + if (commaSeparatedString === null || stringToMatch === null) { + throw new LookupNotFound(this, `"commaSeparatedString" or "stringToMatch" parameter cannot be null.`); + } + + // Split the comma separated string into an array and remove whitespace from each part + const parsedToArray = commaSeparatedString.split(',').map((part) => part.trim()); + return parsedToArray.includes(stringToMatch); + }, + args: [ExprVal.String, ExprVal.String] as const, + returns: ExprVal.Boolean, + }), + lowerCase: defineFunc({ + impl(string: string): string { + if (string === null) { + throw new LookupNotFound(this, `"string" parameter cannot be null.`); + } + return string.toLowerCase(); + }, + args: [ExprVal.String] as const, + returns: ExprVal.String, + }), + upperCase: defineFunc({ + impl(string: string): string { + if (string === null) { + throw new LookupNotFound(this, `"string" parameter cannot be null.`); + } + return string.toUpperCase(); + }, + args: [ExprVal.String] as const, + returns: ExprVal.String, + }), }; function asNumber(arg: string) { diff --git a/src/features/expressions/shared-tests/functions/commaContains/should-include-word-in-string.json b/src/features/expressions/shared-tests/functions/commaContains/should-include-word-in-string.json new file mode 100644 index 0000000000..0f4a9c0e09 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/commaContains/should-include-word-in-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should return true if the comma-separated list contains the given value", + "expression": ["commaContains", "hello, bye, hola, adios", "hola"], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/commaContains/should-not-include-word-in-string.json b/src/features/expressions/shared-tests/functions/commaContains/should-not-include-word-in-string.json new file mode 100644 index 0000000000..a2af3ad5aa --- /dev/null +++ b/src/features/expressions/shared-tests/functions/commaContains/should-not-include-word-in-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should return false if the comma-separated list does not contain the given value", + "expression": ["commaContains", "hello, bye, hola, adios", "Hasta luego"], + "expects": false +} diff --git a/src/features/expressions/shared-tests/functions/commaContains/string-list-include-number.json b/src/features/expressions/shared-tests/functions/commaContains/string-list-include-number.json new file mode 100644 index 0000000000..f4049e3948 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/commaContains/string-list-include-number.json @@ -0,0 +1,5 @@ +{ + "name": "Should return true if the comma-separated list contains the given value even if its provided as a number", + "expression": ["commaContains", "40, 50, 60", 40], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/contains/case-sensitivity.json b/src/features/expressions/shared-tests/functions/contains/case-sensitivity.json new file mode 100644 index 0000000000..e761b184ae --- /dev/null +++ b/src/features/expressions/shared-tests/functions/contains/case-sensitivity.json @@ -0,0 +1,5 @@ +{ + "name": "Should not match case sensitive", + "expression": ["contains", "Hello", "hello"], + "expects": false +} diff --git a/src/features/expressions/shared-tests/functions/contains/exact-match.json b/src/features/expressions/shared-tests/functions/contains/exact-match.json new file mode 100644 index 0000000000..5f9667e206 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/contains/exact-match.json @@ -0,0 +1,5 @@ +{ + "name": "Should return true if the first string contains the second string", + "expression": ["contains", "abc", "abc"], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/contains/not-match.json b/src/features/expressions/shared-tests/functions/contains/not-match.json new file mode 100644 index 0000000000..1c4d59214b --- /dev/null +++ b/src/features/expressions/shared-tests/functions/contains/not-match.json @@ -0,0 +1,5 @@ +{ + "name": "should return false if the second string does not contain the first string", + "expression": ["contains", "Hello", "Bye"], + "expects": false +} diff --git a/src/features/expressions/shared-tests/functions/contains/partial-match.json b/src/features/expressions/shared-tests/functions/contains/partial-match.json new file mode 100644 index 0000000000..1dc17e579e --- /dev/null +++ b/src/features/expressions/shared-tests/functions/contains/partial-match.json @@ -0,0 +1,5 @@ +{ + "name": "Should return true if the string contains the substring", + "expression": ["contains", "abc", "b"], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/endsWith/case-sensitivity.json b/src/features/expressions/shared-tests/functions/endsWith/case-sensitivity.json new file mode 100644 index 0000000000..6e63b5b213 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/endsWith/case-sensitivity.json @@ -0,0 +1,5 @@ +{ + "name": "Should be case sensitive and return false if the string does end with the given string but opposite case", + "expression": ["endsWith", "Hello", "LO"], + "expects": false +} diff --git a/src/features/expressions/shared-tests/functions/endsWith/ends-with-number.json b/src/features/expressions/shared-tests/functions/endsWith/ends-with-number.json new file mode 100644 index 0000000000..e401cac5c6 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/endsWith/ends-with-number.json @@ -0,0 +1,5 @@ +{ + "name": "Should be true when the string ends with the given string (even when the given 'string' is a number)", + "expression": ["endsWith", "Im 40", 40], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/endsWith/ends-with.json b/src/features/expressions/shared-tests/functions/endsWith/ends-with.json new file mode 100644 index 0000000000..37fcd96e91 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/endsWith/ends-with.json @@ -0,0 +1,5 @@ +{ + "name": "Should be true when the string ends with the specified string", + "expression": ["endsWith", "Hello", "lo"], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/endsWith/exact-match.json b/src/features/expressions/shared-tests/functions/endsWith/exact-match.json new file mode 100644 index 0000000000..1c9ced8afa --- /dev/null +++ b/src/features/expressions/shared-tests/functions/endsWith/exact-match.json @@ -0,0 +1,5 @@ +{ + "name": "Should be true when the string ends with the specified string, even on exact match", + "expression": ["endsWith", "Hello", "Hello"], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/endsWith/not-ends-with.json b/src/features/expressions/shared-tests/functions/endsWith/not-ends-with.json new file mode 100644 index 0000000000..fbf25b86ca --- /dev/null +++ b/src/features/expressions/shared-tests/functions/endsWith/not-ends-with.json @@ -0,0 +1,5 @@ +{ + "name": "Should be false when the string does not ends with the specified string", + "expression": ["endsWith", "Hello", "me"], + "expects": false +} diff --git a/src/features/expressions/shared-tests/functions/endsWith/number-ends-with-number.json b/src/features/expressions/shared-tests/functions/endsWith/number-ends-with-number.json new file mode 100644 index 0000000000..1b2bc1b7c7 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/endsWith/number-ends-with-number.json @@ -0,0 +1,5 @@ +{ + "name": "Should be true when the given number ends with the given digit", + "expression": ["endsWith", 102, 2], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/language/should-return-selected-language.json b/src/features/expressions/shared-tests/functions/language/should-return-selected-language.json new file mode 100644 index 0000000000..56700b3a21 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/language/should-return-selected-language.json @@ -0,0 +1,8 @@ +{ + "name": "Should return the selected language", + "expression": ["language"], + "expects": "nb", + "frontendSettings": { + "selectedLanguage": "nb" + } +} diff --git a/src/features/expressions/shared-tests/functions/lowerCase/lowercase-number-should-return-string.json b/src/features/expressions/shared-tests/functions/lowerCase/lowercase-number-should-return-string.json new file mode 100644 index 0000000000..7b6e3a1df3 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/lowerCase/lowercase-number-should-return-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should return number as string when number is passed", + "expression": ["lowerCase", 40], + "expects": "40" +} diff --git a/src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-string.json b/src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-string.json new file mode 100644 index 0000000000..5f38166d8b --- /dev/null +++ b/src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should lowercase the string", + "expression": ["lowerCase", "HELLO"], + "expects": "hello" +} diff --git a/src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-whole-string.json b/src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-whole-string.json new file mode 100644 index 0000000000..7a90a8d227 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-whole-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should lowercase the whole string when given a string has multiple words", + "expression": ["lowerCase", "Hola, Como Estas?"], + "expects": "hola, como estas?" +} diff --git a/src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-whole-word.json b/src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-whole-word.json new file mode 100644 index 0000000000..4b9fa972a8 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/lowerCase/should-lowercase-whole-word.json @@ -0,0 +1,5 @@ +{ + "name": "Should lowercase the whole string", + "expression": ["lowerCase", "HElLo"], + "expects": "hello" +} diff --git a/src/features/expressions/shared-tests/functions/notContains/case-sensitivity.json b/src/features/expressions/shared-tests/functions/notContains/case-sensitivity.json new file mode 100644 index 0000000000..0cdf815c03 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/notContains/case-sensitivity.json @@ -0,0 +1,5 @@ +{ + "name": "Should not match case sensitive", + "expression": ["notContains", "Hello", "hello"], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/notContains/exact-match.json b/src/features/expressions/shared-tests/functions/notContains/exact-match.json new file mode 100644 index 0000000000..02c5f9b689 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/notContains/exact-match.json @@ -0,0 +1,5 @@ +{ + "name": "Should return false when the string does contain the substring", + "expression": ["notContains", "abc", "abc"], + "expects": false +} diff --git a/src/features/expressions/shared-tests/functions/notContains/not-match.json b/src/features/expressions/shared-tests/functions/notContains/not-match.json new file mode 100644 index 0000000000..8cc79e6f41 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/notContains/not-match.json @@ -0,0 +1,5 @@ +{ + "name": "should return true if the string does not contain the substring", + "expression": ["notContains", "Hello", "Bye"], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/round/nearest-integer-with-decimal-as-strings.json b/src/features/expressions/shared-tests/functions/round/nearest-integer-with-decimal-as-strings.json new file mode 100644 index 0000000000..796a004f16 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/round/nearest-integer-with-decimal-as-strings.json @@ -0,0 +1,5 @@ +{ + "name": "Should round a number to the nearest integer with a precision of 2", + "expression": ["round", "2.2199999", "2"], + "expects": 2.22 +} diff --git a/src/features/expressions/shared-tests/functions/round/nearest-integer-with-decimal.json b/src/features/expressions/shared-tests/functions/round/nearest-integer-with-decimal.json new file mode 100644 index 0000000000..18d3156860 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/round/nearest-integer-with-decimal.json @@ -0,0 +1,5 @@ +{ + "name": "Should round a number to the nearest integer with a precision of 2", + "expression": ["round", 3.2199999, 2], + "expects": 3.22 +} diff --git a/src/features/expressions/shared-tests/functions/round/nearest-integer.json b/src/features/expressions/shared-tests/functions/round/nearest-integer.json new file mode 100644 index 0000000000..05ee5aee77 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/round/nearest-integer.json @@ -0,0 +1,5 @@ +{ + "name": "Should round to nearest integer", + "expression": ["round", 3.2, null], + "expects": 3 +} diff --git a/src/features/expressions/shared-tests/functions/round/round-negative-number.json b/src/features/expressions/shared-tests/functions/round/round-negative-number.json new file mode 100644 index 0000000000..c5e464a7c2 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/round/round-negative-number.json @@ -0,0 +1,5 @@ +{ + "name": "Should round negative number", + "expression": ["round", -2.999, null], + "expects": -3 +} diff --git a/src/features/expressions/shared-tests/functions/round/round-strings.json b/src/features/expressions/shared-tests/functions/round/round-strings.json new file mode 100644 index 0000000000..5f4c373ee8 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/round/round-strings.json @@ -0,0 +1,5 @@ +{ + "name": "Should be able to round a number to the nearest integer even if it is a string", + "expression": ["round", "3.99", null], + "expects": 4 +} diff --git a/src/features/expressions/shared-tests/functions/startsWith/case-sensitivity.json b/src/features/expressions/shared-tests/functions/startsWith/case-sensitivity.json new file mode 100644 index 0000000000..c9a6c8e3c9 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/startsWith/case-sensitivity.json @@ -0,0 +1,5 @@ +{ + "name": "Should be case sensitive and return false if the string does start with the given string but opposite case", + "expression": ["startsWith", "Hello", "HEL"], + "expects": false +} diff --git a/src/features/expressions/shared-tests/functions/startsWith/exact-match.json b/src/features/expressions/shared-tests/functions/startsWith/exact-match.json new file mode 100644 index 0000000000..70c50773f3 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/startsWith/exact-match.json @@ -0,0 +1,5 @@ +{ + "name": "Should be true when the string starts with the specified string, even on exact match", + "expression": ["startsWith", "Hello", "Hello"], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/startsWith/not-starts-with.json b/src/features/expressions/shared-tests/functions/startsWith/not-starts-with.json new file mode 100644 index 0000000000..5651cacecc --- /dev/null +++ b/src/features/expressions/shared-tests/functions/startsWith/not-starts-with.json @@ -0,0 +1,5 @@ +{ + "name": "Should be false when the string does not starts with the specified string", + "expression": ["startsWith", "Hello", "Bye"], + "expects": false +} diff --git a/src/features/expressions/shared-tests/functions/startsWith/number-starts-with-number.json b/src/features/expressions/shared-tests/functions/startsWith/number-starts-with-number.json new file mode 100644 index 0000000000..5d4c14bcd1 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/startsWith/number-starts-with-number.json @@ -0,0 +1,5 @@ +{ + "name": "Should be true when the given number starts with the given digit", + "expression": ["startsWith", 102, 1], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/startsWith/number-starts-with-string.json b/src/features/expressions/shared-tests/functions/startsWith/number-starts-with-string.json new file mode 100644 index 0000000000..f14d63a247 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/startsWith/number-starts-with-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should be true when the number starts with the given string (number starts with string)", + "expression": ["startsWith", 40, "40"], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/startsWith/start-with-number.json b/src/features/expressions/shared-tests/functions/startsWith/start-with-number.json new file mode 100644 index 0000000000..67b58ef0e5 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/startsWith/start-with-number.json @@ -0,0 +1,5 @@ +{ + "name": "Should be true when the string starts with the given string (even when the given 'string' is a number)", + "expression": ["startsWith", "40 years old", 40], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/startsWith/start-with.json b/src/features/expressions/shared-tests/functions/startsWith/start-with.json new file mode 100644 index 0000000000..902ef46656 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/startsWith/start-with.json @@ -0,0 +1,5 @@ +{ + "name": "Should be true when the string starts with the specified string", + "expression": ["startsWith", "Hello", "Hel"], + "expects": true +} diff --git a/src/features/expressions/shared-tests/functions/stringLength/empty-string.json b/src/features/expressions/shared-tests/functions/stringLength/empty-string.json new file mode 100644 index 0000000000..e2249bdca3 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/stringLength/empty-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should return the length of a string even when it's empty", + "expression": ["stringLength", ""], + "expects": 0 +} diff --git a/src/features/expressions/shared-tests/functions/stringLength/length-of-number.json b/src/features/expressions/shared-tests/functions/stringLength/length-of-number.json new file mode 100644 index 0000000000..5bd8f01777 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/stringLength/length-of-number.json @@ -0,0 +1,5 @@ +{ + "name": "Should return the length of a string even if it is type of number", + "expression": ["stringLength", 203], + "expects": 3 +} diff --git a/src/features/expressions/shared-tests/functions/stringLength/string-length.json b/src/features/expressions/shared-tests/functions/stringLength/string-length.json new file mode 100644 index 0000000000..880a2ae9f7 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/stringLength/string-length.json @@ -0,0 +1,5 @@ +{ + "name": "Should return the length of a string", + "expression": ["stringLength", "Hello"], + "expects": 5 +} diff --git a/src/features/expressions/shared-tests/functions/stringLength/whitespace-length.json b/src/features/expressions/shared-tests/functions/stringLength/whitespace-length.json new file mode 100644 index 0000000000..f77bd7b1ef --- /dev/null +++ b/src/features/expressions/shared-tests/functions/stringLength/whitespace-length.json @@ -0,0 +1,5 @@ +{ + "name": "Should count whitespace as a character when counting string length", + "expression": ["stringLength", " "], + "expects": 1 +} diff --git a/src/features/expressions/shared-tests/functions/text/should-return-key-name-if-key-not-exist.json b/src/features/expressions/shared-tests/functions/text/should-return-key-name-if-key-not-exist.json new file mode 100644 index 0000000000..e69a1d3c93 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/text/should-return-key-name-if-key-not-exist.json @@ -0,0 +1,5 @@ +{ + "name": "Should return 'key-name' when key does not exist", + "expression": ["text", "random-key"], + "expects": "random-key" +} diff --git a/src/features/expressions/shared-tests/functions/upperCase/should-uppercase-string.json b/src/features/expressions/shared-tests/functions/upperCase/should-uppercase-string.json new file mode 100644 index 0000000000..e283e4372b --- /dev/null +++ b/src/features/expressions/shared-tests/functions/upperCase/should-uppercase-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should UPPERCASE the string", + "expression": ["upperCase", "hello"], + "expects": "HELLO" +} diff --git a/src/features/expressions/shared-tests/functions/upperCase/should-uppercase-whole-string.json b/src/features/expressions/shared-tests/functions/upperCase/should-uppercase-whole-string.json new file mode 100644 index 0000000000..844d2cbbe7 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/upperCase/should-uppercase-whole-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should UPPERCASE the whole string when given a string has multiple words", + "expression": ["upperCase", "Hola, como estas?"], + "expects": "HOLA, COMO ESTAS?" +} diff --git a/src/features/expressions/shared-tests/functions/upperCase/should-uppercase-whole-word.json b/src/features/expressions/shared-tests/functions/upperCase/should-uppercase-whole-word.json new file mode 100644 index 0000000000..45dce5c184 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/upperCase/should-uppercase-whole-word.json @@ -0,0 +1,5 @@ +{ + "name": "Should UPPERCASE the whole string", + "expression": ["upperCase", "heLlo"], + "expects": "HELLO" +} diff --git a/src/features/expressions/shared-tests/functions/upperCase/uppercase-number-should-return-string.json b/src/features/expressions/shared-tests/functions/upperCase/uppercase-number-should-return-string.json new file mode 100644 index 0000000000..60479c63a2 --- /dev/null +++ b/src/features/expressions/shared-tests/functions/upperCase/uppercase-number-should-return-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should return number as string when number is passed", + "expression": ["upperCase", 40], + "expects": "40" +}