1"use strict"; 2/* 3 * Copyright (c) 2022-2025 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16Object.defineProperty(exports, "__esModule", { value: true }); 17exports.assert = void 0; 18const hypium_1 = require("@ohos/hypium"); 19// todo: the 'message' arg is ignored 20exports.assert = ((expression, message) => { 21 (0, hypium_1.expect)(Boolean(expression)).assertTrue(); 22}); 23exports.assert.equal = (actual, expected, message) => { 24 (0, hypium_1.expect)(actual).assertEqual(expected); 25}; 26exports.assert.notEqual = (actual, expected, message) => { 27 // todo: not accurate impl, because compared values are not printed 28 (0, hypium_1.expect)(actual != expected).assertTrue(); 29}; 30exports.assert.strictEqual = (actual, expected, message) => { 31 // todo: not accurate impl, because compared values are not printed 32 (0, hypium_1.expect)(actual === expected).assertTrue(); 33}; 34exports.assert.notStrictEqual = (actual, expected, message) => { 35 // todo: not accurate impl, because compared values are not printed 36 (0, hypium_1.expect)(actual !== expected).assertTrue(); 37}; 38exports.assert.deepEqual = (actual, expected, message) => { 39 // todo: implement 40 (0, hypium_1.expect)(actual).assertEqual(actual /*expected*/); 41}; 42exports.assert.notDeepEqual = (actual, expected, message) => { 43 // todo: implement 44 (0, hypium_1.expect)(actual).assertEqual(actual /*expected*/); 45}; 46exports.assert.isTrue = (value, message) => { 47 (0, hypium_1.expect)(value).assertTrue(); 48}; 49exports.assert.isFalse = (value, message) => { 50 (0, hypium_1.expect)(value).assertFalse(); 51}; 52exports.assert.closeTo = (actual, expected, delta, message) => { 53 // implementation of 'assertClose' does not fit: 54 // expect(actual).assertClose(expected, delta) 55 const diff = Math.abs(actual - expected); 56 if (diff == delta) 57 (0, hypium_1.expect)(diff).assertEqual(delta); 58 else 59 (0, hypium_1.expect)(diff).assertLess(delta); 60}; 61exports.assert.fail = (message) => { 62 (0, hypium_1.expect)().assertFail(); 63}; 64exports.assert.isNull = (value, message) => { 65 (0, hypium_1.expect)(value).assertNull(); 66}; 67exports.assert.isNotNull = (value, message) => { 68 (0, hypium_1.expect)(value ? null : value).assertNull(); 69}; 70exports.assert.instanceOf = (value, constructor, message) => { 71 // todo: not accurate impl 72 // expect(value).assertInstanceOf(constructor.name) 73 (0, hypium_1.expect)(value instanceof constructor).assertTrue(); 74}; 75exports.assert.isAtLeast = (valueToCheck, valueToBeAtLeast, message) => { 76 if (valueToCheck == valueToBeAtLeast) 77 (0, hypium_1.expect)(valueToCheck).assertEqual(valueToBeAtLeast); 78 else 79 (0, hypium_1.expect)(valueToCheck).assertLarger(valueToBeAtLeast); 80}; 81exports.assert.exists = (value, message) => { 82 // todo: not accurate impl 83 (0, hypium_1.expect)(value == null).assertFalse(); 84}; 85exports.assert.throw = (fn, message) => { 86 let fnWrapper = () => { 87 try { 88 fn(); 89 } 90 catch (e) { 91 throw new Error("fn thrown exception"); 92 } 93 }; 94 (0, hypium_1.expect)(fnWrapper).assertThrowError("fn thrown exception"); 95}; 96exports.assert.throws = (fn, message) => { 97 exports.assert.throw(fn, message); 98}; 99exports.assert.isAbove = (valueToCheck, valueToBeAbove, message) => { 100 (0, hypium_1.expect)(valueToCheck).assertLarger(valueToBeAbove); 101}; 102exports.assert.isBelow = (valueToCheck, valueToBeBelow, message) => { 103 (0, hypium_1.expect)(valueToCheck).assertLess(valueToBeBelow); 104}; 105exports.assert.match = (value, regexp, message) => { 106 // todo: not accurate impl 107 (0, hypium_1.expect)(regexp.test(value)).assertTrue(); 108}; 109exports.assert.isDefined = (value, message) => { 110 // todo: not accurate impl 111 (0, hypium_1.expect)(value === undefined).assertFalse(); 112}; 113exports.assert.isUndefined = (value, message) => { 114 (0, hypium_1.expect)(value).assertUndefined(); 115}; 116exports.assert.isEmpty = (object, message) => { 117 // todo: implement 118 (0, hypium_1.expect)(object !== undefined).assertTrue(); 119}; 120exports.assert.isNotEmpty = (object, message) => { 121 // todo: implement 122 (0, hypium_1.expect)(object !== undefined).assertTrue(); 123}; 124//# sourceMappingURL=index.js.map