Changeset 206085 in webkit


Ignore:
Timestamp:
Sep 18, 2016 12:49:28 PM (8 years ago)
Author:
Matt Baker
Message:

Web Inspector: Add test coverage for all array utility functions
https://bugs.webkit.org/show_bug.cgi?id=162044
<rdar://problem/28330846>

Reviewed by Joseph Pecoraro.

New test cases and expectations for Array utility functions.

  • inspector/unit-tests/array-utilities-expected.txt:
  • inspector/unit-tests/array-utilities.html:
Location:
trunk/LayoutTests
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r206063 r206085  
     12016-09-18  Matt Baker  <mattbaker@apple.com>
     2
     3        Web Inspector: Add test coverage for all array utility functions
     4        https://bugs.webkit.org/show_bug.cgi?id=162044
     5        <rdar://problem/28330846>
     6
     7        Reviewed by Joseph Pecoraro.
     8
     9        New test cases and expectations for Array utility functions.
     10
     11        * inspector/unit-tests/array-utilities-expected.txt:
     12        * inspector/unit-tests/array-utilities.html:
     13
    1142016-09-16  Joseph Pecoraro  <pecoraro@apple.com>
    215
  • trunk/LayoutTests/inspector/unit-tests/array-utilities-expected.txt

    r205872 r206085  
    4646PASS: shallowEqual of non-arrays should be false.
    4747
     48-- Running test case: Array.prototype.lastValue
     49PASS: lastValue of a nonempty array should be the last value.
     50PASS: lastValue of an empty array should be undefined.
     51
     52-- Running test case: Array.prototype.remove
     53PASS: remove with onlyFirst equal to true should only remove the first matching value.
     54PASS: remove with onlyFirst equal to false should remove all matching values.
     55PASS: remove with onlyFirst unspecified should remove all matching values.
     56
     57-- Running test case: Array.prototype.toggleIncludes
     58PASS: toggleIncludes of an existing item with force true should have no effect.
     59PASS: toggleIncludes of an existing item with force false should remove the item.
     60PASS: toggleIncludes of a nonexistent item with force true should add the item.
     61PASS: toggleIncludes of a nonexistent item with force false should have no effect.
     62
     63-- Running test case: Array.prototype.insertAtIndex
     64PASS: insertAtIndex with index unspecified should insert at the beginning.
     65PASS: insertAtIndex with index zero should insert at the beginning.
     66PASS: insertAtIndex with 0 < index < length should insert at the correct location.
     67PASS: insertAtIndex with negative index should insert from the end.
     68PASS: insertAtIndex with index greater than array length should insert at the end.
     69
     70-- Running test case: Array.prototype.keySet
     71PASS: keySet should create an object with keys equal to the array values.
     72PASS: keySet should create an object with all values equal to true.
     73PASS: keySet should create an object with keys equal to stringified array values.
     74
  • trunk/LayoutTests/inspector/unit-tests/array-utilities.html

    r205872 r206085  
    1010    suite.addTestCase({
    1111        name: "Array.prototype.lowerBound",
    12         test: () => {
     12        test() {
    1313            // Index:  0  1  2  3  4  5  6  7  8  9
    1414            let arr = [0, 1, 2, 2, 2, 2, 2, 2, 6, 7];
     
    3131    suite.addTestCase({
    3232        name: "Array.prototype.upperBound",
    33         test: () => {
     33        test() {
    3434            // Index:  0  1  2  3  4  5  6  7  8  9
    3535            let arr = [0, 1, 2, 2, 2, 2, 2, 2, 6, 7];
     
    5252    suite.addTestCase({
    5353        name: "Array.prototype.binaryIndexOf",
    54         test: () => {
     54        test() {
    5555            // Index:  0  1  2  3  4  5  6  7  8  9
    5656            let arr = [0, 1, 2, 2, 2, 2, 2, 2, 6, 7];
     
    6666    suite.addTestCase({
    6767        name: "Array.prototype.partition",
    68         test: () => {
     68        test() {
    6969            let arr1 = [1, 2, 3, 4];
    7070            let [even, odd] = arr1.partition((x) => x % 2 === 0);
     
    8888    suite.addTestCase({
    8989        name: "Array.shallowEqual",
    90         test: () => {
     90        test() {
    9191            InspectorTest.expectThat(Array.shallowEqual([], []), "shallowEqual of empty arrays should be true.");
    9292
     
    108108            InspectorTest.expectFalse(Array.shallowEqual(str, str), "shallowEqual of a non-array with itself should be false.");
    109109            InspectorTest.expectFalse(Array.shallowEqual({}, {}), "shallowEqual of non-arrays should be false.");
     110
     111            return true;
     112        }
     113    });
     114
     115    suite.addTestCase({
     116        name: "Array.prototype.lastValue",
     117        test() {
     118            let object1 = {};
     119            let object2 = {};
     120            InspectorTest.expectEqual([object1, object2].lastValue, object2, "lastValue of a nonempty array should be the last value.")
     121            InspectorTest.expectEqual([].lastValue, undefined, "lastValue of an empty array should be undefined.")
     122
     123            return true;
     124        }
     125    });
     126
     127    suite.addTestCase({
     128        name: "Array.prototype.remove",
     129        test() {
     130            let arr1 = [1, 2, 3, 1];
     131            arr1.remove(1, true);
     132            // Note: Array.prototype.remove starts searching from the end of the array.
     133            InspectorTest.expectShallowEqual(arr1, [1, 2, 3], "remove with onlyFirst equal to true should only remove the first matching value.");
     134
     135            let arr2 = [1, 2, 3, 1];
     136            arr2.remove(1, false);
     137            InspectorTest.expectShallowEqual(arr2, [2, 3], "remove with onlyFirst equal to false should remove all matching values.");
     138
     139            let arr3 = [1, 2, 3, 1];
     140            arr3.remove(1);
     141            InspectorTest.expectShallowEqual(arr3, [2, 3], "remove with onlyFirst unspecified should remove all matching values.");
     142
     143            return true;
     144        }
     145    });
     146
     147    suite.addTestCase({
     148        name: "Array.prototype.toggleIncludes",
     149        test() {
     150            let arr1 = [1, 2, 3];
     151            arr1.toggleIncludes(3, true);
     152            InspectorTest.expectShallowEqual(arr1, [1, 2, 3], "toggleIncludes of an existing item with force true should have no effect.");
     153
     154            let arr2 = [1, 2, 3];
     155            arr2.toggleIncludes(3, false);
     156            InspectorTest.expectShallowEqual(arr2, [1, 2], "toggleIncludes of an existing item with force false should remove the item.");
     157
     158            let arr3 = [1, 2, 3];
     159            arr3.toggleIncludes(4, true);
     160            InspectorTest.expectShallowEqual(arr3, [1, 2, 3, 4], "toggleIncludes of a nonexistent item with force true should add the item.");
     161
     162            let arr4 = [1, 2, 3];
     163            arr4.toggleIncludes(4, false);
     164            InspectorTest.expectShallowEqual(arr4, [1, 2, 3], "toggleIncludes of a nonexistent item with force false should have no effect.");
     165
     166            return true;
     167        }
     168    });
     169
     170    suite.addTestCase({
     171        name: "Array.prototype.insertAtIndex",
     172        test() {
     173            let arr1 = [1, 2, 3];
     174            arr1.insertAtIndex("x");
     175            InspectorTest.expectShallowEqual(arr1, ["x", 1, 2, 3], "insertAtIndex with index unspecified should insert at the beginning.");
     176
     177            let arr2 = [1, 2, 3];
     178            arr2.insertAtIndex("x", 0);
     179            InspectorTest.expectShallowEqual(arr2, ["x", 1, 2, 3], "insertAtIndex with index zero should insert at the beginning.");
     180
     181            let arr3 = [1, 2, 3];
     182            arr3.insertAtIndex("x", 2);
     183            InspectorTest.expectShallowEqual(arr3, [1, 2, "x", 3], "insertAtIndex with 0 < index < length should insert at the correct location.");
     184
     185            let arr4 = [1, 2, 3];
     186            arr4.insertAtIndex("x", -1);
     187            InspectorTest.expectShallowEqual(arr4, [1, 2, "x", 3], "insertAtIndex with negative index should insert from the end.");
     188
     189            let arr5 = [1, 2, 3];
     190            arr5.insertAtIndex("x", 100);
     191            InspectorTest.expectShallowEqual(arr5, [1, 2, 3, "x"], "insertAtIndex with index greater than array length should insert at the end.");
     192
     193            return true;
     194        }
     195    });
     196
     197    suite.addTestCase({
     198        name: "Array.prototype.keySet",
     199        test() {
     200            let arr1 = ["abc", "def", "xyz"];
     201            let keySet = arr1.keySet();
     202            InspectorTest.expectShallowEqual(Object.keys(keySet), arr1, "keySet should create an object with keys equal to the array values.");
     203            InspectorTest.expectShallowEqual(Object.values(keySet), [true, true, true], "keySet should create an object with all values equal to true.");
     204
     205            let arr2 = [1, 2, 3];
     206            InspectorTest.expectShallowEqual(Object.keys(arr2.keySet()), arr2.map(x => x.toString()), "keySet should create an object with keys equal to stringified array values.");
    110207
    111208            return true;
Note: See TracChangeset for help on using the changeset viewer.