diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/callArrayLengthFromLambda.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/callArrayLengthFromLambda.ets new file mode 100644 index 0000000000000000000000000000000000000000..036cde1455f82a16d8127cfb564376eb12d3f674 --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/callArrayLengthFromLambda.ets @@ -0,0 +1,17 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/callArrayLengthFromLambda +tags: [compile-only] +---*/ + +function callArrayLengthFromLambda() { + const cb: (arg: number) => void = + (arg: number) => { + let arr: number[] = []; + arr.length; + } +} + +function main(): void { + callArrayLengthFromLambda(); +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/callAsyncMethodFromAsyncLambda1.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/callAsyncMethodFromAsyncLambda1.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f84ce6107ba3df4ad374329f16774d76f68225b --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/callAsyncMethodFromAsyncLambda1.ets @@ -0,0 +1,30 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/callAsyncMethodFromAsyncLambda1 +tags: [] +---*/ + +type asyncLambda = () => Promise + +class LambdaTests { + async asyncFunc(): Promise { + return true; + } + + testCallAsyncLambda(): void { + let call_async_lambda = false; + + let async_lambda: asyncLambda = async (): Promise => { + await this.asyncFunc(); + call_async_lambda = true; + } + + assert(call_async_lambda == false); + await async_lambda(); + assert(call_async_lambda == true); + } +} + +function main(): void { + new LambdaTests().testCallAsyncLambda(); +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/callAsyncMethodFromAsyncLambda2.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/callAsyncMethodFromAsyncLambda2.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a5793cb82d48cf8e159e305569b28c576cd0f6e --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/callAsyncMethodFromAsyncLambda2.ets @@ -0,0 +1,28 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/callAsyncMethodFromAsyncLambda2 +tags: [] +---*/ + +type asyncLambda = () => Promise + +async function asyncFunc(): Promise { + return true; +} + +function testCallAsyncLambda(): void { + let call_async_lambda = false; + + let async_lambda: asyncLambda = async (): Promise => { + await asyncFunc(); + call_async_lambda = true; + } + + assert(call_async_lambda == false); + await async_lambda(); + assert(call_async_lambda == true); +} + +function main(): void { + testCallAsyncLambda(); +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/callMethodFromAsyncLambda1.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/callMethodFromAsyncLambda1.ets new file mode 100644 index 0000000000000000000000000000000000000000..68d4e3612fa0cf59067b27b650f950e4af248245 --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/callMethodFromAsyncLambda1.ets @@ -0,0 +1,29 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/callMethodFromAsyncLambda1 +tags: [] +---*/ + +type asyncLambda = () => Promise + +class LambdaTests { + regularFunc(): boolean { + return true; + } + + testCallFromAsyncLambdaRegularFunc(): void { + let is_call_async_lambda = false; + + let async_lambda: asyncLambda = async (): Promise => { + is_call_async_lambda = this.regularFunc(); + } + + assert(is_call_async_lambda == false); + await async_lambda(); + assert(is_call_async_lambda == true); + } +} + +function main(): void { + new LambdaTests().testCallFromAsyncLambdaRegularFunc(); +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/callMethodFromAsyncLambda2.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/callMethodFromAsyncLambda2.ets new file mode 100644 index 0000000000000000000000000000000000000000..c9a5b13e9b944ac1c555d6d423e5971f4f29d522 --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/callMethodFromAsyncLambda2.ets @@ -0,0 +1,25 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/callMethodFromAsyncLambda2 +tags: [] +---*/ + +type asyncLambda = () => Promise + +function regularFunc(): boolean { + return true; +} + +function testCallFromAsyncLambdaRegularFunc(): void { + let is_call_async_lambda = false; + let async_lambda: asyncLambda = async (): Promise => { + is_call_async_lambda = regularFunc(); + } + assert(is_call_async_lambda == false); + await async_lambda(); + assert(is_call_async_lambda == true); +} + +function main(): void { + testCallFromAsyncLambdaRegularFunc(); +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/callRegularLambda.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/callRegularLambda.ets new file mode 100644 index 0000000000000000000000000000000000000000..6dea3dda6451086e766bcffca165e44070e05efd --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/callRegularLambda.ets @@ -0,0 +1,30 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/callRegularLambda +tags: [] +---*/ + +type regularLambda = () => void + +class Test { + regularFunc(): boolean { + return true; + } + + testCallRegularLambda(): void { + let is_call_regular_lambda: boolean = false; + + let regular_lambda: regularLambda = (): void => { + this.regularFunc(); + is_call_regular_lambda = true; + } + + assert(is_call_regular_lambda == false); + regular_lambda(); + assert(is_call_regular_lambda == true); + } +} + +function main(): void { + new Test().testCallRegularLambda(); +} diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/callRegularLambdaWithAsyncOverload.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/callRegularLambdaWithAsyncOverload.ets new file mode 100644 index 0000000000000000000000000000000000000000..96ab85ae255dcc6926bdc3c2a4d3a2aa3b2a17ae --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/callRegularLambdaWithAsyncOverload.ets @@ -0,0 +1,27 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/callRegularLambdaWithAsyncOverload +tags: [] +---*/ + +class Test { + regularFunc(): boolean { + return true; + } + + async regularFunc(param: () => boolean): Promise { + return param(); + } + + callOverloadRegularFunc(): void { + let is_call_regular_func1 = await this.regularFunc((): boolean => { return true }); + assert(is_call_regular_func1 == true); + + let is_call_regular_func2 = await this.regularFunc((): boolean => { return false }); + assert(is_call_regular_func2 == false); + } +} + +function main(): void { + new Test().callOverloadRegularFunc(); +} diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/compareBooleanWithTrue.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/compareBooleanWithTrue.ets new file mode 100644 index 0000000000000000000000000000000000000000..1e92b8f446b7f6066b2a68f1405d69c538705836 --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/compareBooleanWithTrue.ets @@ -0,0 +1,23 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/compareBooleanWithTrue +tags: [] +---*/ + +type asyncLambda = () => Promise + +function regularFunc(): boolean { + return true; +} + +function main(): void { + let booleanPromise: asyncLambda = async (): Promise => { + return Promise.resolve(regularFunc()); + } + + let is_resolution1: Boolean = new Boolean(true); + assert(is_resolution1 == true); + + let is_resolution2: Boolean = booleanPromise().awaitResolution(); + assert(is_resolution2 == true); +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/incorrectAsyncLambdaReturnValue.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/incorrectAsyncLambdaReturnValue.ets new file mode 100644 index 0000000000000000000000000000000000000000..96cb893017d5e8a1b620a8b38d378c83f0081e29 --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/incorrectAsyncLambdaReturnValue.ets @@ -0,0 +1,11 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/incorrectAsyncLambdaReturnValue +tags: [negative, compile-only] +---*/ + +type fooLambda = () => void + +function main(): void { + let x: fooLambda = async (): void => {} +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/incorrectVariableDeclaration.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/incorrectVariableDeclaration.ets new file mode 100644 index 0000000000000000000000000000000000000000..f6fa058af591831c88a4b0c36df10c839d8e61ef --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/incorrectVariableDeclaration.ets @@ -0,0 +1,13 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/incorrectVariableDeclaration +tags: [negative, compile-only] +---*/ + +type fooLambda = () => int + +function foo() { + let y: int = 1; + let x = () => { return y+1 }; // must be - let x: fooLambda = () => { return y+1 }; + console.log(x()); +} diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/resultFromAwait.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/resultFromAwait.ets new file mode 100644 index 0000000000000000000000000000000000000000..b0e25eeeaa7b5930763cd1fbc82f5e2f5e6fe32e --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/resultFromAwait.ets @@ -0,0 +1,24 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/resultFromAwait +tags: [] +---*/ + +type asyncLambda = () => Promise + +function regularFunc(): boolean { + return true; +} + +function main(): void { + let booleanPromise: asyncLambda = async (): Promise => { + return Promise.resolve(regularFunc()); + } + + let is_true: Boolean = new Boolean(true); + + let is_resolution2: Boolean = await booleanPromise(); + + assert is_resolution2 instanceof Boolean; + assert(is_resolution2 == is_true); +} \ No newline at end of file diff --git a/plugins/ets/tests/ets_func_tests/spec/lambdas/resultFromAwaitResolution.ets b/plugins/ets/tests/ets_func_tests/spec/lambdas/resultFromAwaitResolution.ets new file mode 100644 index 0000000000000000000000000000000000000000..0aad7caa7b95896d7d1ab447f64159038ac3c1ab --- /dev/null +++ b/plugins/ets/tests/ets_func_tests/spec/lambdas/resultFromAwaitResolution.ets @@ -0,0 +1,24 @@ +/*--- +desc: 07.31 Lambda Expressions +name: 07.expressions/31.lambda_expressions/resultFromAwaitResolution +tags: [] +---*/ + +type asyncLambda = () => Promise + +function regularFunc(): boolean { + return true; +} + +function main(): void { + let booleanPromise: asyncLambda = async (): Promise => { + return Promise.resolve(regularFunc()); + } + + let is_true: Boolean = new Boolean(true); + + let is_resolution1: Boolean = booleanPromise().awaitResolution(); + + assert is_resolution1 instanceof Boolean; + assert(is_resolution1 == is_true); +} \ No newline at end of file diff --git a/tests/tests-u-runner/runner/plugins/ets/ets-func-tests-ignored.txt b/tests/tests-u-runner/runner/plugins/ets/ets-func-tests-ignored.txt index af134d128891ddef447c45f4d18dfb02da1e910d..d9117410f1010e9d3d57f560e4488160394a12f3 100644 --- a/tests/tests-u-runner/runner/plugins/ets/ets-func-tests-ignored.txt +++ b/tests/tests-u-runner/runner/plugins/ets/ets-func-tests-ignored.txt @@ -107,3 +107,26 @@ escompat/escompat_Array_Test_escompat_Array_003.ets std/containers/BasicMapTest.ets std/containers/BasicSetTest.ets ### Issue xxx end + +### lambda issues begin +### Issue 14018 +spec/lambdas/callArrayLengthFromLambda.ets + +### Issue 14054 +spec/lambdas/callAsyncMethodFromAsyncLambda1.ets +spec/lambdas/callMethodFromAsyncLambda1.ets + +### Issue 14209 +spec/lambdas/callAsyncMethodFromAsyncLambda2.ets +spec/lambdas/callMethodFromAsyncLambda2.ets + +### Issue 14131 +spec/lambdas/callRegularLambdaWithAsyncOverload.ets + +### Issue 14234 +spec/lambdas/resultFromAwait.ets +spec/lambdas/resultFromAwaitResolution.ets + +### Issue 14235 +spec/lambdas/compareBooleanWithTrue.ets +### lambda issues end