From ad3510ef6a84f7fcc0b695bd59bb61e38eeac75d Mon Sep 17 00:00:00 2001 From: Vicktor Karpov Date: Sun, 26 Jan 2025 20:49:42 +0500 Subject: [PATCH] Fix from lint and formating --- core/engine/src/builtins/set/mod.rs | 5 ++- core/engine/src/builtins/set/tests.rs | 51 ++++++--------------------- 2 files changed, 13 insertions(+), 43 deletions(-) diff --git a/core/engine/src/builtins/set/mod.rs b/core/engine/src/builtins/set/mod.rs index 5c36ff2020c..bc63933e3de 100644 --- a/core/engine/src/builtins/set/mod.rs +++ b/core/engine/src/builtins/set/mod.rs @@ -509,7 +509,6 @@ impl Set { /// /// [spec]: https://tc39.es/ecma262/#sec-set.prototype.difference /// [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/difference - pub(crate) fn difference(this: &JsValue, args: &[JsValue], context: &mut Context) -> JsResult { // 1. Let S be the this value. // 2. Perform ? RequireInternalSlot(S, [[SetData]]). @@ -869,8 +868,8 @@ impl Set { for value in other_set.iter() { // If value is in the current set, remove it from result_set. - if set.contains(&value) { - result_set.delete(&value); + if set.contains(value) { + result_set.delete(value); } else { // Otherwise, add it to result_set. result_set.add(value.clone()); diff --git a/core/engine/src/builtins/set/tests.rs b/core/engine/src/builtins/set/tests.rs index e10c31ab233..48c97a0fda5 100644 --- a/core/engine/src/builtins/set/tests.rs +++ b/core/engine/src/builtins/set/tests.rs @@ -186,12 +186,10 @@ fn difference() { TestAction::assert_with_op("setA.difference(setB)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set { 3, 5, 7 }" }), TestAction::assert_with_op("setB.difference(setA)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set { 4 }" }), @@ -207,15 +205,13 @@ fn difference_equal_set(){ "#}), TestAction::assert_with_op("setA.difference(setB)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set { 3 }" }), TestAction::assert_with_op("setB.difference(setA)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set { 4 }" }), - ]) + ]); } #[test] @@ -227,11 +223,9 @@ fn difference_empty(){ "#}), TestAction::assert_with_op("setA.difference(setB)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set { 1, 3, 5, 7, 9 }" }), TestAction::assert_with_op("setB.difference(setA)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set(0)" }) ]); @@ -250,27 +244,21 @@ fn intersection(){ }), TestAction::assert_with_op("setA.intersection(setB)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set { 1, 3 }" }), TestAction::assert_with_op("setB.intersection(setA)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set { 1, 3 }" }), TestAction::assert_with_op("setA.intersection(setA)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set { 1, 2, 3 }" }), TestAction::assert_with_op("setB.intersection(setB)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set { 1, 4, 3 }" }), TestAction::assert_with_op("setB.intersection(setC)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set { 1, 4, 3 }" }), TestAction::assert_with_op("setA.intersection(setC)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); v.display().to_string() == "Set { 1, 2, 3 }" }), ]); @@ -287,12 +275,10 @@ fn is_dist_joint_from() { "# }), TestAction::assert_with_op("setA.isDisjointFrom(setB)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); - v.as_boolean().unwrap_or(false) == false + !v.as_boolean().unwrap_or(false) }), TestAction::assert_with_op("setA.isDisjointFrom(setC)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); - v.as_boolean().unwrap_or(true) == true + v.as_boolean().unwrap_or(true) }), ]); } @@ -310,32 +296,25 @@ fn is_subset_of(){ "# }), TestAction::assert_with_op("setA.isSubsetOf(setB)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); - v.as_boolean().unwrap_or(false) == false + !v.as_boolean().unwrap_or(false) }), TestAction::assert_with_op("setA.isSubsetOf(setC)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); - v.as_boolean().unwrap_or(true) == true + v.as_boolean().unwrap_or(true) }), TestAction::assert_with_op("setB.isSubsetOf(setC)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); - v.as_boolean().unwrap_or(false) == false + !v.as_boolean().unwrap_or(false) }), TestAction::assert_with_op("setC.isSubsetOf(setC)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); - v.as_boolean().unwrap_or(true) == true + v.as_boolean().unwrap_or(true) }), TestAction::assert_with_op("setD.isSubsetOf(setC)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); - v.as_boolean().unwrap_or(true) == true + v.as_boolean().unwrap_or(true) }), TestAction::assert_with_op("setE.isSubsetOf(setC)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); - v.as_boolean().unwrap_or(true) == true + v.as_boolean().unwrap_or(true) }), TestAction::assert_with_op("setA.isSubsetOf(setE)", |v, _| { - println!("Difference result: {:?}", v.display().to_string()); - v.as_boolean().unwrap_or(false) == false + !v.as_boolean().unwrap_or(false) }), ]); } @@ -350,11 +329,9 @@ fn is_superset_of(){ "# }), TestAction::assert_with_op("setA.isSupersetOf(setB)", |v, _| { - println!("Result for setA.isSupersetOf(setB): {:?}", v.display().to_string()); v.as_boolean().unwrap_or(false) == true }), TestAction::assert_with_op("setB.isSupersetOf(setA)", |v, _| { - println!("Result for setB.isSupersetOf(setA): {:?}", v.display().to_string()); v.as_boolean().unwrap_or(false) == false }), ]); @@ -372,23 +349,19 @@ fn symmetric_difference(){ "# }), TestAction::assert_with_op("setA.symmetricDifference(setB)", |v, _| { - println!("Result for setA.isSupersetOf(setB): {:?}", v.display().to_string()); v.display().to_string() == "Set { \"HTML\", \"CSS\", \"Python\", \"Java\", \"PHP\" }" }), TestAction::assert_with_op("setB.symmetricDifference(setA)", |v, _| { - println!("Result for setB.isSupersetOf(setA): {:?}", v.display().to_string()); v.display().to_string() == "Set { \"Python\", \"Java\", \"PHP\", \"HTML\", \"CSS\" }" }), TestAction::assert_with_op("setA.symmetricDifference(setA)", |v, _| { - println!("Result for setB.isSupersetOf(setA): {:?}", v.display().to_string()); v.display().to_string() == "Set(0)" }), TestAction::assert_with_op("setC.symmetricDifference(setD)", |v, _| { - println!("Result for setB.isSupersetOf(setA): {:?}", v.display().to_string()); v.display().to_string() == "Set { 2, 6, 8, 1, 9 }" }), TestAction::assert_with_op("setD.symmetricDifference(setC)", |v, _| { - println!("Result for setB.isSupersetOf(setA): {:?}", v.display().to_string()); + v.display().to_string() == "Set { 1, 9, 2, 6, 8 }" }), ]); @@ -406,11 +379,9 @@ fn union(){ "# }), TestAction::assert_with_op("setA.union(setB)", |v, _| { - println!("Result for setA.isSupersetOf(setB): {:?}", v.display().to_string()); v.display().to_string() == "Set { 2, 4, 6, 8, 1, 9 }" }), TestAction::assert_with_op("setB.union(setA)", |v, _| { - println!("Result for setB.isSupersetOf(setA): {:?}", v.display().to_string()); v.display().to_string() == "Set { 1, 4, 9, 2, 6, 8 }" }), ]);