Changeset 270149 in webkit


Ignore:
Timestamp:
Nov 21, 2020 11:08:51 AM (3 years ago)
Author:
BJ Burg
Message:

Web Inspector: implement Multimap.prototype.take()
https://bugs.webkit.org/show_bug.cgi?id=219231

Reviewed by Devin Rousso.

Source/WebInspectorUI:

  • UserInterface/Base/Multimap.js:

(Multimap.prototype.take):

  • UserInterface/Base/Utilities.js:

(value):

LayoutTests:

  • inspector/unit-tests/multimap-expected.txt:
  • inspector/unit-tests/multimap.html:
  • inspector/unit-tests/set-utilities.html:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r270148 r270149  
     12020-11-21  Brian Burg  <bburg@apple.com>
     2
     3        Web Inspector: implement Multimap.prototype.take()
     4        https://bugs.webkit.org/show_bug.cgi?id=219231
     5
     6        Reviewed by Devin Rousso.
     7
     8        * inspector/unit-tests/multimap-expected.txt:
     9        * inspector/unit-tests/multimap.html:
     10        * inspector/unit-tests/set-utilities.html:
     11
    1122020-11-21  Aditya Keerthi  <akeerthi@apple.com>
    213
  • trunk/LayoutTests/inspector/unit-tests/multimap-expected.txt

    r243264 r270149  
    5858[["raccoon","opossum"]]
    5959
     60-- Running test case: Multimap.prototype.take.SingleKeyAndValue
     61[[0,1],[2,3],[2,4]]
     621
     63PASS: The key 0 and the value 1 were taken.
     64PASS: Only one key should remain.
     65[[2,3],[2,4]]
     66undefined
     67PASS: Nothing should have been taken.
     68PASS: Only one key should remain.
     69[[2,3],[2,4]]
     703
     71PASS: The key 2 and the value 3 were taken.
     72PASS: Only one key should remain.
     73[[2,4]]
     744
     75PASS: The key 2 and the value 4 were taken.
     76PASS: No more keys should remain.
     77[]
     78
     79-- Running test case: Multimap.prototype.take.AllValuesForKey
     80[["opossum","badger"],["opossum","raccoon"],["raccoon","opossum"]]
     81PASS: Nothing was removed for key "badger".
     82[["opossum","badger"],["opossum","raccoon"],["raccoon","opossum"]]
     83PASS: Only one key should remain.
     84PASS: Two values from the key "opossum" should be taken.
     85PASS: Result should include "badger".
     86PASS: Result should include "raccoon".
     87[["raccoon","opossum"]]
     88
    6089-- Running test case: Multimap.prototype.clear
    6190[["one","two"],["one","five"],["three","four"],["three","six"]]
  • trunk/LayoutTests/inspector/unit-tests/multimap.html

    r243264 r270149  
    166166
    167167    suite.addTestCase({
     168        name: "Multimap.prototype.take.SingleKeyAndValue",
     169        test() {
     170            let multimap = new Multimap;
     171            let result;
     172
     173            multimap.add(0, 1);
     174            multimap.add(2, 3);
     175            multimap.add(2, 4);
     176
     177            InspectorTest.log(multimap);
     178
     179            result = multimap.take(0, 1);
     180            InspectorTest.log(result);
     181            InspectorTest.expectEqual(result, 1, "The key 0 and the value 1 were taken.");
     182            InspectorTest.expectEqual(multimap.size, 1, "Only one key should remain.");
     183
     184            InspectorTest.log(multimap);
     185
     186            result = multimap.take(5, 1);
     187            InspectorTest.log(result);
     188            InspectorTest.expectEqual(result, undefined, "Nothing should have been taken.");
     189            InspectorTest.expectEqual(multimap.size, 1, "Only one key should remain.");
     190
     191            InspectorTest.log(multimap);
     192
     193            result = multimap.take(2, 3)
     194            InspectorTest.log(result);
     195            InspectorTest.expectEqual(result, 3, "The key 2 and the value 3 were taken.");
     196            InspectorTest.expectEqual(multimap.size, 1, "Only one key should remain.");
     197
     198            InspectorTest.log(multimap);
     199
     200            result = multimap.take(2, 4)
     201            InspectorTest.log(result);
     202            InspectorTest.expectEqual(result, 4, "The key 2 and the value 4 were taken.");
     203            InspectorTest.expectEqual(multimap.size, 0, "No more keys should remain.");
     204
     205            InspectorTest.log(multimap);
     206        },
     207    });
     208
     209    suite.addTestCase({
     210        name: "Multimap.prototype.take.AllValuesForKey",
     211        test() {
     212            let multimap = new Multimap;
     213
     214            multimap.add("opossum", "badger");
     215            multimap.add("opossum", "raccoon");
     216            multimap.add("raccoon", "opossum");
     217
     218            InspectorTest.log(multimap);
     219            InspectorTest.expectFalse(multimap.take("badger"), `Nothing was removed for key "badger".`);
     220
     221            InspectorTest.log(multimap);
     222
     223            let result = multimap.take("opossum");
     224            InspectorTest.expectEqual(multimap.size, 1, `Only one key should remain.`);
     225            InspectorTest.expectEqual(result.size, 2, `Two values from the key "opossum" should be taken.`);
     226            InspectorTest.expectThat(result.has("badger"), `Result should include "badger".`);
     227            InspectorTest.expectThat(result.has("raccoon"), `Result should include "raccoon".`);
     228
     229            InspectorTest.log(multimap);
     230        },
     231    });
     232
     233    suite.addTestCase({
    168234        name: "Multimap.prototype.clear",
    169235        test() {
  • trunk/LayoutTests/inspector/unit-tests/set-utilities.html

    r262806 r270149  
    107107            let set = new Set;
    108108            set.add(key);
    109             InspectorTest.expectTrue(set.take(key), "Set can take `key`.");
     109            InspectorTest.expectEqual(set.take(key), key, "Set can take `key`.");
    110110            InspectorTest.expectFalse(set.has(key), "Set no longer has `key`.");
    111             InspectorTest.expectFalse(set.take(key), "Set can NOT take `key`.");
    112             InspectorTest.expectFalse(set.take("DNE"), "Set can NOT take `DNE`, as it does NOT exist.");
     111            InspectorTest.expectEqual(set.take(key), undefined, "Set can NOT take `key`.");
     112            InspectorTest.expectEqual(set.take("DNE"), undefined, "Set can NOT take `DNE`, as it does NOT exist.");
    113113        }
    114114    });
  • trunk/Source/WebInspectorUI/ChangeLog

    r270134 r270149  
     12020-11-21  Brian Burg  <bburg@apple.com>
     2
     3        Web Inspector: implement Multimap.prototype.take()
     4        https://bugs.webkit.org/show_bug.cgi?id=219231
     5
     6        Reviewed by Devin Rousso.
     7
     8        * UserInterface/Base/Multimap.js:
     9        (Multimap.prototype.take):
     10        * UserInterface/Base/Utilities.js:
     11        (value):
     12
    1132020-11-20  Devin Rousso  <drousso@apple.com>
    214
  • trunk/Source/WebInspectorUI/UserInterface/Base/Multimap.js

    r247053 r270149  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    8484    }
    8585
     86    take(key, value)
     87    {
     88        // Allow an entire key to be removed by not passing a value.
     89        if (arguments.length === 1)
     90            return this._map.take(key);
     91
     92        let valueSet = this._map.get(key);
     93        if (!valueSet)
     94            return undefined;
     95
     96        let result = valueSet.take(value);
     97        if (!valueSet.size)
     98            this._map.delete(key);
     99        return result;
     100    }
     101
    86102    clear()
    87103    {
  • trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js

    r268634 r270149  
    179179    value(key)
    180180    {
    181         let exists = this.has(key);
    182         if (exists)
     181        if (this.has(key)) {
    183182            this.delete(key);
    184         return exists;
     183            return key;
     184        }
     185
     186        return undefined;
    185187    }
    186188});
Note: See TracChangeset for help on using the changeset viewer.