• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 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
16import { paramMock } from "../utils"
17
18export function mockHashSet() {
19  const paramHashSet = {
20    paramAnyMock : '[PC Preview] unknow any'
21  }
22  const HashSetClass = class HashSet {
23    constructor(...args) {
24      console.warn('util.HashSet interface mocked in the Previewer. How this interface works on the Previewer' +
25        ' may be different from that on a real device.');
26      this.length = '[PC preview] unknow length';
27      this.isEmpty = function (...args) {
28        console.warn("HashSet.isEmpty interface mocked in the Previewer. How this interface works on the Previewer" +
29          " may be different from that on a real device.")
30        return paramMock.paramBooleanMock;
31      };
32      this.has = function (...args) {
33        console.warn("HashSet.has interface mocked in the Previewer. How this interface works on the Previewer" +
34          " may be different from that on a real device.")
35        return paramMock.paramBooleanMock;
36      };
37      this.add = function (...args) {
38        console.warn("HashSet.add interface mocked in the Previewer. How this interface works on the Previewer" +
39          " may be different from that on a real device.")
40        return paramMock.paramBooleanMock;
41      };
42      this.remove = function (...args) {
43        console.warn("HashSet.remove interface mocked in the Previewer. How this interface works on the Previewer" +
44          " may be different from that on a real device.")
45        return paramMock.paramBooleanMock;
46      };
47      this.clear = function (...args) {
48        console.warn("HashSet.clear interface mocked in the Previewer. How this interface works on the Previewer" +
49          " may be different from that on a real device.")
50      };
51      this.forEach = function (...args) {
52        console.warn("HashSet.forEach interface mocked in the Previewer. How this interface works on the Previewer" +
53          " may be different from that on a real device.")
54        if (this.args[0] === 'function') {
55          args[0].call(this, paramMock.businessErrorMock);
56        }
57      };
58      this.values = function (...args) {
59        console.warn('HashSet.values interface mocked in the Previewer. How this interface works on the Previewer' +
60          ' may be different from that on a real device.');
61        const IteratorVMock = {
62          *[Symbol.iterator]() {
63            yield paramHashSet.paramAnyMock;
64          }
65        };
66        return IteratorVMock;
67      };
68      this.entries = function (...args) {
69        console.warn('HashSet.entries interface mocked in the Previewer. How this interface works on the Previewer' +
70          ' may be different from that on a real device.');
71        const IteratorEntriesMock = {
72          *[Symbol.iterator]() {
73            yield [paramHashSet.paramAnyMock, paramHashSet.paramAnyMock];
74          }
75        };
76        return IteratorEntriesMock;
77      };
78      this[Symbol.iterator] = function (...args) {
79        console.warn("HashSet.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer" +
80          " may be different from that on a real device.")
81        let index = 0;
82        const IteratorMock = {
83          next: () => {
84            if (index < 1) {
85              const returnValue = [paramHashSet.paramAnyMock, paramHashSet.paramAnyMock];
86              index++;
87              return {
88                value: returnValue,
89                done: false
90              };
91            } else {
92              return {
93                done: true
94              };
95            }
96          }
97        };
98        return IteratorMock;
99      }
100    }
101  }
102  return HashSetClass;
103}