Skip to content

Commit

Permalink
Fix from lint and formating
Browse files Browse the repository at this point in the history
  • Loading branch information
Hemenguelbindi committed Jan 26, 2025
1 parent ebc8c7d commit ad3510e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 43 deletions.
5 changes: 2 additions & 3 deletions core/engine/src/builtins/set/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsValue> {
// 1. Let S be the this value.
// 2. Perform ? RequireInternalSlot(S, [[SetData]]).
Expand Down Expand Up @@ -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());
Expand Down
51 changes: 11 additions & 40 deletions core/engine/src/builtins/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }"
}),

Expand All @@ -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]
Expand All @@ -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)"
})
]);
Expand All @@ -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 }"
}),
]);
Expand All @@ -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)
}),
]);
}
Expand All @@ -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)
}),
]);
}
Expand All @@ -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
}),
]);
Expand All @@ -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 }"
}),
]);
Expand All @@ -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 }"
}),
]);
Expand Down

0 comments on commit ad3510e

Please sign in to comment.