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 mockPlainArray() { 19 const paramPlainArray = { 20 paramAnyMock : '[PC Preview] unknow any', 21 paramPlainArray : '[PC Preview] unknow PlainArray', 22 paramIterMock_K : '[PC Preview] unknow iterableiterator_k', 23 paramIterMock_V : '[PC Preview] unknow iterableiterator_v' 24 } 25 const PlainArrayClass = class PlainArray { 26 constructor(...args) { 27 console.warn('util.PlainArray interface mocked in the Previewer. How this interface works on the Previewer' + 28 ' may be different from that on a real device.'); 29 this.length = '[PC preview] unknow length'; 30 this.add = function (...args) { 31 console.warn("PlainArray.add interface mocked in the Previewer. How this interface works on the Previewer" + 32 " may be different from that on a real device.") 33 }; 34 this.clear = function (...args) { 35 console.warn("PlainArray.clear interface mocked in the Previewer. How this interface works on the Previewer" + 36 " may be different from that on a real device.") 37 }; 38 this.clone = function (...args) { 39 console.warn("PlainArray.clone interface mocked in the Previewer. How this interface works on the Previewer" + 40 " may be different from that on a real device.") 41 return paramPlainArray.paramPlainArray; 42 }; 43 this.has = function (...args) { 44 console.warn("PlainArray.has interface mocked in the Previewer. How this interface works on the Previewer" + 45 " may be different from that on a real device.") 46 return paramMock.paramBooleanMock; 47 }; 48 this.get = function (...args) { 49 console.warn("PlainArray.get interface mocked in the Previewer. How this interface works on the Previewer" + 50 " may be different from that on a real device.") 51 return paramPlainArray.paramAnyMock; 52 }; 53 this.getIndexOfKey = function (...args) { 54 console.warn("PlainArray.getIndexOfKey interface mocked in the Previewer. How this interface works on the Previewer" + 55 " may be different from that on a real device.") 56 return paramMock.paramNumberMock; 57 }; 58 this.getIndexOfValue = function (...args) { 59 console.warn("PlainArray.getIndexOfValue interface mocked in the Previewer. How this interface works on the Previewer" + 60 " may be different from that on a real device.") 61 return paramMock.paramNumberMock; 62 }; 63 this.isEmpty = function (...args) { 64 console.warn("PlainArray.isEmpty interface mocked in the Previewer. How this interface works on the Previewer" + 65 " may be different from that on a real device.") 66 return paramMock.paramBooleanMock; 67 }; 68 this.getKeyAt = function (...args) { 69 console.warn("PlainArray.getKeyAt interface mocked in the Previewer. How this interface works on the Previewer" + 70 " may be different from that on a real device.") 71 return paramMock.paramNumberMock; 72 }; 73 this.remove = function (...args) { 74 console.warn("PlainArray.remove interface mocked in the Previewer. How this interface works on the Previewer" + 75 " may be different from that on a real device.") 76 return paramPlainArray.paramAnyMock; 77 }; 78 this.removeAt = function (...args) { 79 console.warn("PlainArray.removeAt interface mocked in the Previewer. How this interface works on the Previewer" + 80 " may be different from that on a real device.") 81 return paramPlainArray.paramAnyMock; 82 }; 83 this.removeRangeFrom = function (...args) { 84 console.warn("PlainArray.removeRangeFrom interface mocked in the Previewer. How this interface works on the Previewer" + 85 " may be different from that on a real device.") 86 return paramMock.paramNumberMock; 87 }; 88 this.setValueAt = function (...args) { 89 console.warn("PlainArray.setValueAt interface mocked in the Previewer. How this interface works on the Previewer" + 90 " may be different from that on a real device.") 91 }; 92 this.toString = function (...args) { 93 console.warn("PlainArray.toString interface mocked in the Previewer. How this interface works on the Previewer" + 94 " may be different from that on a real device.") 95 return paramMock.paramStringMock; 96 }; 97 this.getValueAt = function (...args) { 98 console.warn("PlainArray.getValueAt interface mocked in the Previewer. How this interface works on the Previewer" + 99 " may be different from that on a real device.") 100 return paramPlainArray.paramAnyMock; 101 }; 102 this.forEach = function (...args) { 103 console.warn("PlainArray.forEach interface mocked in the Previewer. How this interface works on the Previewer" + 104 " may be different from that on a real device.") 105 if (this.args[0] === 'function') { 106 args[0].call(this, paramMock.businessErrorMock) 107 } 108 }; 109 this[Symbol.iterator] = function (...args) { 110 console.warn("PlainArray.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer" + 111 " may be different from that on a real device.") 112 let index = 0; 113 const IteratorMock = { 114 next: () => { 115 if (index < 1) { 116 const returnValue = [paramPlainArray.paramIterMock_K, paramPlainArray.paramIterMock_V]; 117 index++; 118 return { 119 value: returnValue, 120 done: false 121 }; 122 } else { 123 return { 124 done: true 125 }; 126 } 127 } 128 }; 129 return IteratorMock; 130 } 131 } 132 } 133 return PlainArrayClass; 134}