Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: AdaptiveExpressions: Allow 0 to convert as false bool #3801

Merged
merged 1 commit into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libraries/adaptive-expressions/src/builtinFunctions/bool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class Bool extends ComparisonEvaluator {
* @private
*/
private static func(args: any[]): boolean {
if (FunctionUtils.isNumber(args[0])) {
return args[0] !== 0;
}

return InternalFunctionUtils.isLogicTrue(args[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ const testCases = [
['equals(max(createArray(1,2,3,4), 5.0), 5)', true],
['equals(bag.index, 2)', false],
['equals(hello == \'world\', bool(\'true\'))', false],
['equals(hello == \'world\', bool(0))', false],
['equals(hello == \'world\', bool(0))', true],
['equals(hello == \'world\', bool(1))', false],
['if(!exists(one), \'r1\', \'r2\')', 'r2'],
['if(!!exists(one), \'r1\', \'r2\')', 'r1'],
['if(0, \'r1\', \'r2\')', 'r1'],
Expand Down Expand Up @@ -415,23 +416,23 @@ const testCases = [
['string(bool(1))', 'true'],
['string(bag.set)', '{"four":4}'], // ts-->"{\"four\":4}", C# --> "{\"four\":4.0}"
['bool(1)', true],
['bool(0)', true],
['bool(0)', false],
['bool(null)', false],
['bool(hello * 5)', false],
['bool(\'false\')', true], // we make it true, because it is not empty
['bool(\'hi\')', true],
['[1,2,3]', [1, 2, 3]],
['[1,2,3, [4,5]]', [1, 2, 3, [4, 5]]],
['"[1,2,3]"', '[1,2,3]'],
['[1, bool(0), string(bool(1)), float(\'10\')]', [1, true, 'true', 10.0]],
['[1, bool(0), string(bool(1)), float(\'10\')]', [1, false, 'true', 10.0]],
['[\'a\', \'b[]\', \'c[][][]\'][1]', 'b[]'],
['[\'a\', [\'b\', \'c\']][1][0]', 'b'],
['union(["a", "b", "c"], ["d", ["e", "f"], "g"][1])', ['a', 'b', 'c', 'e', 'f']],
['union(["a", "b", "c"], ["d", ["e", "f"], "g"][1])[1]', 'b'],
['createArray(\'h\', \'e\', \'l\', \'l\', \'o\')', ['h', 'e', 'l', 'l', 'o']],
['createArray()', []],
['[]', []],
['createArray(1, bool(0), string(bool(1)), float(\'10\'))', [1, true, 'true', 10.0]],
['createArray(1, bool(0), string(bool(1)), float(\'10\'))', [1, false, 'true', 10.0]],
['binary(hello)', new Uint8Array([104, 101, 108, 108, 111])],
['dataUri(hello)', 'data:text/plain;charset=utf-8;base64,aGVsbG8='],
['count(binary(hello))', 5],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
{
"$kind": "Microsoft.SetProperty",
"property": "turn.interrupted",
"value": "=false"
"value": "=bool(0)"
}
]
}
Expand Down Expand Up @@ -107,4 +107,4 @@
"text": "I have 36 as your age"
}
]
}
}