Title: [270149] trunk
Revision
270149
Author
[email protected]
Date
2020-11-21 11:08:51 -0800 (Sat, 21 Nov 2020)

Log 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:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (270148 => 270149)


--- trunk/LayoutTests/ChangeLog	2020-11-21 17:24:24 UTC (rev 270148)
+++ trunk/LayoutTests/ChangeLog	2020-11-21 19:08:51 UTC (rev 270149)
@@ -1,3 +1,14 @@
+2020-11-21  Brian Burg  <[email protected]>
+
+        Web Inspector: implement Multimap.prototype.take()
+        https://bugs.webkit.org/show_bug.cgi?id=219231
+
+        Reviewed by Devin Rousso.
+
+        * inspector/unit-tests/multimap-expected.txt:
+        * inspector/unit-tests/multimap.html:
+        * inspector/unit-tests/set-utilities.html:
+
 2020-11-21  Aditya Keerthi  <[email protected]>
 
         Space between minute and meridiem fields in time inputs is too large

Modified: trunk/LayoutTests/inspector/unit-tests/multimap-expected.txt (270148 => 270149)


--- trunk/LayoutTests/inspector/unit-tests/multimap-expected.txt	2020-11-21 17:24:24 UTC (rev 270148)
+++ trunk/LayoutTests/inspector/unit-tests/multimap-expected.txt	2020-11-21 19:08:51 UTC (rev 270149)
@@ -57,6 +57,35 @@
 PASS: Values were removed for key "opossum".
 [["raccoon","opossum"]]
 
+-- Running test case: Multimap.prototype.take.SingleKeyAndValue
+[[0,1],[2,3],[2,4]]
+1
+PASS: The key 0 and the value 1 were taken.
+PASS: Only one key should remain.
+[[2,3],[2,4]]
+undefined
+PASS: Nothing should have been taken.
+PASS: Only one key should remain.
+[[2,3],[2,4]]
+3
+PASS: The key 2 and the value 3 were taken.
+PASS: Only one key should remain.
+[[2,4]]
+4
+PASS: The key 2 and the value 4 were taken.
+PASS: No more keys should remain.
+[]
+
+-- Running test case: Multimap.prototype.take.AllValuesForKey
+[["opossum","badger"],["opossum","raccoon"],["raccoon","opossum"]]
+PASS: Nothing was removed for key "badger".
+[["opossum","badger"],["opossum","raccoon"],["raccoon","opossum"]]
+PASS: Only one key should remain.
+PASS: Two values from the key "opossum" should be taken.
+PASS: Result should include "badger".
+PASS: Result should include "raccoon".
+[["raccoon","opossum"]]
+
 -- Running test case: Multimap.prototype.clear
 [["one","two"],["one","five"],["three","four"],["three","six"]]
 []

Modified: trunk/LayoutTests/inspector/unit-tests/multimap.html (270148 => 270149)


