From f5af847f45acb8ccec707bfad6a71da628191876 Mon Sep 17 00:00:00 2001 From: vopl Date: Thu, 15 May 2025 15:20:07 +0300 Subject: [PATCH] ui-plugins golden test skeleton --- .../ui-plugins/test/arktsconfig-golden.json | 36 ++ ui2abc/ui-plugins/test/ets/Rewrite.ets | 353 ++++++++++++++++++ ui2abc/ui-plugins/test/golden/Rewrite.ets | 1 + ui2abc/ui-plugins/test/package.json | 8 + 4 files changed, 398 insertions(+) create mode 100644 ui2abc/ui-plugins/test/arktsconfig-golden.json create mode 100644 ui2abc/ui-plugins/test/ets/Rewrite.ets create mode 100644 ui2abc/ui-plugins/test/golden/Rewrite.ets create mode 100644 ui2abc/ui-plugins/test/package.json diff --git a/ui2abc/ui-plugins/test/arktsconfig-golden.json b/ui2abc/ui-plugins/test/arktsconfig-golden.json new file mode 100644 index 0000000000..b5159eabe1 --- /dev/null +++ b/ui2abc/ui-plugins/test/arktsconfig-golden.json @@ -0,0 +1,36 @@ +{ + "compilerOptions": { + "package": "@test", + "outDir": "build/abc", + "baseUrl": ".", + "paths": { + "@ohos.arkui": ["../../../arkoala-arkts/arkui/sdk"], + "@ohos.router": ["../../../arkoala-arkts/arkui/sdk/ohos/router.ets"], + "@koalaui/builderLambda": ["../../../arkoala-arkts/arkui/sdk/annotations"], + "@koalaui/interop": ["../../../interop/src/arkts"], + "@koalaui/harness": ["../../../incremental/harness/src/arkts"], + "@koalaui/compat": [ "../../../incremental/compat/src/arkts" ], + "#platform": [ "../../../incremental/compat/src/arkts" ], + "@koalaui/common": [ "../../../incremental/common/src" ], + "@koalaui/runtime": [ "../../../incremental/runtime/ets" ], + "@koalaui/runtime/annotations": [ "../../../incremental/runtime/annotations" ] + }, + "plugins": [ + { + "transform": "../lib/parsed-stage-plugin", + "stage": "parsed", + "name": "ui" + }, + { + "transform": "../lib/checked-stage-plugin", + "stage": "checked", + "name": "ui" + }, + { + "transform": "@koalaui/memo-plugin", + "stage": "checked", + "name": "memo" + } + ] + } +} diff --git a/ui2abc/ui-plugins/test/ets/Rewrite.ets b/ui2abc/ui-plugins/test/ets/Rewrite.ets new file mode 100644 index 0000000000..861d23dcac --- /dev/null +++ b/ui2abc/ui-plugins/test/ets/Rewrite.ets @@ -0,0 +1,353 @@ +/* + * Copyright (c) 2022-2025 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. + */ + + +// Bare empty struct + +@Entry +@Component +export struct EntryExample { + build(){ } +} + +@Component +struct ComponentExample { + build(){ } +} + + +// A builder call in the build() function + +@Component +struct BuildExample { + build(){ + Text("message") + .fontColor(Color.Red) + .width(100) + } +} + +// Simple state management annotations + +@Component +struct StateExample { + @State x: string = "hello" + build(){ + Text(this.x) + } +} + +@Component +struct LinkExample { + @Link x: string + build(){ + Text(this.x) + } +} + +@Component +struct PropExample { + @Prop x: string + build(){ + Text(this.x) + } +} + +@Component +struct PropInitializedExample { + @Prop x: string = "init" + build(){ + Text(this.x) + } +} + +@Component +struct ProvideExample { + @Provide("name") x: string = "text" + + build(){ + Text(this.x) + } +} + +@Component +struct ConsumeExample { + @Consume("name") x: string + build(){ + Text(this.x) + } +} + +// Builder functions + +@Component +struct BuilderExample { + @Builder foo() { + Text("hello") + } + build() { + this.foo() + } +} + +@Builder +function bar() { + Text("hello") +} + +@Component +struct GlobalBuilderExample { + build() { + bar() + } +} + +// TODO: check this +//@Component +//struct BuilderParamExample { +// @BuilderParam foo: () => {} +// build() { +// this.foo() +// } +//} + +// @Styles @Extend @AnimatableExtend + +@Styles +function looks() { +// TODO: check this +// .height(500) +// .width(400) +// .backgroundColor(Color.Gray) +} + +@Component +struct StylesExample { + build() { + Text() + .width(17) + .looks() + } +} + +@Component +struct StylesMethodExample { + @Styles + nice() { +// TODO: check this +// .height(500) +// .width(400) +// .backgroundColor(Color.Gray) + } + + build() { + Text() + .width(17) + .nice() + } +} + + +@Extend(Column) +function clown(width: number) { +// TODO: check this +// .height(500) +// .width(width) +// .backgroundColor(Color.Gray) +} + +@Component +struct ExtendExample { + build() { + Column() + .width(17) + .clown(400) + } +} + +class AnimatableValue implements AnimatableArithmetic { + plus(rhs: AnimatableValue): AnimatableValue { + return new AnimatableValue() + } + subtract(rhs: AnimatableValue): AnimatableValue { + return new AnimatableValue() + } + multiply(scale: number): AnimatableValue { + return new AnimatableValue() + } + equals(rhs: AnimatableValue): boolean { + return this === rhs + } +} + +@AnimatableExtend(Text) +function attributeExtend(n: number, animatable: AnimatableValue) { +// TODO: check this +// .fontSize(n) +} + +@Component +struct AnimatableExtendExample { + build() { + Text() + .width(17) + .attributeExtend(50, new AnimatableValue()) + } +} + + +// Advanced state management + +@Component +struct WatchExample { + @State @Watch("watchFunction") x: string = "hello" + watchFunction() { + console.log("Watch function") + } + build() { + } +} + +@Component +struct StorageLinkExample { + @StorageLink("storage") link: string = "Start" + build() { + } +} + +@Component +struct StoragePropExample { + @StorageProp("storage") prop: string = "Start" + build() { + } +} + +// CustomDialog + +@CustomDialog +struct CustomDialogExample { + controller: CustomDialogController + build() { + } +} + +@Component +export struct CustomDialogControllerExample { + dialogController: CustomDialogController = new CustomDialogController({ + builder: { + build: () => CustomDialogExample(), + buildOptions: {} + }, + autoCancel: true, + alignment: DialogAlignment.Default, + offset: { dx: 0, dy: 0 }, + gridCount: 4, + customStyle: false + }) + + aboutToAppear() { + this.dialogController.open() + } + + aboutToDisappear() { + this.dialogController.close() + } + + build() { + } +} + +// TODO: check this +//// ObjectLink and Observed +// +//@Observed +//class ObservedExample { +// public c: number +// constructor(c: number) { +// this.c = c +// } +//} + +//@Component +//struct ObjectLinkExample { +// @ObjectLink a: ObservedExample +// +// build() { +// Button() +// .onClick(() => { +// this.a.c += 1 +// }) +// } +//} +// +//@Component +//struct ObjectLinkExampleParent { +// @State a: ObservedExample[] = [new ObservedExample(0), new ObservedExample(0)] +// +// build() { +// ObjectLinkExample() +// } +//} + +@Component +struct PlainPropertyExample { + field: number = 17 +} + +@Component +struct DollarCallExample { + @State + state: number = 17 + build() { + Child({counter: this.state}) + } +} + +@Component +struct CallExample { + @State + state: number = 17 + build() { + Child({counter: this.state}) + } +} + +@Component +struct Child { + @Link + counter: number + build() {} +} + +@Component +struct BuilderPropagationExample { + build() { + ChildWithBuilder().width(100) + } +} + +@Component +struct ChildWithBuilder { + build() { + Column() {} + } +} + +@Component +struct StaticField { + static x: number = 17 + build() {} +} + diff --git a/ui2abc/ui-plugins/test/golden/Rewrite.ets b/ui2abc/ui-plugins/test/golden/Rewrite.ets new file mode 100644 index 0000000000..30404ce4c5 --- /dev/null +++ b/ui2abc/ui-plugins/test/golden/Rewrite.ets @@ -0,0 +1 @@ +TODO \ No newline at end of file diff --git a/ui2abc/ui-plugins/test/package.json b/ui2abc/ui-plugins/test/package.json new file mode 100644 index 0000000000..a60bf1aa4f --- /dev/null +++ b/ui2abc/ui-plugins/test/package.json @@ -0,0 +1,8 @@ +{ + "scripts": { + "run": "../../../incremental/tools/panda/arkts/ui2abc --arktsconfig ./arktsconfig-golden.json --output ./build/golden-needless.abc ./ets/Rewrite.ets", + "clean": "rm -rf out", + "test": "npm run clean && (npm run run 2> /dev/null || true) && diff golden/Rewrite.ets out/Rewrite.ets", + "test:debug": "npm run clean && npm run run" + } +} -- Gitee