13af6ab5fSopenharmony_ci/** 23af6ab5fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci * You may obtain a copy of the License at 63af6ab5fSopenharmony_ci * 73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci * 93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci * limitations under the License. 143af6ab5fSopenharmony_ci */ 153af6ab5fSopenharmony_ci 163af6ab5fSopenharmony_ci#include "ast_verifier_test.h" 173af6ab5fSopenharmony_ci#include "macros.h" 183af6ab5fSopenharmony_ci#include "util/ast-builders/classDefinitionBuilder.h" 193af6ab5fSopenharmony_ci#include "util/ast-builders/binaryExpressionBuilder.h" 203af6ab5fSopenharmony_ci#include "util/ast-builders/classPropertyBuilder.h" 213af6ab5fSopenharmony_ci#include "util/ast-builders/identifierBuilder.h" 223af6ab5fSopenharmony_ci#include "util/ast-builders/numberLiteralBuilder.h" 233af6ab5fSopenharmony_ci#include "util/ast-builders/awaitExpressionBuilder.h" 243af6ab5fSopenharmony_ci#include "util/ast-builders/bigintLiteralBuilder.h" 253af6ab5fSopenharmony_ci#include "util/ast-builders/blockExpressionBuilder.h" 263af6ab5fSopenharmony_ci#include "util/ast-builders/blockStatementBuilder.h" 273af6ab5fSopenharmony_ci#include "util/ast-builders/booleanLiteralBuilder.h" 283af6ab5fSopenharmony_ci#include "util/ast-builders/breakStatementBuilder.h" 293af6ab5fSopenharmony_ci#include "util/ast-builders/callExpressionBuilder.h" 303af6ab5fSopenharmony_ci#include "util/ast-builders/superExpressionBuilder.h" 313af6ab5fSopenharmony_ci#include "util/ast-builders/charLiteralBuilder.h" 323af6ab5fSopenharmony_ci#include "util/ast-builders/classDeclarationBuilder.h" 333af6ab5fSopenharmony_ci#include "util/ast-builders/etsTypeReferenceBuilder.h" 343af6ab5fSopenharmony_ci#include "util/ast-builders/etsTypeReferencePartBuilder.h" 353af6ab5fSopenharmony_ci#include "util/ast-builders/exportDefaultDeclarationBuilder.h" 363af6ab5fSopenharmony_ci#include "util/ast-builders/expressionStatementBuilder.h" 373af6ab5fSopenharmony_ci#include "util/ast-builders/ifStatementBuilder.h" 383af6ab5fSopenharmony_ci#include "util/ast-builders/importDeclarationBuilder.h" 393af6ab5fSopenharmony_ci#include "util/ast-builders/importSpecifierBuilder.h" 403af6ab5fSopenharmony_ci#include "util/ast-builders/memberExpressionBuilder.h" 413af6ab5fSopenharmony_ci#include "util/ast-builders/thisExpressionBuilder.h" 423af6ab5fSopenharmony_ci#include "util/ast-builders/methodDefinitionBuilder.h" 433af6ab5fSopenharmony_ci#include "util/ast-builders/functionExpressionBuilder.h" 443af6ab5fSopenharmony_ci#include "util/ast-builders/scriptFunctionBuilder.h" 453af6ab5fSopenharmony_ci#include "util/ast-builders/stringLiteralBuilder.h" 463af6ab5fSopenharmony_ci#include "util/ast-builders/switchStatementBuilder.h" 473af6ab5fSopenharmony_ci#include "util/ast-builders/tsClassImplementsBuilder.h" 483af6ab5fSopenharmony_ci#include "util/ast-builders/tsEnumDeclarationBuilder.h" 493af6ab5fSopenharmony_ci#include "util/ast-builders/tsEnumMemberBuilder.h" 503af6ab5fSopenharmony_ci#include "util/ast-builders/tsTypeParameterInstantiationBuilder.h" 513af6ab5fSopenharmony_ci#include "util/ast-builders/unaryExpressionBuilder.h" 523af6ab5fSopenharmony_ci#include "util/ast-builders/undefinedLiteralBuilder.h" 533af6ab5fSopenharmony_ci#include "util/ast-builders/updateExpressionBuilder.h" 543af6ab5fSopenharmony_ci#include "util/ast-builders/variableDeclarationBuilder.h" 553af6ab5fSopenharmony_ci#include "util/ast-builders/variableDeclaratorBuilder.h" 563af6ab5fSopenharmony_ci#include "util/ast-builders/whileStatementBuilder.h" 573af6ab5fSopenharmony_ci#include "util/ast-builders/switchCaseStatementBuilder.h" 583af6ab5fSopenharmony_ci 593af6ab5fSopenharmony_ci#include <gtest/gtest.h> 603af6ab5fSopenharmony_ci 613af6ab5fSopenharmony_ciusing ark::es2panda::compiler::ast_verifier::InvariantNameSet; 623af6ab5fSopenharmony_ciusing ark::es2panda::ir::AwaitExpressionBuilder; 633af6ab5fSopenharmony_ciusing ark::es2panda::ir::BigIntLiteralBuilder; 643af6ab5fSopenharmony_ciusing ark::es2panda::ir::BinaryExpressionBuilder; 653af6ab5fSopenharmony_ciusing ark::es2panda::ir::BlockExpressionBuilder; 663af6ab5fSopenharmony_ciusing ark::es2panda::ir::BlockStatementBuilder; 673af6ab5fSopenharmony_ciusing ark::es2panda::ir::BooleanLiteralBuilder; 683af6ab5fSopenharmony_ciusing ark::es2panda::ir::BreakStatementBuilder; 693af6ab5fSopenharmony_ciusing ark::es2panda::ir::CallExpressionBuilder; 703af6ab5fSopenharmony_ciusing ark::es2panda::ir::CharLiteralBuilder; 713af6ab5fSopenharmony_ciusing ark::es2panda::ir::ClassDeclarationBuilder; 723af6ab5fSopenharmony_ciusing ark::es2panda::ir::ClassDefinitionBuilder; 733af6ab5fSopenharmony_ciusing ark::es2panda::ir::ClassPropertyBuilder; 743af6ab5fSopenharmony_ciusing ark::es2panda::ir::ETSTypeReferenceBuilder; 753af6ab5fSopenharmony_ciusing ark::es2panda::ir::ETSTypeReferencePartBuilder; 763af6ab5fSopenharmony_ciusing ark::es2panda::ir::ExportDefaultDeclarationBuilder; 773af6ab5fSopenharmony_ciusing ark::es2panda::ir::ExpressionStatementBuilder; 783af6ab5fSopenharmony_ciusing ark::es2panda::ir::FunctionExpressionBuilder; 793af6ab5fSopenharmony_ciusing ark::es2panda::ir::IdentifierBuilder; 803af6ab5fSopenharmony_ciusing ark::es2panda::ir::IfStatementBuilder; 813af6ab5fSopenharmony_ciusing ark::es2panda::ir::ImportDeclarationBuilder; 823af6ab5fSopenharmony_ciusing ark::es2panda::ir::ImportSpecifierBuilder; 833af6ab5fSopenharmony_ciusing ark::es2panda::ir::MemberExpressionBuilder; 843af6ab5fSopenharmony_ciusing ark::es2panda::ir::MethodDefinitionBuilder; 853af6ab5fSopenharmony_ciusing ark::es2panda::ir::NumberLiteralBuilder; 863af6ab5fSopenharmony_ciusing ark::es2panda::ir::ScriptFunctionBuilder; 873af6ab5fSopenharmony_ciusing ark::es2panda::ir::StringLiteralBuilder; 883af6ab5fSopenharmony_ciusing ark::es2panda::ir::SuperExpressionBuilder; 893af6ab5fSopenharmony_ciusing ark::es2panda::ir::SwitchCaseStatementBuilder; 903af6ab5fSopenharmony_ciusing ark::es2panda::ir::SwitchStatementBuilder; 913af6ab5fSopenharmony_ciusing ark::es2panda::ir::ThisExpressionBuilder; 923af6ab5fSopenharmony_ciusing ark::es2panda::ir::TSClassImplementsBuilder; 933af6ab5fSopenharmony_ciusing ark::es2panda::ir::TSEnumDeclarationBuilder; 943af6ab5fSopenharmony_ciusing ark::es2panda::ir::TSEnumMemberBuilder; 953af6ab5fSopenharmony_ciusing ark::es2panda::ir::TSTypeParameterInstantiationBuilder; 963af6ab5fSopenharmony_ciusing ark::es2panda::ir::UnaryExpressionBuilder; 973af6ab5fSopenharmony_ciusing ark::es2panda::ir::UndefinedLiteralBuilder; 983af6ab5fSopenharmony_ciusing ark::es2panda::ir::UpdateExpressionBuilder; 993af6ab5fSopenharmony_ciusing ark::es2panda::ir::VariableDeclarationBuilder; 1003af6ab5fSopenharmony_ciusing ark::es2panda::ir::VariableDeclaratorBuilder; 1013af6ab5fSopenharmony_ciusing ark::es2panda::ir::WhileStatementBuilder; 1023af6ab5fSopenharmony_ci 1033af6ab5fSopenharmony_cinamespace { 1043af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, arrowFunctionExpressionBuild) 1053af6ab5fSopenharmony_ci{ 1063af6ab5fSopenharmony_ci auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 1073af6ab5fSopenharmony_ci auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 1083af6ab5fSopenharmony_ci auto binaryExpr = BinaryExpressionBuilder(Allocator()) 1093af6ab5fSopenharmony_ci .SetLeft(left) 1103af6ab5fSopenharmony_ci .SetRight(right) 1113af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 1123af6ab5fSopenharmony_ci .Build(); 1133af6ab5fSopenharmony_ci auto awaitExpr = AwaitExpressionBuilder(Allocator()).SetArgument(binaryExpr).Build(); 1143af6ab5fSopenharmony_ci ASSERT_TRUE(awaitExpr->IsAwaitExpression()); 1153af6ab5fSopenharmony_ci} 1163af6ab5fSopenharmony_ci 1173af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, awaitExpressionBuild) 1183af6ab5fSopenharmony_ci{ 1193af6ab5fSopenharmony_ci auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 1203af6ab5fSopenharmony_ci auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 1213af6ab5fSopenharmony_ci auto binaryExpr = BinaryExpressionBuilder(Allocator()) 1223af6ab5fSopenharmony_ci .SetLeft(left) 1233af6ab5fSopenharmony_ci .SetRight(right) 1243af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 1253af6ab5fSopenharmony_ci .Build(); 1263af6ab5fSopenharmony_ci auto awaitExpr = AwaitExpressionBuilder(Allocator()).SetArgument(binaryExpr).Build(); 1273af6ab5fSopenharmony_ci ASSERT_TRUE(awaitExpr->IsAwaitExpression()); 1283af6ab5fSopenharmony_ci} 1293af6ab5fSopenharmony_ci 1303af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, bigintLiteralBuild) 1313af6ab5fSopenharmony_ci{ 1323af6ab5fSopenharmony_ci auto bigint = BigIntLiteralBuilder(Allocator()).SetValue("123").Build(); 1333af6ab5fSopenharmony_ci ASSERT_TRUE(bigint->IsBigIntLiteral()); 1343af6ab5fSopenharmony_ci} 1353af6ab5fSopenharmony_ci 1363af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, binaryExpressionBuild) 1373af6ab5fSopenharmony_ci{ 1383af6ab5fSopenharmony_ci auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 1393af6ab5fSopenharmony_ci auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 1403af6ab5fSopenharmony_ci auto binaryExpr = BinaryExpressionBuilder(Allocator()) 1413af6ab5fSopenharmony_ci .SetLeft(left) 1423af6ab5fSopenharmony_ci .SetRight(right) 1433af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 1443af6ab5fSopenharmony_ci .Build(); 1453af6ab5fSopenharmony_ci ASSERT_TRUE(binaryExpr->IsBinaryExpression()); 1463af6ab5fSopenharmony_ci} 1473af6ab5fSopenharmony_ci 1483af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, blockExpressionBuild) 1493af6ab5fSopenharmony_ci{ 1503af6ab5fSopenharmony_ci auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 1513af6ab5fSopenharmony_ci auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 1523af6ab5fSopenharmony_ci auto binaryExpr = BinaryExpressionBuilder(Allocator()) 1533af6ab5fSopenharmony_ci .SetLeft(left) 1543af6ab5fSopenharmony_ci .SetRight(right) 1553af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 1563af6ab5fSopenharmony_ci .Build(); 1573af6ab5fSopenharmony_ci auto exprStmnt = ExpressionStatementBuilder(Allocator()).SetExpression(binaryExpr).Build(); 1583af6ab5fSopenharmony_ci auto blockExpr = BlockExpressionBuilder(Allocator()).AddStatement(exprStmnt).Build(); 1593af6ab5fSopenharmony_ci ASSERT_TRUE(blockExpr->IsBlockExpression()); 1603af6ab5fSopenharmony_ci} 1613af6ab5fSopenharmony_ci 1623af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, blockStatementBuild) 1633af6ab5fSopenharmony_ci{ 1643af6ab5fSopenharmony_ci auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 1653af6ab5fSopenharmony_ci auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 1663af6ab5fSopenharmony_ci auto binaryExpr = BinaryExpressionBuilder(Allocator()) 1673af6ab5fSopenharmony_ci .SetLeft(left) 1683af6ab5fSopenharmony_ci .SetRight(right) 1693af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 1703af6ab5fSopenharmony_ci .Build(); 1713af6ab5fSopenharmony_ci auto exprStmnt = ExpressionStatementBuilder(Allocator()).SetExpression(binaryExpr).Build(); 1723af6ab5fSopenharmony_ci auto blockStmnt = BlockStatementBuilder(Allocator()).AddStatement(exprStmnt).Build(); 1733af6ab5fSopenharmony_ci ASSERT_TRUE(blockStmnt->IsBlockStatement()); 1743af6ab5fSopenharmony_ci} 1753af6ab5fSopenharmony_ci 1763af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, booleanLiteralBuild) 1773af6ab5fSopenharmony_ci{ 1783af6ab5fSopenharmony_ci auto boolLiteral = BooleanLiteralBuilder(Allocator()).SetValue(true).Build(); 1793af6ab5fSopenharmony_ci ASSERT_TRUE(boolLiteral->IsBooleanLiteral()); 1803af6ab5fSopenharmony_ci} 1813af6ab5fSopenharmony_ci 1823af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, breakStatementBuild) 1833af6ab5fSopenharmony_ci{ 1843af6ab5fSopenharmony_ci auto breakStmnt = BreakStatementBuilder(Allocator()).Build(); 1853af6ab5fSopenharmony_ci ASSERT_TRUE(breakStmnt->IsBreakStatement()); 1863af6ab5fSopenharmony_ci} 1873af6ab5fSopenharmony_ci 1883af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, callExpressionBuild) 1893af6ab5fSopenharmony_ci{ 1903af6ab5fSopenharmony_ci auto superExpr = SuperExpressionBuilder(Allocator()).Build(); 1913af6ab5fSopenharmony_ci auto callExpr = CallExpressionBuilder(Allocator()).SetCallee(superExpr).Build(); 1923af6ab5fSopenharmony_ci ASSERT_TRUE(callExpr->IsCallExpression()); 1933af6ab5fSopenharmony_ci} 1943af6ab5fSopenharmony_ci 1953af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, charLiteralBuild) 1963af6ab5fSopenharmony_ci{ 1973af6ab5fSopenharmony_ci // Create char literal with default value u0000 1983af6ab5fSopenharmony_ci auto charLiteral = CharLiteralBuilder(Allocator()).Build(); 1993af6ab5fSopenharmony_ci ASSERT_TRUE(charLiteral->IsCharLiteral()); 2003af6ab5fSopenharmony_ci} 2013af6ab5fSopenharmony_ci 2023af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, classDeclarationBuild) 2033af6ab5fSopenharmony_ci{ 2043af6ab5fSopenharmony_ci auto id = IdentifierBuilder(Allocator()).SetName("a").Build(); 2053af6ab5fSopenharmony_ci auto number = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 2063af6ab5fSopenharmony_ci auto classProperty = ClassPropertyBuilder(Allocator()) 2073af6ab5fSopenharmony_ci .SetKey(id) 2083af6ab5fSopenharmony_ci .SetValue(number) 2093af6ab5fSopenharmony_ci .AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE) 2103af6ab5fSopenharmony_ci .Build(); 2113af6ab5fSopenharmony_ci 2123af6ab5fSopenharmony_ci auto classId = IdentifierBuilder(Allocator()).SetName("A").Build(); 2133af6ab5fSopenharmony_ci auto classDef = ClassDefinitionBuilder(Allocator()).SetIdentifier(classId).AddProperty(classProperty).Build(); 2143af6ab5fSopenharmony_ci auto classDecl = ClassDeclarationBuilder(Allocator()).SetDefinition(classDef).Build(); 2153af6ab5fSopenharmony_ci ASSERT_TRUE(classDecl->IsClassDeclaration()); 2163af6ab5fSopenharmony_ci} 2173af6ab5fSopenharmony_ci 2183af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, etsTypeReferenceBuild) 2193af6ab5fSopenharmony_ci{ 2203af6ab5fSopenharmony_ci auto id = IdentifierBuilder(Allocator()).SetName("a").Build(); 2213af6ab5fSopenharmony_ci auto etsTypeReferencePart = 2223af6ab5fSopenharmony_ci ETSTypeReferencePartBuilder(Allocator()).SetName(id).SetTypeParams(nullptr).SetPrev(nullptr).Build(); 2233af6ab5fSopenharmony_ci auto etsTypeReference = ETSTypeReferenceBuilder(Allocator()).SetETSTypeReferencePart(etsTypeReferencePart).Build(); 2243af6ab5fSopenharmony_ci ASSERT_TRUE(etsTypeReference->IsETSTypeReference()); 2253af6ab5fSopenharmony_ci} 2263af6ab5fSopenharmony_ci 2273af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, exportDefaultDeclarationBuild) 2283af6ab5fSopenharmony_ci{ 2293af6ab5fSopenharmony_ci auto idParent = IdentifierBuilder(Allocator()).SetName("parent").Build(); 2303af6ab5fSopenharmony_ci auto id = IdentifierBuilder(Allocator()).SetName("a").SetParent<IdentifierBuilder>(idParent).Build(); 2313af6ab5fSopenharmony_ci auto number = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 2323af6ab5fSopenharmony_ci auto classProperty = ClassPropertyBuilder(Allocator()) 2333af6ab5fSopenharmony_ci .SetKey(id) 2343af6ab5fSopenharmony_ci .SetValue(number) 2353af6ab5fSopenharmony_ci .AddModifier(ark::es2panda::ir::ModifierFlags::PRIVATE) 2363af6ab5fSopenharmony_ci .Build(); 2373af6ab5fSopenharmony_ci 2383af6ab5fSopenharmony_ci auto classId = IdentifierBuilder(Allocator()).SetName("A").Build(); 2393af6ab5fSopenharmony_ci auto classDef = ClassDefinitionBuilder(Allocator()).SetIdentifier(classId).AddProperty(classProperty).Build(); 2403af6ab5fSopenharmony_ci auto classDecl = ClassDeclarationBuilder(Allocator()).SetDefinition(classDef).Build(); 2413af6ab5fSopenharmony_ci auto exportDefaultDecl = 2423af6ab5fSopenharmony_ci ExportDefaultDeclarationBuilder(Allocator()).SetDeclaration(classDecl).SetExportEquals(true).Build(); 2433af6ab5fSopenharmony_ci ASSERT_TRUE(exportDefaultDecl->IsExportDefaultDeclaration()); 2443af6ab5fSopenharmony_ci} 2453af6ab5fSopenharmony_ci 2463af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, expressionStatementBuild) 2473af6ab5fSopenharmony_ci{ 2483af6ab5fSopenharmony_ci auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 2493af6ab5fSopenharmony_ci auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 2503af6ab5fSopenharmony_ci auto binaryExpr = BinaryExpressionBuilder(Allocator()) 2513af6ab5fSopenharmony_ci .SetLeft(left) 2523af6ab5fSopenharmony_ci .SetRight(right) 2533af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 2543af6ab5fSopenharmony_ci .Build(); 2553af6ab5fSopenharmony_ci auto exprStmnt = ExpressionStatementBuilder(Allocator()).SetExpression(binaryExpr).Build(); 2563af6ab5fSopenharmony_ci ASSERT_TRUE(exprStmnt->IsExpressionStatement()); 2573af6ab5fSopenharmony_ci} 2583af6ab5fSopenharmony_ci 2593af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, ifStatementBuild) 2603af6ab5fSopenharmony_ci{ 2613af6ab5fSopenharmony_ci auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 2623af6ab5fSopenharmony_ci auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 2633af6ab5fSopenharmony_ci auto binaryExpr = BinaryExpressionBuilder(Allocator()) 2643af6ab5fSopenharmony_ci .SetLeft(left) 2653af6ab5fSopenharmony_ci .SetRight(right) 2663af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 2673af6ab5fSopenharmony_ci .Build(); 2683af6ab5fSopenharmony_ci auto consStmnt = ExpressionStatementBuilder(Allocator()).SetExpression(binaryExpr).Build(); 2693af6ab5fSopenharmony_ci auto alterStmnt = ExpressionStatementBuilder(Allocator()).SetExpression(binaryExpr).Build(); 2703af6ab5fSopenharmony_ci auto ifStmnt = 2713af6ab5fSopenharmony_ci IfStatementBuilder(Allocator()).SetTest(binaryExpr).SetConsequent(consStmnt).SetAlternate(alterStmnt).Build(); 2723af6ab5fSopenharmony_ci ASSERT_TRUE(ifStmnt->IsIfStatement()); 2733af6ab5fSopenharmony_ci} 2743af6ab5fSopenharmony_ci 2753af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, memberExpressionBuild) 2763af6ab5fSopenharmony_ci{ 2773af6ab5fSopenharmony_ci auto member = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 2783af6ab5fSopenharmony_ci auto thisExpr = ThisExpressionBuilder(Allocator()).Build(); 2793af6ab5fSopenharmony_ci auto memberExpression = MemberExpressionBuilder(Allocator()) 2803af6ab5fSopenharmony_ci .SetObject(thisExpr) 2813af6ab5fSopenharmony_ci .SetProperty(member) 2823af6ab5fSopenharmony_ci .SetKind(ark::es2panda::ir::MemberExpressionKind::PROPERTY_ACCESS) 2833af6ab5fSopenharmony_ci .Build(); 2843af6ab5fSopenharmony_ci ASSERT_TRUE(memberExpression->IsMemberExpression()); 2853af6ab5fSopenharmony_ci} 2863af6ab5fSopenharmony_ci 2873af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, methodDefinitionBuild) 2883af6ab5fSopenharmony_ci{ 2893af6ab5fSopenharmony_ci auto id = IdentifierBuilder(Allocator()).SetName("a").Build(); 2903af6ab5fSopenharmony_ci ark::ArenaVector<ark::es2panda::ir::Expression *> params(Allocator()->Adapter()); 2913af6ab5fSopenharmony_ci auto signature = ark::es2panda::ir::FunctionSignature(nullptr, std::move(params), nullptr); 2923af6ab5fSopenharmony_ci auto func = ScriptFunctionBuilder(Allocator()).SetSignature(&signature).Build(); 2933af6ab5fSopenharmony_ci auto funcExpr = FunctionExpressionBuilder(Allocator()).SetFunction(func).Build(); 2943af6ab5fSopenharmony_ci auto methodDef = MethodDefinitionBuilder(Allocator()) 2953af6ab5fSopenharmony_ci .SetKey(id) 2963af6ab5fSopenharmony_ci .SetMethodDefinitionKind(ark::es2panda::ir::MethodDefinitionKind::METHOD) 2973af6ab5fSopenharmony_ci .SetModifierFlags(ark::es2panda::ir::ModifierFlags::PUBLIC) 2983af6ab5fSopenharmony_ci .SetValue(funcExpr) 2993af6ab5fSopenharmony_ci .Build(); 3003af6ab5fSopenharmony_ci ASSERT_TRUE(methodDef->IsMethodDefinition()); 3013af6ab5fSopenharmony_ci} 3023af6ab5fSopenharmony_ci 3033af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, stringLiteralBuild) 3043af6ab5fSopenharmony_ci{ 3053af6ab5fSopenharmony_ci auto stringLiteral = StringLiteralBuilder(Allocator()).SetValue("qwe").Build(); 3063af6ab5fSopenharmony_ci ASSERT_TRUE(stringLiteral->IsStringLiteral()); 3073af6ab5fSopenharmony_ci} 3083af6ab5fSopenharmony_ci 3093af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, tsClassImplementsBuild) 3103af6ab5fSopenharmony_ci{ 3113af6ab5fSopenharmony_ci auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 3123af6ab5fSopenharmony_ci auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 3133af6ab5fSopenharmony_ci auto binaryExpr = BinaryExpressionBuilder(Allocator()) 3143af6ab5fSopenharmony_ci .SetLeft(left) 3153af6ab5fSopenharmony_ci .SetRight(right) 3163af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 3173af6ab5fSopenharmony_ci .Build(); 3183af6ab5fSopenharmony_ci ark::ArenaVector<ark::es2panda::ir::TypeNode *> types(Allocator()->Adapter()); 3193af6ab5fSopenharmony_ci auto typeParams = TSTypeParameterInstantiationBuilder(Allocator()).SetParams(std::move(types)).Build(); 3203af6ab5fSopenharmony_ci auto tsClassImpl = 3213af6ab5fSopenharmony_ci TSClassImplementsBuilder(Allocator()).SetExpression(binaryExpr).SetTypeParameters(typeParams).Build(); 3223af6ab5fSopenharmony_ci ASSERT_TRUE(tsClassImpl->IsTSClassImplements()); 3233af6ab5fSopenharmony_ci} 3243af6ab5fSopenharmony_ci 3253af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, switchStatementBuild) 3263af6ab5fSopenharmony_ci{ 3273af6ab5fSopenharmony_ci auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 3283af6ab5fSopenharmony_ci auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 3293af6ab5fSopenharmony_ci auto binaryExpr = BinaryExpressionBuilder(Allocator()) 3303af6ab5fSopenharmony_ci .SetLeft(left) 3313af6ab5fSopenharmony_ci .SetRight(right) 3323af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 3333af6ab5fSopenharmony_ci .Build(); 3343af6ab5fSopenharmony_ci auto consStmnt = ExpressionStatementBuilder(Allocator()).SetExpression(binaryExpr).Build(); 3353af6ab5fSopenharmony_ci 3363af6ab5fSopenharmony_ci auto thisExpr = ThisExpressionBuilder(Allocator()).Build(); 3373af6ab5fSopenharmony_ci ark::ArenaVector<ark::es2panda::ir::SwitchCaseStatement *> cases(Allocator()->Adapter()); 3383af6ab5fSopenharmony_ci ark::ArenaVector<ark::es2panda::ir::Statement *> conseq(Allocator()->Adapter()); 3393af6ab5fSopenharmony_ci conseq.push_back(consStmnt); 3403af6ab5fSopenharmony_ci auto switchCase = SwitchCaseStatementBuilder(Allocator()).SetTest(binaryExpr).SetConsequent(conseq).Build(); 3413af6ab5fSopenharmony_ci cases.push_back(switchCase); 3423af6ab5fSopenharmony_ci auto switchStmnt = SwitchStatementBuilder(Allocator()).SetCases(cases).SetDiscriminant(thisExpr).Build(); 3433af6ab5fSopenharmony_ci ASSERT_TRUE(switchStmnt->IsSwitchStatement()); 3443af6ab5fSopenharmony_ci} 3453af6ab5fSopenharmony_ci 3463af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, enumBuild) 3473af6ab5fSopenharmony_ci{ 3483af6ab5fSopenharmony_ci auto id = IdentifierBuilder(Allocator()).SetName("a").Build(); 3493af6ab5fSopenharmony_ci auto idMember = IdentifierBuilder(Allocator()).SetName("s").Build(); 3503af6ab5fSopenharmony_ci auto init = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 3513af6ab5fSopenharmony_ci auto enumMember = TSEnumMemberBuilder(Allocator()).SetKey(idMember).SetInit(init).Build(); 3523af6ab5fSopenharmony_ci auto enumDecl = TSEnumDeclarationBuilder(Allocator()) 3533af6ab5fSopenharmony_ci .SetKey(id) 3543af6ab5fSopenharmony_ci .SetIsConst(false) 3553af6ab5fSopenharmony_ci .SetIsDeclare(true) 3563af6ab5fSopenharmony_ci .SetIsConst(false) 3573af6ab5fSopenharmony_ci .AddMember(enumMember) 3583af6ab5fSopenharmony_ci .Build(); 3593af6ab5fSopenharmony_ci ASSERT_TRUE(enumDecl->IsTSEnumDeclaration()); 3603af6ab5fSopenharmony_ci} 3613af6ab5fSopenharmony_ci 3623af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, unaryExpressionBuild) 3633af6ab5fSopenharmony_ci{ 3643af6ab5fSopenharmony_ci auto id = IdentifierBuilder(Allocator()).SetName("a").Build(); 3653af6ab5fSopenharmony_ci auto unaryExpr = UnaryExpressionBuilder(Allocator()) 3663af6ab5fSopenharmony_ci .SetArgument(id) 3673af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_MINUS) 3683af6ab5fSopenharmony_ci .Build(); 3693af6ab5fSopenharmony_ci ASSERT_TRUE(unaryExpr->IsUnaryExpression()); 3703af6ab5fSopenharmony_ci} 3713af6ab5fSopenharmony_ci 3723af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, undefinedLiteralBuild) 3733af6ab5fSopenharmony_ci{ 3743af6ab5fSopenharmony_ci auto undefLiteral = UndefinedLiteralBuilder(Allocator()).Build(); 3753af6ab5fSopenharmony_ci ASSERT_TRUE(undefLiteral->IsUndefinedLiteral()); 3763af6ab5fSopenharmony_ci} 3773af6ab5fSopenharmony_ci 3783af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, updateExpressionBuild) 3793af6ab5fSopenharmony_ci{ 3803af6ab5fSopenharmony_ci auto id = IdentifierBuilder(Allocator()).SetName("a").Build(); 3813af6ab5fSopenharmony_ci auto updateExpr = UpdateExpressionBuilder(Allocator()) 3823af6ab5fSopenharmony_ci .SetArgument(id) 3833af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_MINUS_MINUS) 3843af6ab5fSopenharmony_ci .SetIsPrefix(true) 3853af6ab5fSopenharmony_ci .Build(); 3863af6ab5fSopenharmony_ci ASSERT_TRUE(updateExpr->IsUpdateExpression()); 3873af6ab5fSopenharmony_ci} 3883af6ab5fSopenharmony_ci 3893af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, VariableDeclarationBuild) 3903af6ab5fSopenharmony_ci{ 3913af6ab5fSopenharmony_ci auto idDeclarator = IdentifierBuilder(Allocator()).SetName("a").Build(); 3923af6ab5fSopenharmony_ci auto init = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 3933af6ab5fSopenharmony_ci auto varDeclarator = VariableDeclaratorBuilder(Allocator()).SetId(idDeclarator).SetInit(init).Build(); 3943af6ab5fSopenharmony_ci ark::ArenaVector<ark::es2panda::ir::VariableDeclarator *> declarators(Allocator()->Adapter()); 3953af6ab5fSopenharmony_ci declarators.push_back(varDeclarator); 3963af6ab5fSopenharmony_ci auto varDecl = VariableDeclarationBuilder(Allocator()) 3973af6ab5fSopenharmony_ci .SetDeclarators(std::move(declarators)) 3983af6ab5fSopenharmony_ci .SetKind(ark::es2panda::ir::VariableDeclaration::VariableDeclarationKind::LET) 3993af6ab5fSopenharmony_ci .Build(); 4003af6ab5fSopenharmony_ci ASSERT_TRUE(varDecl->IsVariableDeclaration()); 4013af6ab5fSopenharmony_ci} 4023af6ab5fSopenharmony_ci 4033af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, whileStatementBuild) 4043af6ab5fSopenharmony_ci{ 4053af6ab5fSopenharmony_ci auto left = NumberLiteralBuilder(Allocator()).SetValue("10").Build(); 4063af6ab5fSopenharmony_ci auto right = NumberLiteralBuilder(Allocator()).SetValue("5").Build(); 4073af6ab5fSopenharmony_ci auto binaryExpr = BinaryExpressionBuilder(Allocator()) 4083af6ab5fSopenharmony_ci .SetLeft(left) 4093af6ab5fSopenharmony_ci .SetRight(right) 4103af6ab5fSopenharmony_ci .SetOperator(ark::es2panda::lexer::TokenType::PUNCTUATOR_PLUS) 4113af6ab5fSopenharmony_ci .Build(); 4123af6ab5fSopenharmony_ci auto exprStmnt = ExpressionStatementBuilder(Allocator()).SetExpression(binaryExpr).Build(); 4133af6ab5fSopenharmony_ci auto whileStmnt = WhileStatementBuilder(Allocator()).SetTest(binaryExpr).SetBody(exprStmnt).Build(); 4143af6ab5fSopenharmony_ci ASSERT_TRUE(whileStmnt->IsWhileStatement()); 4153af6ab5fSopenharmony_ci} 4163af6ab5fSopenharmony_ci 4173af6ab5fSopenharmony_ciTEST_F(ASTVerifierTest, multipleImportTest) 4183af6ab5fSopenharmony_ci{ 4193af6ab5fSopenharmony_ci auto importedIdent = IdentifierBuilder(Allocator()).SetName("A").Build(); 4203af6ab5fSopenharmony_ci auto localIdent = IdentifierBuilder(Allocator()).SetName("A").Build(); 4213af6ab5fSopenharmony_ci auto stringLiteral = StringLiteralBuilder(Allocator()).SetValue("test").Build(); 4223af6ab5fSopenharmony_ci auto importSpecifier = ImportSpecifierBuilder(Allocator()).SetImported(importedIdent).SetLocal(localIdent).Build(); 4233af6ab5fSopenharmony_ci auto importDecl = 4243af6ab5fSopenharmony_ci ImportDeclarationBuilder(Allocator()).SetSource(stringLiteral).AddSpecifier(importSpecifier).Build(); 4253af6ab5fSopenharmony_ci ASSERT_TRUE(importDecl->IsImportDeclaration()); 4263af6ab5fSopenharmony_ci 4273af6ab5fSopenharmony_ci auto classId = IdentifierBuilder(Allocator()).SetName("B").Build(); 4283af6ab5fSopenharmony_ci auto classDef = ClassDefinitionBuilder(Allocator()).SetIdentifier(classId).SetSuperClass(localIdent).Build(); 4293af6ab5fSopenharmony_ci auto classDecl = ClassDeclarationBuilder(Allocator()).SetDefinition(classDef).Build(); 4303af6ab5fSopenharmony_ci ASSERT_TRUE(classDecl->IsClassDeclaration()); 4313af6ab5fSopenharmony_ci} 4323af6ab5fSopenharmony_ci} // anonymous namespace 433