--- trunk/LayoutTests/inspector/unit-tests/multimap.html	2020-11-21 17:24:24 UTC (rev 270148)
+++ trunk/LayoutTests/inspector/unit-tests/multimap.html	2020-11-21 19:08:51 UTC (rev 270149)
@@ -165,6 +165,72 @@
     });
 
     suite.addTestCase({
+        name: "Multimap.prototype.take.SingleKeyAndValue",
+        test() {
+            let multimap = new Multimap;
+            let result;
+
+            multimap.add(0, 1);
+            multimap.add(2, 3);
+            multimap.add(2, 4);
+
+            InspectorTest.log(multimap);
+
+            result = multimap.take(0, 1);
+            InspectorTest.log(result);
+            InspectorTest.expectEqual(result, 1, "The key 0 and the value 1 were taken.");
+            InspectorTest.expectEqual(multimap.size, 1, "Only one key should remain.");
+
+            InspectorTest.log(multimap);
+
+            result = multimap.take(5, 1);
+            InspectorTest.log(result);
+            InspectorTest.expectEqual(result, undefined, "Nothing should have been taken.");
+            InspectorTest.expectEqual(multimap.size, 1, "Only one key should remain.");
+
+            InspectorTest.log(multimap);
+
+            result = multimap.take(2, 3)
+            InspectorTest.log(result);
+            InspectorTest.expectEqual(result, 3, "The key 2 and the value 3 were taken.");
+            InspectorTest.expectEqual(multimap.size, 1, "Only one key should remain.");
+
+            InspectorTest.log(multimap);
+
+            result = multimap.take(2, 4)
+            InspectorTest.log(result);
+            InspectorTest.expectEqual(result, 4, "The key 2 and the value 4 were taken.");
+            InspectorTest.expectEqual(multimap.size, 0, "No more keys should remain.");
+
+            InspectorTest.log(multimap);
+        },
+    });
+
+    suite.addTestCase({
+        name: "Multimap.prototype.take.AllValuesForKey",
+        test() {
+            let multimap = new Multimap;
+
+            multimap.add("opossum", "badger");
+            multimap.add("opossum", "raccoon");
+            multimap.add("raccoon", "opossum");
+
+            InspectorTest.log(multimap);
+            InspectorTest.expectFalse(multimap.take("badger"), `Nothing was removed for key "badger".`);
+
+            InspectorTest.log(multimap);
+
+            let result = multimap.take("opossum");
+            InspectorTest.expectEqual(multimap.size, 1, `Only one key should remain.`);
+            InspectorTest.expectEqual(result.size, 2, `Two values from the key "opossum" should be taken.`);
+            InspectorTest.expectThat(result.has("badger"), `Result should include "badger".`);
+            InspectorTest.expectThat(result.has("raccoon"), `Result should include "raccoon".`);
+
+            InspectorTest.log(multimap);
+        },
+    });
+
+    suite.addTestCase({
         name: "Multimap.prototype.clear",
         test() {
             let multimap = new Multimap;

Modified: trunk/LayoutTests/inspector/unit-tests/set-utilities.html (270148 => 270149)


--- trunk/LayoutTests/inspector/unit-tests/set-utilities.html	2020-11-21 17:24:24 UTC (rev 270148)
+++ trunk/LayoutTests/inspector/unit-tests/set-utilities.html	2020-11-21 19:08:51 UTC (rev 270149)
@@ -106,10 +106,10 @@
 
             let set = new Set;
             set.add(key);
-            InspectorTest.expectTrue(set.take(key), "Set can take `key`.");
+            InspectorTest.expectEqual(set.take(key), key, "Set can take `key`.");
             InspectorTest.expectFalse(set.has(key), "Set no longer has `key`.");
-            InspectorTest.expectFalse(set.take(key), "Set can NOT take `key`.");
-            InspectorTest.expectFalse(set.take("DNE"), "Set can NOT take `DNE`, as it does NOT exist.");
+            InspectorTest.expectEqual(set.take(key), undefined, "Set can NOT take `key`.");
+            InspectorTest.expectEqual(set.take("DNE"), undefined, "Set can NOT take `DNE`, as it does NOT exist.");
         }
     });
 

Modified: trunk/Source/WebInspectorUI/ChangeLog (270148 => 270149)


--- trunk/Source/WebInspectorUI/ChangeLog	2020-11-21 17:24:24 UTC (rev 270148)
+++ trunk/Source/WebInspectorUI/ChangeLog	2020-11-21 19:08:51 UTC (rev 270149)
@@ -1,3 +1,15 @@
+2020-11-21  Brian Burg  <[email protected]>
+
+        Web Inspector: implement Multimap.prototype.take()
+        https://bugs.webkit.org/show_bug.cgi?id=219231
+
+        Reviewed by Devin Rousso.
+
+        * UserInterface/Base/Multimap.js:
+        (Multimap.prototype.take):
+        * UserInterface/Base/Utilities.js:
+        (value):
+
 2020-11-20  Devin Rousso  <[email protected]>
 
         Web Inspector: drop `shown`/`hidden` in favor of `attached`/`detached`

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Multimap.js (270148 => 270149)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Multimap.js	2020-11-21 17:24:24 UTC (rev 270148)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Multimap.js	2020-11-21 19:08:51 UTC (rev 270149)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2018-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -83,6 +83,22 @@
         return deleted;
     }
 
+    take(key, value)
+    {
+        // Allow an entire key to be removed by not passing a value.
+        if (arguments.length === 1)
+            return this._map.take(key);
+
+        let valueSet = this._map.get(key);
+        if (!valueSet)
+            return undefined;
+
+        let result = valueSet.take(value);
+        if (!valueSet.size)
+            this._map.delete(key);
+        return result;
+    }
+
     clear()
     {
         this._map.clear();

Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js (270148 => 270149)


--- trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2020-11-21 17:24:24 UTC (rev 270148)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js	2020-11-21 19:08:51 UTC (rev 270149)
@@ -178,10 +178,12 @@
 {
     value(key)
     {
-        let exists = this.has(key);
-        if (exists)
+        if (this.has(key)) {
             this.delete(key);
-        return exists;
+            return key;
+        }
+
+        return undefined;
     }
 });
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to