!2197 [ArkTS Interop-tests] : Operator "."

Merge pull request !2197 from alexanderpolenov/dot_operator
This commit is contained in:
openharmony_ci 2024-09-15 00:05:08 +00:00 committed by Gitee
commit c25dee6e08
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
20 changed files with 711 additions and 0 deletions

View File

@ -0,0 +1,15 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
add_subdirectory(sts_to_js)
add_subdirectory(ts_to_sts)

View File

@ -0,0 +1,17 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
panda_ets_interop_js_gtest(ets_interop_js__dot_operator_sts_to_js
CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/dot_operator.cpp
ETS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/dot_operator.sts
)

View File

@ -0,0 +1,31 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const {
jsInt,
CheckDotClass,
} = require('dot_operator.test');
const Obj = new CheckDotClass();
function checkCheckCallChaining() {
const expectResult = -5;
const resChaining = Obj.arr.reverse().map(i => i + jsInt).filter(i => i > jsInt).sort().reduce((a, b) => a - b);
ASSERT_TRUE(resChaining === expectResult);
}
checkCheckCallChaining();

View File

@ -0,0 +1,32 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const {
CheckDotClass,
} = require('dot_operator.test');
const Obj = new CheckDotClass();
function checkCallMethodForValue() {
ASSERT_TRUE(Obj.name.toUpperCase() !== Obj.name);
}
function checkCallMethodForValueWithOptionalOperator() {
ASSERT_TRUE(Obj?.name.toUpperCase() !== Obj.name);
}
checkCallMethodForValue();
checkCallMethodForValueWithOptionalOperator();

View File

@ -0,0 +1,27 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const {
CheckDotClass,
} = require('dot_operator.test');
const Obj = new CheckDotClass();
function checkNotNullishOperator() {
const res = Obj.age;
ASSERT_TRUE(res === undefined);
}
checkNotNullishOperator();

View File

@ -0,0 +1,39 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "ets_interop_js_gtest.h"
namespace ark::ets::interop::js::testing {
class EtsDotOperatorEtsToJsTest : public EtsInteropTest {};
TEST_F(EtsDotOperatorEtsToJsTest, check_call_chaining)
{
ASSERT_TRUE(RunJsTestSuite("check_call_chaining.js"));
}
TEST_F(EtsDotOperatorEtsToJsTest, check_call_method_for_value)
{
ASSERT_TRUE(RunJsTestSuite("check_call_method_for_value.js"));
}
TEST_F(EtsDotOperatorEtsToJsTest, check_not_nullish_operator)
{
ASSERT_TRUE(RunJsTestSuite("check_not_nullish_operator.js"));
}
} // namespace ark::ets::interop::js::testing

View File

@ -0,0 +1,24 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dot_operator.test;
class CheckDotClass {
name = 'test';
sum = (arg: int): int => arg;
arr = [1,2,3];
age?: int;
secondName?: string
}

View File

@ -0,0 +1,27 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const stsVm = require('lib/module/ets_interop_js_napi');
const jsInt = 1;
const jsString = 'Test';
const CheckDotClass = stsVm.getClass('Ldot_operator/test/CheckDotClass;');
module.exports = {
jsInt,
jsString,
CheckDotClass,
};

View File

@ -0,0 +1,39 @@
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set(ETS_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/arktsconfig.json)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/arktsconfig.in.json ${ETS_CONFIG})
panda_ets_interop_js_gtest(ets_interop_js__optional_operator_ts_to_sts
CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/optional_operator/optional_operator.cpp
ETS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/optional_operator/optional_operator.sts
ETS_CONFIG ${ETS_CONFIG}
)
panda_ets_interop_js_gtest(ets_interop_js__not_nullish_operator_ts_to_sts
CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/not_nullish_operator/not_nullish_operator.cpp
ETS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/not_nullish_operator/not_nullish_operator.sts
ETS_CONFIG ${ETS_CONFIG}
)
panda_ets_interop_js_gtest(ets_interop_js__call_method_for_value_ts_to_sts
CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/call_method_for_value/call_method_for_value.cpp
ETS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/call_method_for_value/call_method_for_value.sts
ETS_CONFIG ${ETS_CONFIG}
)
panda_ets_interop_js_gtest(ets_interop_js__call_chaining_ts_to_sts
CPP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/call_chaining/call_chaining.cpp
ETS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/call_chaining/call_chaining.sts
ETS_CONFIG ${ETS_CONFIG}
)

View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"baseUrl": "${PANDA_ROOT}",
"paths": {
"escompat": [
"${PANDA_ROOT}/plugins/ets/stdlib/escompat"
],
"std": [
"${PANDA_ROOT}/plugins/ets/stdlib/std"
],
"main_js": [
"${CMAKE_CURRENT_SOURCE_DIR}/main.js"
]
},
"dynamicPaths": {
"${CMAKE_CURRENT_SOURCE_DIR}/main.js": {
"language": "js",
"hasDecl": false
}
}
}
}

View File

