• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16
17import { describe, it, expect } from '@ohos/hypium';
18import { asyncGenerator } from './test2018_01'
19import { obj3 } from './test2018_02'
20import { remaining } from './test2018_03'
21import { test2018_05_ans } from './test2018_05'
22import { test2018_06_ans } from './test2018_06'
23
24
25export default function es2018Test() {
26  describe('ES2018Test', () => {
27    /**
28     * @tc.number    : SUB_COMMONLIBRARY_ETSUTILS_ES2018NewFeatures_0001
29     * @tc.name      : testAsynchronousIteration
30     * @tc.desc      : add name of task for taskpool
31     * @tc.size      : MediumTest
32     * @tc.type      : Function
33     * @tc.level     : Level 0
34     */
35    it('testAsynchronousIteration', 0, async () => {
36      let es2018_01_ans: number[] = [];
37      for await (const value of asyncGenerator()) {
38        es2018_01_ans.push(value);
39      }
40      expect(es2018_01_ans).assertDeepEquals([0, 1, 2, 3, 4])
41    })
42    /**
43     * @tc.number    : SUB_COMMONLIBRARY_ETSUTILS_ES2018NewFeatures_0002
44     * @tc.name      : testSpreadingIntoObjectLiterals
45     * @tc.desc      : add name of task for taskpool
46     * @tc.size      : MediumTest
47     * @tc.type      : Function
48     * @tc.level     : Level 0
49     */
50    it('testSpreadingIntoObjectLiterals', 0, () => {
51      expect(obj3).assertDeepEquals({
52        one: 1, two: 2, three: 3, four: 4
53      })
54    })
55    /**
56     * @tc.number    : SUB_COMMONLIBRARY_ETSUTILS_ES2018NewFeatures_0003
57     * @tc.name      : testRestProperty
58     * @tc.desc      : add name of task for taskpool
59     * @tc.size      : MediumTest
60     * @tc.type      : Function
61     * @tc.level     : Level 0
62     */
63    it('testRestProperty', 0, () => {
64      expect(remaining).assertDeepEquals({
65        b: 2, c: 3
66      })
67    })
68    /**
69     * @tc.number    : SUB_COMMONLIBRARY_ETSUTILS_ES2018NewFeatures_0004
70     * @tc.name      : testPromise.finally
71     * @tc.desc      : add name of task for taskpool
72     * @tc.size      : MediumTest
73     * @tc.type      : Function
74     * @tc.level     : Level 0
75     */
76    it('testPromise.finally', 0, () => {
77      let test2018_04_ans: number = 0;
78      let promise1 = new Promise((resolve: (value: string) => void, rejcet: (value: string) => void) => {
79        resolve("resolved");
80      })
81      let promise2 = new Promise((resolve: (value: string) => void, rejcet: (value: string) => void) => {
82        resolve("resolved");
83      })
84      promise1.then(
85        () => {
86          throw (new Error("error"));
87        }
88      ).catch((err: string) => {
89      }
90      ).finally(() => {
91        test2018_04_ans += 1;
92        promise2.then(
93          () => {
94          }
95        ).catch((err: string) => {
96        }
97        ).finally(() => {
98          test2018_04_ans += 1;
99          expect(test2018_04_ans).assertEqual(2);
100        })
101      })
102    })
103    /**
104     * @tc.number    : SUB_COMMONLIBRARY_ETSUTILS_ES2018NewFeatures_0005
105     * @tc.name      : testNewFeaturesOfRegExp
106     * @tc.desc      : add name of task for taskpool
107     * @tc.size      : MediumTest
108     * @tc.type      : Function
109     * @tc.level     : Level 0
110     */
111    it('testNewFeaturesOfRegExp', 0, () => {
112      expect(test2018_05_ans).assertEqual("756abcbcdeffalsetruetruetruetrue");
113    })
114    /**
115     * @tc.number    : SUB_COMMONLIBRARY_ETSUTILS_ES2018NewFeatures_0006
116     * @tc.name      : testFixTemplateString
117     * @tc.desc      : add name of task for taskpool
118     * @tc.size      : MediumTest
119     * @tc.type      : Function
120     * @tc.level     : Level 0
121     */
122    it('testFixTemplateString', 0, () => {
123      expect(test2018_06_ans).assertEqual("ES2018undefined");
124    })
125  })
126}