From 26aa1dab76de8defcf7bed61d3c9cf5ad69a2edf Mon Sep 17 00:00:00 2001 From: Vemund Gaukstad Date: Tue, 8 Aug 2023 12:49:12 +0200 Subject: [PATCH] Sync backend expression functions with frontend (#277) * Implement missing functions in backend * add some testcases for functions that should be evaluated before implemented in the backend code * Simplify some functions --- .../Expressions/ExpressionEvaluator.cs | 157 ++++++++++++++++-- .../Expressions/ExpressionFunctionEnum.cs | 36 ++++ .../CommonTests/TestFunctions.cs | 36 ++++ .../context-lists/groups/noData.json | 2 +- .../context-lists/groups/oneRow.json | 2 +- .../context-lists/groups/twoRows.json | 2 +- .../nonRepeatingGroups/maxCount0.json | 2 +- .../nonRepeatingGroups/maxCount1.json | 2 +- .../nonRepeatingGroups/simple.json | 2 +- .../recursiveGroups/recursiveNoData.json | 2 +- .../recursiveGroups/recursiveOneRow.json | 2 +- .../recursiveTwoRowsInner.json | 2 +- .../recursiveTwoRowsOuter.json | 2 +- .../context-lists/simple/twoPages.json | 2 +- .../functions/commaContains/empty-string.json | 5 + .../functions/commaContains/null.json | 5 + .../functions/commaContains/null2.json | 5 + .../should-include-word-in-string.json | 5 + .../should-not-include-word-in-string.json | 5 + .../string-list-include-number.json | 5 + .../component/distant-across-page.json | 82 ++++----- .../functions/component/distant.json | 68 ++++---- .../functions/contains/case-sensitivity.json | 5 + .../functions/contains/empty-string.json | 5 + .../functions/contains/exact-match.json | 5 + .../functions/contains/not-match.json | 5 + .../shared-tests/functions/contains/null.json | 5 + .../functions/contains/null2.json | 5 + .../functions/contains/null3.json | 5 + .../functions/contains/null4.json | 5 + .../functions/contains/partial-match.json | 5 + .../functions/endsWith/case-sensitivity.json | 5 + .../functions/endsWith/empty-string.json | 5 + .../functions/endsWith/ends-with-null.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 + ...lowercase-number-should-return-string.json | 5 + .../functions/lowerCase/null.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 + .../functions/notContains/null.json | 5 + .../functions/notContains/null2.json | 5 + .../functions/notContains/null3.json | 5 + .../functions/notContains/null4.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-0-decimal-places.json | 5 + .../round/round-0-decimal-places2.json | 5 + .../round/round-negative-number.json | 5 + .../functions/round/round-null.json | 5 + .../functions/round/round-null2.json | 5 + .../functions/round/round-strings.json | 5 + .../round/round-with-too-many-args.json | 5 + .../round/round-without-decimalCount.json | 5 + .../round/round-without-decimalCount2.json | 5 + .../startsWith/case-sensitivity.json | 5 + .../functions/startsWith/empty-string.json | 5 + .../functions/startsWith/exact-match.json | 5 + .../functions/startsWith/not-starts-with.json | 5 + .../functions/startsWith/null.json | 5 + .../functions/startsWith/null2.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 + .../stringLength/length-of-unicode.json | 5 + .../functions/stringLength/null.json | 5 + .../functions/stringLength/string-length.json | 5 + .../stringLength/whitespace-length.json | 5 + .../functions/upperCase/null.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 + .../functions/authContext/read-confirm.json | 15 ++ .../authContext/read-sign-reject.json | 15 ++ .../functions/authContext/read-sign.json | 20 +++ .../functions/authContext/read-write.json | 15 ++ .../language/should-return-nb-if-not-set.json | 5 + ...ld-return-profile-settings-preference.json | 8 + .../should-return-selected-language.json | 5 + .../functions/text/null.json | 5 + ...ould-return-key-name-if-key-not-exist.json | 5 + ...ariable-in-rep-group-no-index-markers.json | 114 +++++++++++++ ...t-resource-with-variable-in-rep-group.json | 114 +++++++++++++ ...ld-return-text-resource-with-variable.json | 25 +++ .../text/should-return-text-resource.json | 11 ++ 97 files changed, 998 insertions(+), 100 deletions(-) create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/empty-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/null.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/null2.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/should-include-word-in-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/should-not-include-word-in-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/string-list-include-number.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/case-sensitivity.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/empty-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/exact-match.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/not-match.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null2.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null3.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null4.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/partial-match.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/case-sensitivity.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/empty-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/ends-with-null.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/ends-with-number.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/ends-with.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/exact-match.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/not-ends-with.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/number-ends-with-number.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/lowercase-number-should-return-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/null.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/should-lowercase-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/should-lowercase-whole-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/should-lowercase-whole-word.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/case-sensitivity.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/exact-match.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/not-match.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null2.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null3.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null4.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/nearest-integer-with-decimal-as-strings.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/nearest-integer-with-decimal.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/nearest-integer.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-0-decimal-places.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-0-decimal-places2.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-negative-number.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-null.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-null2.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-strings.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-with-too-many-args.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-without-decimalCount.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-without-decimalCount2.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/case-sensitivity.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/empty-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/exact-match.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/not-starts-with.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/null.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/null2.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/number-starts-with-number.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/number-starts-with-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/start-with-number.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/start-with.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/empty-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/length-of-number.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/length-of-unicode.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/null.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/string-length.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/whitespace-length.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/null.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/should-uppercase-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/should-uppercase-whole-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/should-uppercase-whole-word.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/uppercase-number-should-return-string.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-confirm.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-sign-reject.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-sign.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-write.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-nb-if-not-set.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-profile-settings-preference.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-selected-language.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/null.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-key-name-if-key-not-exist.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable-in-rep-group-no-index-markers.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable-in-rep-group.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable.json create mode 100644 test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource.json diff --git a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs index f2afe3651..fb90a7e43 100644 --- a/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs +++ b/src/Altinn.App.Core/Internal/Expressions/ExpressionEvaluator.cs @@ -1,5 +1,4 @@ using System.Globalization; -using System.Text.Json; using System.Text.RegularExpressions; using Altinn.App.Core.Models.Expressions; @@ -76,6 +75,15 @@ public static bool EvaluateBooleanExpression(LayoutEvaluatorState state, Compone ExpressionFunction.and => And(args), ExpressionFunction.or => Or(args), ExpressionFunction.not => Not(args), + ExpressionFunction.contains => Contains(args), + ExpressionFunction.notContains => !Contains(args), + ExpressionFunction.commaContains => CommaContains(args), + ExpressionFunction.endsWith => EndsWith(args), + ExpressionFunction.startsWith => StartsWith(args), + ExpressionFunction.stringLength => StringLength(args), + ExpressionFunction.round => Round(args), + ExpressionFunction.upperCase => UpperCase(args), + ExpressionFunction.lowerCase => LowerCase(args), _ => throw new ExpressionEvaluatorTypeErrorException($"Function \"{expr.Function}\" not implemented"), }; return ret; @@ -119,6 +127,127 @@ public static bool EvaluateBooleanExpression(LayoutEvaluatorState state, Compone return string.Join("", args.Select(a => a switch { string s => s, _ => ToStringForEquals(a) })); } + private static bool Contains(object?[] args) + { + if (args.Length != 2) + { + throw new ExpressionEvaluatorTypeErrorException($"Expected 2 argument(s), got {args.Length}"); + } + string? stringOne = ToStringForEquals(args[0]); + string? stringTwo = ToStringForEquals(args[1]); + + if (stringOne is null || stringTwo is null) + { + return false; + } + + return stringOne.Contains(stringTwo, StringComparison.InvariantCulture); + } + + private static bool EndsWith(object?[] args) + { + if (args.Length != 2) + { + throw new ExpressionEvaluatorTypeErrorException($"Expected 2 argument(s), got {args.Length}"); + } + string? stringOne = ToStringForEquals(args[0]); + string? stringTwo = ToStringForEquals(args[1]); + + if (stringOne is null || stringTwo is null) + { + return false; + } + + return stringOne.EndsWith(stringTwo, StringComparison.InvariantCulture); + } + + private static bool StartsWith(object?[] args) + { + if (args.Length != 2) + { + throw new ExpressionEvaluatorTypeErrorException($"Expected 2 argument(s), got {args.Length}"); + } + string? stringOne = ToStringForEquals(args[0]); + string? stringTwo = ToStringForEquals(args[1]); + + if (stringOne is null || stringTwo is null) + { + return false; + } + + return stringOne.StartsWith(stringTwo, StringComparison.InvariantCulture); + } + + private static bool CommaContains(object?[] args) + { + if (args.Length != 2) + { + throw new ExpressionEvaluatorTypeErrorException($"Expected 2 arguments, got {args.Length}"); + } + string? stringOne = ToStringForEquals(args[0]); + string? stringTwo = ToStringForEquals(args[1]); + + if (stringOne is null || stringTwo is null) + { + return false; + } + + return stringOne.Split(",").Select(s => s.Trim()).Contains(stringTwo, StringComparer.InvariantCulture); + } + + private static int StringLength(object?[] args) + { + if (args.Length != 1) + { + throw new ExpressionEvaluatorTypeErrorException($"Expected 1 argument, got {args.Length}"); + } + string? stringOne = ToStringForEquals(args[0]); + return stringOne?.Length ?? 0; + } + + private static string Round(object?[] args) + { + if (args.Length < 1 || args.Length> 2) + { + throw new ExpressionEvaluatorTypeErrorException($"Expected 1-2 argument(s), got {args.Length}"); + } + + var number = PrepareNumericArg(args[0]); + + if(number is null) + { + number = 0; + } + + int precision = 0; + if (args.Length == 2 && args[1] is not null) + { + precision = Convert.ToInt32(args[1]); + } + + return number.Value.ToString($"N{precision}", CultureInfo.InvariantCulture); + } + + private static string? UpperCase(object?[] args) + { + if (args.Length != 1) + { + throw new ExpressionEvaluatorTypeErrorException($"Expected 1 argument, got {args.Length}"); + } + string? stringOne = ToStringForEquals(args[0]); + return stringOne?.ToUpperInvariant(); + } + + private static string? LowerCase(object?[] args) + { + if (args.Length != 1) + { + throw new ExpressionEvaluatorTypeErrorException($"Expected 1 argument, got {args.Length}"); + } + string? stringOne = ToStringForEquals(args[0]); + return stringOne?.ToLowerInvariant(); + } + private static bool PrepareBooleanArg(object? arg) { return arg switch @@ -187,23 +316,23 @@ private static (double?, double?) PrepareNumericArgs(object?[] args) { throw new ExpressionEvaluatorTypeErrorException("Invalid number of args for compare"); } - var a = args[0] switch - { - bool ab => throw new ExpressionEvaluatorTypeErrorException($"Expected number, got value {(ab ? "true" : "false")}"), - string s => parseNumber(s), - object o => o as double?, // assume all relevant numers are representable as double (as in frontend) - _ => null, - }; - var b = args[1] switch + var a = PrepareNumericArg(args[0]); + + var b = PrepareNumericArg(args[1]); + + return (a, b); + } + + private static double? PrepareNumericArg(object? arg) + { + return arg switch { - bool bb => throw new ExpressionEvaluatorTypeErrorException($"Expected number, got value {(bb ? "true" : "false")}"), + bool ab => throw new ExpressionEvaluatorTypeErrorException($"Expected number, got value {(ab ? "true" : "false")}"), string s => parseNumber(s), - object o => o as double?, // assume all relevant numers are representable as double (as in frontend) - _ => null, + object o => o as double?, // assume all relevant numbers are representable as double (as in frontend) + _ => null }; - - return (a, b); } private static object? IfImpl(object?[] args) diff --git a/src/Altinn.App.Core/Models/Expressions/ExpressionFunctionEnum.cs b/src/Altinn.App.Core/Models/Expressions/ExpressionFunctionEnum.cs index f5eec0e9e..b5be86c35 100644 --- a/src/Altinn.App.Core/Models/Expressions/ExpressionFunctionEnum.cs +++ b/src/Altinn.App.Core/Models/Expressions/ExpressionFunctionEnum.cs @@ -34,6 +34,34 @@ public enum ExpressionFunction /// concat, /// + /// Turn characters to upper case + /// + upperCase, + /// + /// Turn characters to lower case + /// + lowerCase, + /// + /// Check if a string contains another string + /// + contains, + /// + /// Check if a string does not contain another string + /// + notContains, + /// + /// Check if a comma separated string contains a value + /// + commaContains, + /// + /// Check if a string ends with another string + /// + endsWith, + /// + /// Check if a string starts with another string + /// + startsWith, + /// /// Check if values are equal /// equals, @@ -58,6 +86,14 @@ public enum ExpressionFunction /// greaterThan, /// + /// Return the length of a string + /// + stringLength, + /// + /// Rounds a number to an integer, or optionally a decimal with a configurable amount of decimal points + /// + round, + /// /// Return true if all the expressions evaluate to true /// and, diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs index 585e1ff79..695ac6812 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/TestFunctions.cs @@ -31,15 +31,27 @@ public TestFunctions(ITestOutputHelper output) [Theory] [SharedTest("component")] public void Component_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); + + [Theory] + [SharedTest("commaContains")] + public void CommaContains_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); [Theory] [SharedTest("concat")] public void Concat_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); + [Theory] + [SharedTest("contains")] + public void Contains_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); + [Theory] [SharedTest("dataModel")] public void DataModel_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); + [Theory] + [SharedTest("endsWith")] + public void EndsWith_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); + [Theory] [SharedTest("equals")] public void Equals_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); @@ -59,6 +71,10 @@ public TestFunctions(ITestOutputHelper output) [Theory] [SharedTest("not")] public void Not_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); + + [Theory] + [SharedTest("notContains")] + public void NotContains_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); [Theory] [SharedTest("instanceContext")] @@ -83,6 +99,26 @@ public TestFunctions(ITestOutputHelper output) [Theory] [SharedTest("unknown")] public void Unknown_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); + + [Theory] + [SharedTest("upperCase")] + public void UpperCase_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); + + [Theory] + [SharedTest("lowerCase")] + public void LowerCase_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); + + [Theory] + [SharedTest("startsWith")] + public void StartsWith_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); + + [Theory] + [SharedTest("stringLength")] + public void StringLength_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); + + [Theory] + [SharedTest("round")] + public void Round_Theory(ExpressionTestCaseRoot test) => RunTestCase(test); private void RunTestCase(ExpressionTestCaseRoot test) { diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/noData.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/noData.json index 360768a36..1596105a1 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/noData.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/noData.json @@ -6,7 +6,7 @@ "layout": [ { "id": "comp1", - "type": "Heading" + "type": "Header" }, { "id": "group1", diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/oneRow.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/oneRow.json index 26ba4e5d6..b043d9411 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/oneRow.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/oneRow.json @@ -6,7 +6,7 @@ "layout": [ { "id": "comp1", - "type": "Heading" + "type": "Header" }, { "id": "group1", diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/twoRows.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/twoRows.json index efcd93c0d..89dd4f259 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/twoRows.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/groups/twoRows.json @@ -6,7 +6,7 @@ "layout": [ { "id": "comp1", - "type": "Heading" + "type": "Header" }, { "id": "group1", diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/maxCount0.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/maxCount0.json index 8db04ce09..8c038be56 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/maxCount0.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/maxCount0.json @@ -6,7 +6,7 @@ "layout": [ { "id": "comp1", - "type": "Heading" + "type": "Header" }, { "id": "group1", diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/maxCount1.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/maxCount1.json index 06199128e..7019c6eed 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/maxCount1.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/maxCount1.json @@ -6,7 +6,7 @@ "layout": [ { "id": "comp1", - "type": "Heading" + "type": "Header" }, { "id": "group1", diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/simple.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/simple.json index 352a1711f..56d2c9252 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/simple.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/nonRepeatingGroups/simple.json @@ -6,7 +6,7 @@ "layout": [ { "id": "comp1", - "type": "Heading" + "type": "Header" }, { "id": "group1", diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveNoData.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveNoData.json index e1f37b526..05ff77bc9 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveNoData.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveNoData.json @@ -6,7 +6,7 @@ "layout": [ { "id": "comp1", - "type": "Heading" + "type": "Header" }, { "id": "group0", diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveOneRow.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveOneRow.json index eb995da76..a0329b437 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveOneRow.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveOneRow.json @@ -6,7 +6,7 @@ "layout": [ { "id": "comp1", - "type": "Heading" + "type": "Header" }, { "id": "group0", diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveTwoRowsInner.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveTwoRowsInner.json index 431fbf231..d4b60ccd3 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveTwoRowsInner.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveTwoRowsInner.json @@ -6,7 +6,7 @@ "layout": [ { "id": "comp1", - "type": "Heading" + "type": "Header" }, { "id": "group0", diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveTwoRowsOuter.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveTwoRowsOuter.json index 652d1df29..0bf29ee1c 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveTwoRowsOuter.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/recursiveGroups/recursiveTwoRowsOuter.json @@ -6,7 +6,7 @@ "layout": [ { "id": "comp1", - "type": "Heading" + "type": "Header" }, { "id": "group0", diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/simple/twoPages.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/simple/twoPages.json index bbe977f53..74356d8de 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/simple/twoPages.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/context-lists/simple/twoPages.json @@ -6,7 +6,7 @@ "layout": [ { "id": "comp1", - "type": "Heading" + "type": "Header" }, { "id": "comp2", diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/empty-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/empty-string.json new file mode 100644 index 000000000..5beadc3d5 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/empty-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should not contain an empty string", + "expression": ["commaContains", "40, 50, 60", ""], + "expects": false +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/null.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/null.json new file mode 100644 index 000000000..30e4156c5 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/null.json @@ -0,0 +1,5 @@ +{ + "name": "Should not contain a null value", + "expression": ["commaContains", "40, 50, 60", null], + "expects": false +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/null2.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/null2.json new file mode 100644 index 000000000..009bae254 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/null2.json @@ -0,0 +1,5 @@ +{ + "name": "Should not split a null value", + "expression": ["commaContains", null, "hello world"], + "expects": false +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/should-include-word-in-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/should-include-word-in-string.json new file mode 100644 index 000000000..0f4a9c0e0 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/should-not-include-word-in-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/should-not-include-word-in-string.json new file mode 100644 index 000000000..a2af3ad5a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/string-list-include-number.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/commaContains/string-list-include-number.json new file mode 100644 index 000000000..f4049e394 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/component/distant-across-page.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/component/distant-across-page.json index 9e1aa5b06..c6beab899 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/component/distant-across-page.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/component/distant-across-page.json @@ -1,45 +1,45 @@ { - "name": "Lookup component that cannot be found using closest() across page", - "expression": ["component", "navn"], - "expects": "Kaptein Sabeltann", - "context": { - "component": "information", - "currentLayout": "Summary" - }, - "dataModel": { - "Navn": "Kaptein Sabeltann" - }, - "layouts": { - "Form": { - "$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json", - "data": { - "layout": [ - { - "id": "group", - "type": "Group", - "dataModelBindings": {}, - "children": ["navn"] - }, - { - "id": "navn", - "type": "Input", - "dataModelBindings": { - "simpleBinding": "Navn" - } - } - ] - } - }, - "Summary": { - "$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json", - "data": { - "layout": [ - { - "id": "information", - "type": "Panel" + "name": "Lookup component that cannot be found using closest() across page", + "expression": ["component", "navn"], + "expects": "Kaptein Sabeltann", + "context": { + "component": "information", + "currentLayout": "Summary" + }, + "dataModel": { + "Navn": "Kaptein Sabeltann" + }, + "layouts": { + "Form": { + "$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json", + "data": { + "layout": [ + { + "id": "group", + "type": "Group", + "dataModelBindings": {}, + "children": ["navn"] + }, + { + "id": "navn", + "type": "Input", + "dataModelBindings": { + "simpleBinding": "Navn" } - ] - } + } + ] + } + }, + "Summary": { + "$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json", + "data": { + "layout": [ + { + "id": "information", + "type": "Panel" + } + ] } } - } \ No newline at end of file + } +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/component/distant.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/component/distant.json index 109ab57cd..2ad95271d 100644 --- a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/component/distant.json +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/component/distant.json @@ -1,38 +1,38 @@ { - "name": "Lookup component that cannot be found using closest()", - "expression": ["component", "navn"], - "expects": "Kaptein Sabeltann", - "context": { - "component": "information", - "currentLayout": "Form" - }, - "dataModel": { - "Navn": "Kaptein Sabeltann" - }, - "layouts": { - "Form": { - "$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json", - "data": { - "layout": [ - { - "id": "group", - "type": "Group", - "dataModelBindings": {}, - "children": ["navn"] - }, - { - "id": "navn", - "type": "Input", - "dataModelBindings": { - "simpleBinding": "Navn" - } - }, - { - "id": "information", - "type": "Panel" + "name": "Lookup component that cannot be found using closest()", + "expression": ["component", "navn"], + "expects": "Kaptein Sabeltann", + "context": { + "component": "information", + "currentLayout": "Form" + }, + "dataModel": { + "Navn": "Kaptein Sabeltann" + }, + "layouts": { + "Form": { + "$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json", + "data": { + "layout": [ + { + "id": "group", + "type": "Group", + "dataModelBindings": {}, + "children": ["navn"] + }, + { + "id": "navn", + "type": "Input", + "dataModelBindings": { + "simpleBinding": "Navn" } - ] - } + }, + { + "id": "information", + "type": "Panel" + } + ] } } - } \ No newline at end of file + } +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/case-sensitivity.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/case-sensitivity.json new file mode 100644 index 000000000..e761b184a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/empty-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/empty-string.json new file mode 100644 index 000000000..b4e14894f --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/empty-string.json @@ -0,0 +1,5 @@ +{ + "name": "Should always contain en empty string", + "expression": ["contains", "Hello", ""], + "expects": true +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/exact-match.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/exact-match.json new file mode 100644 index 000000000..5f9667e20 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/not-match.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/not-match.json new file mode 100644 index 000000000..1c4d59214 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null.json new file mode 100644 index 000000000..f53527bde --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null.json @@ -0,0 +1,5 @@ +{ + "name": "Should always return false when the input is null", + "expression": ["contains", null, "null"], + "expects": false +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null2.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null2.json new file mode 100644 index 000000000..0302631b7 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null2.json @@ -0,0 +1,5 @@ +{ + "name": "Should always return false when the input is null", + "expression": ["contains", "null", null], + "expects": false +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null3.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null3.json new file mode 100644 index 000000000..b525fb777 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null3.json @@ -0,0 +1,5 @@ +{ + "name": "Should always return false when the input is null", + "expression": ["contains", null, null], + "expects": false +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null4.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null4.json new file mode 100644 index 000000000..286a2e3cf --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/null4.json @@ -0,0 +1,5 @@ +{ + "name": "Should treat stringy nulls as null", + "expression": ["contains", "null", "null"], + "expects": false +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/partial-match.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/contains/partial-match.json new file mode 100644 index 000000000..1dc17e579 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/case-sensitivity.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/case-sensitivity.json new file mode 100644 index 000000000..6e63b5b21 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/empty-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/empty-string.json new file mode 100644 index 000000000..1626ffef4 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/empty-string.json @@ -0,0 +1,5 @@ +{ + "name": "All strings ends with an empty string", + "expression": ["endsWith", "Hello", ""], + "expects": true +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/ends-with-null.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/ends-with-null.json new file mode 100644 index 000000000..59e6f17eb --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/ends-with-null.json @@ -0,0 +1,5 @@ +{ + "name": "No string ends with a null", + "expression": ["endsWith", "Hello", null], + "expects": false +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/ends-with-number.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/ends-with-number.json new file mode 100644 index 000000000..e401cac5c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/ends-with.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/ends-with.json new file mode 100644 index 000000000..37fcd96e9 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/exact-match.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/exact-match.json new file mode 100644 index 000000000..1c9ced8af --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/not-ends-with.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/not-ends-with.json new file mode 100644 index 000000000..fbf25b86c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/number-ends-with-number.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/endsWith/number-ends-with-number.json new file mode 100644 index 000000000..1b2bc1b7c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/lowercase-number-should-return-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/lowercase-number-should-return-string.json new file mode 100644 index 000000000..7b6e3a1df --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/null.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/null.json new file mode 100644 index 000000000..d341f9767 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/null.json @@ -0,0 +1,5 @@ +{ + "name": "Should return a null when the input is a null", + "expression": ["lowerCase", null], + "expects": null +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/should-lowercase-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/should-lowercase-string.json new file mode 100644 index 000000000..5f38166d8 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/should-lowercase-whole-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/should-lowercase-whole-string.json new file mode 100644 index 000000000..7a90a8d22 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/should-lowercase-whole-word.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/lowerCase/should-lowercase-whole-word.json new file mode 100644 index 000000000..4b9fa972a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/case-sensitivity.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/case-sensitivity.json new file mode 100644 index 000000000..0cdf815c0 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/exact-match.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/exact-match.json new file mode 100644 index 000000000..02c5f9b68 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/not-match.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/not-match.json new file mode 100644 index 000000000..8cc79e6f4 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null.json new file mode 100644 index 000000000..206d1f058 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null.json @@ -0,0 +1,5 @@ +{ + "name": "Should always return true if the input is null", + "expression": ["notContains", null, null], + "expects": true +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null2.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null2.json new file mode 100644 index 000000000..1ff4196b4 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null2.json @@ -0,0 +1,5 @@ +{ + "name": "Should always return true if the input is null", + "expression": ["notContains", "null", null], + "expects": true +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null3.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null3.json new file mode 100644 index 000000000..b473ca2a5 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null3.json @@ -0,0 +1,5 @@ +{ + "name": "Should always return true if the input is null", + "expression": ["notContains", null, "null"], + "expects": true +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null4.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null4.json new file mode 100644 index 000000000..f0d906f8e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/notContains/null4.json @@ -0,0 +1,5 @@ +{ + "name": "Should treat stringy nulls as null", + "expression": ["notContains", "null", "null"], + "expects": true +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/nearest-integer-with-decimal-as-strings.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/nearest-integer-with-decimal-as-strings.json new file mode 100644 index 000000000..0e7d6530e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/nearest-integer-with-decimal.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/nearest-integer-with-decimal.json new file mode 100644 index 000000000..49642cf5a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/nearest-integer.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/nearest-integer.json new file mode 100644 index 000000000..5856e76c8 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-0-decimal-places.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-0-decimal-places.json new file mode 100644 index 000000000..1822cf78e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-0-decimal-places.json @@ -0,0 +1,5 @@ +{ + "name": "Should be able to round 0 to 0 decimal places", + "expression": ["round", 0, 0], + "expects": "0" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-0-decimal-places2.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-0-decimal-places2.json new file mode 100644 index 000000000..b79c24939 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-0-decimal-places2.json @@ -0,0 +1,5 @@ +{ + "name": "Should be able to round 0 to 0 decimal places", + "expression": ["round", 2.9999, 0], + "expects": "3" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-negative-number.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-negative-number.json new file mode 100644 index 000000000..63b9e5edd --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-null.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-null.json new file mode 100644 index 000000000..dc1a2c666 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-null.json @@ -0,0 +1,5 @@ +{ + "name": "Should be able to round a null", + "expression": ["round", null], + "expects": "0" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-null2.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-null2.json new file mode 100644 index 000000000..bebf3af4a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-null2.json @@ -0,0 +1,5 @@ +{ + "name": "Should be able to round a null", + "expression": ["round", null, 2], + "expects": "0.00" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-strings.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-strings.json new file mode 100644 index 000000000..b067d7253 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-with-too-many-args.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-with-too-many-args.json new file mode 100644 index 000000000..603931c73 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-with-too-many-args.json @@ -0,0 +1,5 @@ +{ + "name": "Should fail when given too many arguments", + "expression": ["round", 3.99, 2, 3], + "expectsFailure": "Expected 1-2 argument(s), got 3" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-without-decimalCount.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-without-decimalCount.json new file mode 100644 index 000000000..0bdcbef2b --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-without-decimalCount.json @@ -0,0 +1,5 @@ +{ + "name": "Should be able to round a number without the optional second argument", + "expression": ["round", "3.99"], + "expects": "4" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-without-decimalCount2.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-without-decimalCount2.json new file mode 100644 index 000000000..01b5fa64d --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/round/round-without-decimalCount2.json @@ -0,0 +1,5 @@ +{ + "name": "Should be able to round a number without the optional second argument", + "expression": ["round", 3.99], + "expects": "4" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/case-sensitivity.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/case-sensitivity.json new file mode 100644 index 000000000..c9a6c8e3c --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/empty-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/empty-string.json new file mode 100644 index 000000000..5da24b3da --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/empty-string.json @@ -0,0 +1,5 @@ +{ + "name": "All strings start with an empty string", + "expression": ["startsWith", "Hello world", ""], + "expects": true +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/exact-match.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/exact-match.json new file mode 100644 index 000000000..70c50773f --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/not-starts-with.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/not-starts-with.json new file mode 100644 index 000000000..5651cacec --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/null.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/null.json new file mode 100644 index 000000000..b088b4f16 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/null.json @@ -0,0 +1,5 @@ +{ + "name": "Should always be false when given a null", + "expression": ["startsWith", null, "null"], + "expects": false +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/null2.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/null2.json new file mode 100644 index 000000000..92656df76 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/null2.json @@ -0,0 +1,5 @@ +{ + "name": "Should always be false when given a null", + "expression": ["startsWith", null, null], + "expects": false +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/number-starts-with-number.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/number-starts-with-number.json new file mode 100644 index 000000000..5d4c14bcd --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/number-starts-with-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/number-starts-with-string.json new file mode 100644 index 000000000..f14d63a24 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/start-with-number.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/start-with-number.json new file mode 100644 index 000000000..67b58ef0e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/start-with.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/startsWith/start-with.json new file mode 100644 index 000000000..902ef4665 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/empty-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/empty-string.json new file mode 100644 index 000000000..e2249bdca --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/length-of-number.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/length-of-number.json new file mode 100644 index 000000000..5bd8f0177 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/length-of-unicode.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/length-of-unicode.json new file mode 100644 index 000000000..c9b3b9df8 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/length-of-unicode.json @@ -0,0 +1,5 @@ +{ + "name": "Should return the number of characters in a unicode string", + "expression": ["stringLength", "æøå"], + "expects": 3 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/null.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/null.json new file mode 100644 index 000000000..c4b7e2ec8 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/null.json @@ -0,0 +1,5 @@ +{ + "name": "Should return 0 when the input is a null", + "expression": ["stringLength", null], + "expects": 0 +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/string-length.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/string-length.json new file mode 100644 index 000000000..880a2ae9f --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/whitespace-length.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/stringLength/whitespace-length.json new file mode 100644 index 000000000..f77bd7b1e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/null.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/null.json new file mode 100644 index 000000000..ba4519654 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/null.json @@ -0,0 +1,5 @@ +{ + "name": "Should return a null when the input is a null", + "expression": ["upperCase", null], + "expects": null +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/should-uppercase-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/should-uppercase-string.json new file mode 100644 index 000000000..e283e4372 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/should-uppercase-whole-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/should-uppercase-whole-string.json new file mode 100644 index 000000000..844d2cbbe --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/should-uppercase-whole-word.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/should-uppercase-whole-word.json new file mode 100644 index 000000000..45dce5c18 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/uppercase-number-should-return-string.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/shared-tests/functions/upperCase/uppercase-number-should-return-string.json new file mode 100644 index 000000000..60479c63a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/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" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-confirm.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-confirm.json new file mode 100644 index 000000000..fb705002e --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-confirm.json @@ -0,0 +1,15 @@ +{ + "name": "Read/Confirm", + "expression": ["and", ["authContext", "read"], ["not", ["authContext", "write"]], ["authContext", "confirm"]], + "expects": true, + "permissions": { + "read": true, + "write": false, + "actions": { + "instantiate": true, + "confirm": true, + "sign": false, + "reject": false + } + } +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-sign-reject.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-sign-reject.json new file mode 100644 index 000000000..a65aa0a8a --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-sign-reject.json @@ -0,0 +1,15 @@ +{ + "name": "Read/Sign", + "expression": ["and", ["authContext", "read"], ["not", ["authContext", "write"]], ["authContext", "sign"], ["authContext", "reject"]], + "expects": true, + "permissions": { + "read": true, + "write": false, + "actions": { + "instantiate": true, + "confirm": false, + "sign": true, + "reject": true + } + } +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-sign.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-sign.json new file mode 100644 index 000000000..a674b8a05 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-sign.json @@ -0,0 +1,20 @@ +{ + "name": "Read/Sign", + "expression": [ + "and", + ["authContext", "read"], + ["not", ["authContext", "write"]], + ["authContext", "sign"], + ["not", ["authContext", "reject"]] + ], + "expects": true, + "permissions": { + "read": true, + "write": false, + "actions": { + "instantiate": true, + "confirm": false, + "sign": true + } + } +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-write.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-write.json new file mode 100644 index 000000000..b34438a8d --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/authContext/read-write.json @@ -0,0 +1,15 @@ +{ + "name": "Read/Write", + "expression": ["and", ["authContext", "read"], ["authContext", "write"]], + "expects": true, + "permissions": { + "read": true, + "write": true, + "actions": { + "instantiate": true, + "confirm": false, + "sign": false, + "reject": false + } + } +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-nb-if-not-set.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-nb-if-not-set.json new file mode 100644 index 000000000..d5684add6 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-nb-if-not-set.json @@ -0,0 +1,5 @@ +{ + "name": "Should default to nb if no profile is set", + "expression": ["language"], + "expects": "nb" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-profile-settings-preference.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-profile-settings-preference.json new file mode 100644 index 000000000..d97364a87 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-profile-settings-preference.json @@ -0,0 +1,8 @@ +{ + "name": "Should return profileSetting language if set", + "expression": ["language"], + "expects": "en", + "profileSettings": { + "language": "en" + } +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-selected-language.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-selected-language.json new file mode 100644 index 000000000..281943384 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/language/should-return-selected-language.json @@ -0,0 +1,5 @@ +{ + "name": "Should return 'nb' language as default", + "expression": ["language"], + "expects": "nb" +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/null.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/null.json new file mode 100644 index 000000000..fec35efc0 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/null.json @@ -0,0 +1,5 @@ +{ + "name": "Should return null when the input is null", + "expression": ["text", null], + "expects": null +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-key-name-if-key-not-exist.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-key-name-if-key-not-exist.json new file mode 100644 index 000000000..e69a1d3c9 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/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/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable-in-rep-group-no-index-markers.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable-in-rep-group-no-index-markers.json new file mode 100644 index 000000000..c6cf039f1 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable-in-rep-group-no-index-markers.json @@ -0,0 +1,114 @@ +{ + "name": "Should text resource with resolved variable inside a repeating group, without index markers", + "disabledFrontend": true, + "expression": ["text", "found.key"], + "expects": "Hello world Arne", + "context": { + "component": "myndig", + "rowIndices": [1, 0], + "currentLayout": "Page2" + }, + "textResources": [ + { + "id": "found.key", + "value": "Hello world {0}", + "variables": [ + { + "key": "Bedrifter.Ansatte.Navn", + "dataSource": "dataModel.default" + } + ] + } + ], + "layouts": { + "Page1": { + "$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json", + "data": { + "layout": [] + } + }, + "Page2": { + "$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json", + "data": { + "layout": [ + { + "id": "bedrifter", + "type": "Group", + "maxCount": 99, + "dataModelBindings": { + "group": "Bedrifter" + }, + "children": ["bedriftsNavn", "ansatte"] + }, + { + "id": "bedriftsNavn", + "type": "Input", + "dataModelBindings": { + "simpleBinding": "Bedrifter.Navn" + } + }, + { + "id": "ansatte", + "type": "Group", + "maxCount": 99, + "dataModelBindings": { + "group": "Bedrifter.Ansatte" + }, + "children": ["navn", "alder", "myndig"] + }, + { + "id": "navn", + "type": "Input", + "dataModelBindings": { + "simpleBinding": "Bedrifter.Ansatte.Navn" + } + }, + { + "id": "alder", + "type": "Input", + "dataModelBindings": { + "simpleBinding": "Bedrifter.Ansatte.Alder" + } + }, + { + "id": "myndig", + "type": "Paragraph", + "textResourceBindings": { + "title": "Hurra, den ansatte er myndig!" + } + } + ] + } + } + }, + "dataModel": { + "Bedrifter": [ + { + "Navn": "Hell og lykke AS", + "Ansatte": [ + { + "Navn": "Kaare", + "Alder": 24 + }, + { + "Navn": "Per", + "Alder": 24 + } + ] + }, + { + "Navn": "Nedtur og motgang AS", + "Ansatte": [ + { + "Navn": "Arne", + "Alder": 24 + }, + { + "Navn": "Vidar", + "Alder": 14 + } + ] + } + ] + } +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable-in-rep-group.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable-in-rep-group.json new file mode 100644 index 000000000..c6e2f1756 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable-in-rep-group.json @@ -0,0 +1,114 @@ +{ + "name": "Should text resource with resolved variable inside a repeating group", + "disabledFrontend": true, + "expression": ["text", "found.key"], + "expects": "Hello world Vidar", + "context": { + "component": "myndig", + "rowIndices": [1, 1], + "currentLayout": "Page2" + }, + "textResources": [ + { + "id": "found.key", + "value": "Hello world {0}", + "variables": [ + { + "key": "Bedrifter[{0}].Ansatte[{1}].Navn", + "dataSource": "dataModel.default" + } + ] + } + ], + "layouts": { + "Page1": { + "$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json", + "data": { + "layout": [] + } + }, + "Page2": { + "$schema": "https://altinncdn.no/schemas/json/layout/layout.schema.v1.json", + "data": { + "layout": [ + { + "id": "bedrifter", + "type": "Group", + "maxCount": 99, + "dataModelBindings": { + "group": "Bedrifter" + }, + "children": ["bedriftsNavn", "ansatte"] + }, + { + "id": "bedriftsNavn", + "type": "Input", + "dataModelBindings": { + "simpleBinding": "Bedrifter.Navn" + } + }, + { + "id": "ansatte", + "type": "Group", + "maxCount": 99, + "dataModelBindings": { + "group": "Bedrifter.Ansatte" + }, + "children": ["navn", "alder", "myndig"] + }, + { + "id": "navn", + "type": "Input", + "dataModelBindings": { + "simpleBinding": "Bedrifter.Ansatte.Navn" + } + }, + { + "id": "alder", + "type": "Input", + "dataModelBindings": { + "simpleBinding": "Bedrifter.Ansatte.Alder" + } + }, + { + "id": "myndig", + "type": "Paragraph", + "textResourceBindings": { + "title": "Hurra, den ansatte er myndig!" + } + } + ] + } + } + }, + "dataModel": { + "Bedrifter": [ + { + "Navn": "Hell og lykke AS", + "Ansatte": [ + { + "Navn": "Kaare", + "Alder": 24 + }, + { + "Navn": "Per", + "Alder": 24 + } + ] + }, + { + "Navn": "Nedtur og motgang AS", + "Ansatte": [ + { + "Navn": "Arne", + "Alder": 24 + }, + { + "Navn": "Vidar", + "Alder": 14 + } + ] + } + ] + } +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable.json new file mode 100644 index 000000000..19b5dbaa7 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource-with-variable.json @@ -0,0 +1,25 @@ +{ + "name": "Should text resource with resolved variable", + "disabledFrontend": true, + "expression": ["text", "found.key"], + "expects": "Hello world foo bar", + "textResources": [ + { + "id": "found.key", + "value": "Hello world {0}", + "variables": [ + { + "key": "My.Model.Value", + "dataSource": "dataModel.default" + } + ] + } + ], + "dataModel": { + "My": { + "Model": { + "Value": "foo bar" + } + } + } +} diff --git a/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource.json b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource.json new file mode 100644 index 000000000..06fa4cce9 --- /dev/null +++ b/test/Altinn.App.Core.Tests/LayoutExpressions/CommonTests/up-for-evaluation/functions/text/should-return-text-resource.json @@ -0,0 +1,11 @@ +{ + "name": "Should return text resource value", + "expression": ["text", "found.key"], + "expects": "Hello world", + "textResources": [ + { + "id": "found.key", + "value": "Hello world" + } + ] +}