@ -0,0 +1,28 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "ets_interop_js_gtest.h"
namespace ark::ets::interop::js::testing {
class EtsCallChainingTsToEtsTest : public EtsInteropTest {};
// NOTE (alexanderpolenov) issue(18450) enable this after fix call chain
TEST_F(EtsCallChainingTsToEtsTest, DISABLED_checkCallChaining)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkCallChaining"));
}
} // namespace ark::ets::interop::js::testing

View File

@ -0,0 +1,26 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
tsInt,
Obj,
} from 'main_js';
// function checkCallChaining(): boolean {
// const expectResult = -5;
// const resChaining = Obj.arr.reverse().map((i) => i + tsInt).filter(i => i > tsInt).sort().reduce((a, b) => a - b);
// return resChaining as int == expectResult as int;
// }

View File

@ -0,0 +1,38 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "ets_interop_js_gtest.h"
namespace ark::ets::interop::js::testing {
class EtsCallMethodForValueTsToEtsTest : public EtsInteropTest {};
TEST_F(EtsCallMethodForValueTsToEtsTest, checkCallMethodForValue)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkCallMethodForValue"));
}
TEST_F(EtsCallMethodForValueTsToEtsTest, checkCallMethodForValueWithOptionalOperator)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkCallMethodForValueWithOptionalOperator"));
}
// NOTE (alexanderpolenov) issue(18449) enable this after fix non null operator
TEST_F(EtsCallMethodForValueTsToEtsTest, DISABLED_checkCallMethodForValueWithNotNullishOperator)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkCallMethodForValueWithNotNullishOperator"));
}
} // namespace ark::ets::interop::js::testing

View File

@ -0,0 +1,34 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
tsString,
Obj,
notNullishObj,
} from 'main_js';
function checkCallMethodForValue(): boolean {
return Obj.name.toUpperCase() as string !== Obj.name as string;
}
function checkCallMethodForValueWithOptionalOperator(): boolean {
return Obj?.name.toUpperCase() as string !== Obj.name as string;
}
// NOTE (alexanderpolenov) issue(18449) enable this after fix non null operator
// function checkCallMethodForValueWithNotNullishOperator(): boolean {
// notNullishObg.name = tsString;
//
// return notNullishObj.name.toUpperCase()! as string !== Obj.name as string;
// }

View File

@ -0,0 +1,30 @@
'use strict';
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, '__esModule', { value: true });
exports.notNullishObj = exports.Obj = exports.tsString = exports.tsInt = void 0;
exports.tsInt = 1;
exports.tsString = 'string';
exports.Obj = {
name: 'test',
inside: {
name: 'test'
},
sum: function () { return exports.tsInt; },
arr: [1, 2, 3]
};
exports.notNullishObj = {
secondName: null,
};

View File

@ -0,0 +1,34 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const tsInt = 1;
export const tsString = 'string';
export const Obj = {
name: 'test',
inside: {
name: 'test',
},
sum: (): number => tsInt,
arr: [1, 2, 3],
};
type OptionalProp = {
name?: string,
secondName: null | undefined
};
export const notNullishObj: OptionalProp = {
secondName: null,
};

View File

@ -0,0 +1,33 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "ets_interop_js_gtest.h"
namespace ark::ets::interop::js::testing {
class EtsNotNullishOperatorTsToEtsTest : public EtsInteropTest {};
// NOTE (alexanderpolenov) issue(18449) enable this after fix non null operator
TEST_F(EtsNotNullishOperatorTsToEtsTest, DISABLED_checkNotNullishOperator)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkNotNullishOperator"));
}
// NOTE (alexanderpolenov) issue(18449) enable this after fix non null operator
TEST_F(EtsNotNullishOperatorTsToEtsTest, DISABLED_checkNotNullishOperatorError)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkNotNullishOperatorError"));
}
} // namespace ark::ets::interop::js::testing

View File

@ -0,0 +1,45 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
tsString,
notNullishObj
} from 'main_js';
class PublicGetterClass {
_value = tsString;
test: null | undefined//NullishType
get value(): string {
return this._value;
}
}
// NOTE (alexanderpolenov) issue(18449) enable this after fix non null operator
// function checkNotNullishOperator(): boolean {
// notNullishObj.name = tsString;
// return notNullishObj.name! as string == tsString as string
// }
// NOTE (alexanderpolenov) issue(18449) enable this after fix non null operator
// function checkNotNullishOperatorError(): boolean {
// try {
// notNullishObj.secondName!;
// return false;
// } catch (e) {
// return true;
// }
// }

View File

