1e484b35bSopenharmony_ci/* 2e484b35bSopenharmony_ci * Licensed to the Apache Software Foundation (ASF) under one 3e484b35bSopenharmony_ci * or more contributor license agreements. See the NOTICE file 4e484b35bSopenharmony_ci * distributed with this work for additional information 5e484b35bSopenharmony_ci * regarding copyright ownership. The ASF licenses this file 6e484b35bSopenharmony_ci * to you under the Apache License, Version 2.0 (the 7e484b35bSopenharmony_ci * "License"); you may not use this file except in compliance 8e484b35bSopenharmony_ci * with the License. You may obtain a copy of the License at 9e484b35bSopenharmony_ci * 10e484b35bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 11e484b35bSopenharmony_ci * 12e484b35bSopenharmony_ci * Unless required by applicable law or agreed to in writing, 13e484b35bSopenharmony_ci * software distributed under the License is distributed on an 14e484b35bSopenharmony_ci * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15e484b35bSopenharmony_ci * KIND, either express or implied. See the License for the 16e484b35bSopenharmony_ci * specific language governing permissions and limitations 17e484b35bSopenharmony_ci * under the License. 18e484b35bSopenharmony_ci */ 19e484b35bSopenharmony_ci 20e484b35bSopenharmony_ciimport chai from 'chai'; 21e484b35bSopenharmony_ciimport { 22e484b35bSopenharmony_ci describe, 23e484b35bSopenharmony_ci it 24e484b35bSopenharmony_ci} from 'mocha'; 25e484b35bSopenharmony_ciconst expect = chai.expect; 26e484b35bSopenharmony_ci 27e484b35bSopenharmony_ciimport * as utils from '../../runtime/utils/index'; 28e484b35bSopenharmony_ci 29e484b35bSopenharmony_cidescribe('utils', () => { 30e484b35bSopenharmony_ci it('should be an array or object', () => { 31e484b35bSopenharmony_ci expect(utils.isObject).to.be.an.instanceof(Function); 32e484b35bSopenharmony_ci expect(utils.isObject({})).eql(true); 33e484b35bSopenharmony_ci expect(utils.isObject([])).eql(true); 34e484b35bSopenharmony_ci expect(utils.isObject('a')).eql(false); 35e484b35bSopenharmony_ci expect(utils.isObject(0)).eql(false); 36e484b35bSopenharmony_ci expect(utils.isObject(true)).eql(false); 37e484b35bSopenharmony_ci expect(utils.isObject(null)).eql(false); 38e484b35bSopenharmony_ci expect(utils.isObject(undefined)).eql(false); 39e484b35bSopenharmony_ci expect(utils.isObject(function() {})).eql(false); 40e484b35bSopenharmony_ci expect(utils.isObject(/\w*/)).eql(true); 41e484b35bSopenharmony_ci expect(utils.isObject(new Date())).eql(true); 42e484b35bSopenharmony_ci }); 43e484b35bSopenharmony_ci 44e484b35bSopenharmony_ci it('should be an real object', () => { 45e484b35bSopenharmony_ci expect(utils.isPlainObject).to.be.an.instanceof(Function); 46e484b35bSopenharmony_ci expect(utils.isPlainObject({})).eql(true); 47e484b35bSopenharmony_ci expect(utils.isPlainObject([])).eql(false); 48e484b35bSopenharmony_ci expect(utils.isPlainObject('a')).eql(false); 49e484b35bSopenharmony_ci expect(utils.isPlainObject(0)).eql(false); 50e484b35bSopenharmony_ci expect(utils.isPlainObject(true)).eql(false); 51e484b35bSopenharmony_ci expect(utils.isPlainObject(null)).eql(false); 52e484b35bSopenharmony_ci expect(utils.isPlainObject(undefined)).eql(false); 53e484b35bSopenharmony_ci expect(utils.isPlainObject(function() {})).eql(false); 54e484b35bSopenharmony_ci expect(utils.isPlainObject(/\w*/)).eql(false); 55e484b35bSopenharmony_ci expect(utils.isPlainObject(new Date())).eql(false); 56e484b35bSopenharmony_ci }); 57e484b35bSopenharmony_ci 58e484b35bSopenharmony_ci it('has own property', () => { 59e484b35bSopenharmony_ci expect(utils.hasOwn).to.be.an.instanceof(Function); 60e484b35bSopenharmony_ci function Point() { 61e484b35bSopenharmony_ci this.x = 0; 62e484b35bSopenharmony_ci } 63e484b35bSopenharmony_ci Point.prototype.y = 1; 64e484b35bSopenharmony_ci const p = new Point(); 65e484b35bSopenharmony_ci expect(p.x).eql(0); 66e484b35bSopenharmony_ci expect(p.y).eql(1); 67e484b35bSopenharmony_ci expect(utils.hasOwn(p, 'x')).eql(true); 68e484b35bSopenharmony_ci expect(utils.hasOwn(p, 'y')).eql(false); 69e484b35bSopenharmony_ci }); 70e484b35bSopenharmony_ci 71e484b35bSopenharmony_ci it('own property is empty or not', () => { 72e484b35bSopenharmony_ci expect(utils.isEmpty).to.be.an.instanceof(Function); 73e484b35bSopenharmony_ci expect(utils.isEmpty({})).eql(true); 74e484b35bSopenharmony_ci expect(utils.isEmpty([])).eql(true); 75e484b35bSopenharmony_ci expect(utils.isEmpty('a')).eql(true); 76e484b35bSopenharmony_ci expect(utils.isEmpty(0)).eql(true); 77e484b35bSopenharmony_ci expect(utils.isEmpty(true)).eql(true); 78e484b35bSopenharmony_ci expect(utils.isEmpty(null)).eql(true); 79e484b35bSopenharmony_ci expect(utils.isEmpty(undefined)).eql(true); 80e484b35bSopenharmony_ci expect(utils.isEmpty(function() {})).eql(true); 81e484b35bSopenharmony_ci expect(utils.isEmpty(/\w*/)).eql(true); 82e484b35bSopenharmony_ci expect(utils.isEmpty(new Date())).eql(true); 83e484b35bSopenharmony_ci function Point() { 84e484b35bSopenharmony_ci this.x = 0; 85e484b35bSopenharmony_ci } 86e484b35bSopenharmony_ci const p = new Point(); 87e484b35bSopenharmony_ci expect(p.x).eql(0); 88e484b35bSopenharmony_ci expect(utils.isEmpty(p)).eql(false); 89e484b35bSopenharmony_ci Point.prototype.y = 1; 90e484b35bSopenharmony_ci expect(p.y).eql(1); 91e484b35bSopenharmony_ci expect(utils.isEmpty(p)).eql(false); 92e484b35bSopenharmony_ci }); 93e484b35bSopenharmony_ci 94e484b35bSopenharmony_ci it('is null or undefined', () => { 95e484b35bSopenharmony_ci expect(utils.isNull).to.be.an.instanceof(Function); 96e484b35bSopenharmony_ci expect(utils.isNull({})).eql(false); 97e484b35bSopenharmony_ci expect(utils.isNull([])).eql(false); 98e484b35bSopenharmony_ci expect(utils.isNull('a')).eql(false); 99e484b35bSopenharmony_ci expect(utils.isNull(0)).eql(false); 100e484b35bSopenharmony_ci expect(utils.isNull(true)).eql(false); 101e484b35bSopenharmony_ci expect(utils.isNull(null)).eql(true); 102e484b35bSopenharmony_ci expect(utils.isNull(undefined)).eql(true); 103e484b35bSopenharmony_ci expect(utils.isNull(function() {})).eql(false); 104e484b35bSopenharmony_ci expect(utils.isNull(/\w*/)).eql(false); 105e484b35bSopenharmony_ci expect(utils.isNull(new Date())).eql(false); 106e484b35bSopenharmony_ci }); 107e484b35bSopenharmony_ci}); 108