1 // Copyright (c) 2006 Apple Computer, Inc. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions 5 // are met: 6 // 7 // 1. Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // 10 // 2. Redistributions in binary form must reproduce the above 11 // copyright notice, this list of conditions and the following 12 // disclaimer in the documentation and/or other materials provided 13 // with the distribution. 14 // 15 // 3. Neither the name of the copyright holder(s) nor the names of any 16 // contributors may be used to endorse or promote products derived 17 // from this software without specific prior written permission. 18 // 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 30 // OF THE POSSIBILITY OF SUCH DAMAGE. 31 32 // Simple splice tests based on webkit layout tests. 33 var arr = ['a','b','c','d']; 34 assertArrayEquals(['a','b','c','d'], arr); 35 assertArrayEquals(['c','d'], arr.splice(2)); 36 assertArrayEquals(['a','b'], arr); 37 assertArrayEquals(['a','b'], arr.splice(0)); 38 assertArrayEquals([], arr) 39 40 arr = ['a','b','c','d']; 41 assertEquals(undefined, arr.splice()) 42 assertArrayEquals(['a','b','c','d'], arr); 43 assertArrayEquals(['a','b','c','d'], arr.splice(undefined)) 44 assertArrayEquals([], arr); 45 46 arr = ['a','b','c','d']; 47 assertArrayEquals(['a','b','c','d'], arr.splice(null)) 48 assertArrayEquals([], arr); 49 50 arr = ['a','b','c','d']; 51 assertArrayEquals([], arr.splice(100)) 52 assertArrayEquals(['a','b','c','d'], arr); 53 assertArrayEquals(['d'], arr.splice(-1)) 54 assertArrayEquals(['a','b','c'], arr); 55 56 assertArrayEquals([], arr.splice(2, undefined)) 57 assertArrayEquals([], arr.splice(2, null)) 58 assertArrayEquals([], arr.splice(2, -1)) 59 assertArrayEquals([], arr.splice(2, 0)) 60 assertArrayEquals(['a','b','c'], arr); 61 assertArrayEquals(['c'], arr.splice(2, 100)) 62 assertArrayEquals(['a','b'], arr); 63