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