68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
/**
|
|
* Tests pre-es5 array methods
|
|
*
|
|
* Copyright (C) 2014 Mike Gerwitz
|
|
*
|
|
* This file is part of jsTonic.
|
|
*
|
|
* jstonic is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
var Sut = require( '../../' ).std.Array,
|
|
expect = require( 'chai' ).expect;
|
|
|
|
|
|
describe( 'std.Array', () =>
|
|
{
|
|
describe( '#isArray', () =>
|
|
{
|
|
/**
|
|
* The idea is that this should succeed in whatever environment this
|
|
* test case is being run.
|
|
*/
|
|
it( 'uses either ES5 Array.isArray or std.Array._isArray', () =>
|
|
{
|
|
expect( [ Array.isArray, Sut._isArray ] )
|
|
.to.include( Sut.isArray );
|
|
} );
|
|
} );
|
|
|
|
|
|
/**
|
|
* Our own implementation
|
|
*
|
|
* Many of these tests exist not because there are holes in the
|
|
* implementation, but to prevent regressions.
|
|
*/
|
|
describe( '#_isArray', () =>
|
|
{
|
|
it( 'recognizes array', () => _ischk( [], true ) );
|
|
it( 'rejects objects', () => _ischk( { 0: true }, false ) );
|
|
it( 'rejects functions', () => _ischk( ()=>{}, false ) );
|
|
it( 'rejects strings', () => _ischk( "", false ) );
|
|
it( 'rejects numbers', () => _ischk( 0, false ) );
|
|
it( 'rejects infinity', () => _ischk( Infinity, false ) );
|
|
it( 'rejects NaN', () => _ischk( NaN, false ) );
|
|
it( 'rejects undefined', () => _ischk( undefined, false ) );
|
|
it( 'rejects null', () => _ischk( null, false ) );
|
|
} );
|
|
} );
|
|
|
|
|
|
function _ischk( value, expected )
|
|
{
|
|
expect( Sut._isArray( value ) ).to.equal( expected );
|
|
}
|
|
|