@ -0,0 +1,83 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include "ets_interop_js_gtest.h"
namespace ark::ets::interop::js::testing {
class EtsOptionalOperatorTsToEtsTest : public EtsInteropTest {};
TEST_F(EtsOptionalOperatorTsToEtsTest, checkOptionalOperatorWithValue)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkOptionalOperatorWithValue"));
}
// NOTE (17745) - enable after fix alias undefined
TEST_F(EtsOptionalOperatorTsToEtsTest, DISABLED_checkOptionalOperatorReturnUndefined)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkOptionalOperatorReturnUndefined"));
}
// NOTE: (alexanderpolenov) issue(18238) access by string index
TEST_F(EtsOptionalOperatorTsToEtsTest, DISABLED_check_optional_operator_with_value_by_string_index)
{
ASSERT_EQ(true, CallEtsMethod<bool>("check_optional_operator_with_value_by_string_index"));
}
// NOTE: (alexanderpolenov) issue(18238) access by string index
TEST_F(EtsOptionalOperatorTsToEtsTest, DISABLED_checkOptionalOperatorReturnUndefined_by_string_index)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkOptionalOperatorReturnUndefined_by_string_index"));
}
TEST_F(EtsOptionalOperatorTsToEtsTest, checkOptionalOperatorInsideObjectWithValue)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkOptionalOperatorInsideObjectWithValue"));
}
// NOTE (17745) - enable after fix alias undefined
TEST_F(EtsOptionalOperatorTsToEtsTest, DISABLED_checkOptionalOperatorInsideObjectReturnUndefined)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkOptionalOperatorInsideObjectReturnUndefined"));
}
// NOTE: (alexanderpolenov) issue(18238) access by string index
TEST_F(EtsOptionalOperatorTsToEtsTest, DISABLED_checkOptionalOperatorInsideObjectWithValueByStringIndex)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkOptionalOperatorInsideObjectWithValueByStringIndex"));
}
// NOTE: (alexanderpolenov) issue(18238) access by string index
TEST_F(EtsOptionalOperatorTsToEtsTest, DISABLED_checkOptionalOperatorInsideReturnUndefinedByStringIndex)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkOptionalOperatorInsideReturnUndefinedByStringIndex"));
}
// NOTE (alexanderpolenov) issue(18447) enable after fix call function with ?. operator
TEST_F(EtsOptionalOperatorTsToEtsTest, DISABLED_checkOptionalOperatorFunction)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkOptionalOperatorFunction"));
}
TEST_F(EtsOptionalOperatorTsToEtsTest, checkOptionalOperatorFunctionUndefined)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkOptionalOperatorFunctionUndefined"));
}
// NOTE: (alexanderpolenov) issue(18238) access by string index
TEST_F(EtsOptionalOperatorTsToEtsTest, DISABLED_checkOptionalOperatorFunctionByStringIndex)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkOptionalOperatorFunctionByStringIndex"));
}
// NOTE: (alexanderpolenov) issue(18238) access by string index
TEST_F(EtsOptionalOperatorTsToEtsTest, DISABLED_checkOptionalOperatorFunctionReturnUndefinedByStringIndex)
{
ASSERT_EQ(true, CallEtsMethod<bool>("checkOptionalOperatorFunctionReturnUndefinedByStringIndex"));
}
} // namespace ark::ets::interop::js::testing

View File

@ -0,0 +1,87 @@
/**
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
tsInt,
Obj
} from 'main_js';
function checkOptionalOperatorWithValue(): boolean {
return Obj?.name as string == Obj.name as string;
}
function checkOptionalOperatorReturnUndefined(): boolean {
const res: undefined = Obj?.test as undefined;
return res == undefined;
}
// NOTE: (alexanderpolenov) issue(18238) access by string index
// function check_optional_operator_with_value_by_string_index(): boolean {
// return Obj?.['name'] as string == Obj.name as string;
// }
// function checkOptionalOperatorReturnUndefined_by_string_index(): boolean {
// const res: undefined = Obj?.['test'] as undefined;
// return res == undefined;
// }
function checkOptionalOperatorInsideObjectWithValue(): boolean {
return Obj.inside?.name as string == Obj.inside.name as string;
}
function checkOptionalOperatorInsideObjectReturnUndefined(): boolean {
const res: undefined = Obj.inside?.test as undefined;
return res == undefined;
}
// NOTE: (alexanderpolenov) issue(18238) access by string index
// function checkOptionalOperatorInsideObjectWithValueByStringIndex(): boolean {
// return Obj.inside?.['name'] as string == Obj.name as string;
// }
// function checkOptionalOperatorInsideReturnUndefinedByStringIndex(): boolean {
// const res: undefined = Obj.inside?.['test'] as undefined;
// return res == undefined;
// }
// NOTE (alexanderpolenov) issue(18447) enable after fix call function with ?. operator
// function checkOptionalOperatorFunction(): boolean {
// return Obj?.sum() as int == tsInt as int;
// }
function checkOptionalOperatorFunctionUndefined(): boolean {
try{
Obj?.test();
return false;
}catch(e){
return true;
}
}
// NOTE: (alexanderpolenov) issue(18238) access by string index
// function checkOptionalOperatorFunctionByStringIndex(): boolean {
// return Obj?.['sum']() as int == tsInt as int;
// }
// function checkOptionalOperatorFunctionReturnUndefinedByStringIndex(): boolean {
// try{
// Obj?.['test']();
// return false;
// }catch(e){
// return true;
// }
// }