Skip to content

Commit

Permalink
$mol_compare_deep: All $mol_range2 is unique
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Sep 22, 2023
1 parent 151e1fe commit cb4db67
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions compare/deep/deep.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ namespace $ {
} ,

'Array'() {

$mol_assert_ok( $mol_compare_deep( [] , [] ) )
$mol_assert_ok( $mol_compare_deep( [ 1 , [2] ] , [ 1 , [2] ] ) )

$mol_assert_not( $mol_compare_deep( [ 1 , 2 ] , [ 1 , 3 ] ) )
$mol_assert_not( $mol_compare_deep( [ 1 , 2 , ] , [ 1 , 3 , undefined ] ) )

$mol_assert_not( $mol_compare_deep( $mol_range2().slice(0,0), new Array() ) )
$mol_assert_not( $mol_compare_deep( $mol_range2(), $mol_range2() ) )

} ,

'Non POJO are different'() {
Expand Down
2 changes: 1 addition & 1 deletion compare/deep/deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ namespace $ {

if( !left_proto ) result = compare_pojo( left, right as any )
else if( !Reflect.getPrototypeOf( left_proto ) ) result = compare_pojo( left, right as any )
else if( Symbol.toPrimitive in left ) result = compare_primitive( left, right )
else if( Array.isArray( left ) ) result = compare_array( left, right as any )
else if( left instanceof Set ) result = compare_set( left, right as any )
else if( left instanceof Map ) result = compare_map( left, right as any )
else if( ArrayBuffer.isView( left ) ) result = compare_buffer( left, right as any )
else if( Symbol.iterator in left ) result = compare_iterator( ( left as any )[ Symbol.iterator ](), ( right as any )[ Symbol.iterator ]() )
else if( Symbol.toPrimitive in left ) result = compare_primitive( left, right )
else result = false

} finally {
Expand Down
4 changes: 4 additions & 0 deletions range2/range2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ namespace $ {
sort() {
return $mol_fail( new TypeError( `Mutable sort is forbidden. Use toSorted instead.` ) )
}

[Symbol.toPrimitive]() {
return $mol_guid()
}

}

Expand Down

0 comments on commit cb4db67

Please sign in to comment.