From 6db6fe97eca4d6c750583d2dc192ab6867e2bd4b Mon Sep 17 00:00:00 2001 From: make-github-pseudonymous-again <5165674+make-github-pseudonymous-again@users.noreply.github.com> Date: Sun, 4 Sep 2022 08:52:39 +0200 Subject: [PATCH] :shirt: refactor: Lint source files. --- doc/scripts/header.js | 40 ++-- package.json | 2 +- src/NativeSet.js | 2 +- src/_Set.js | 338 ++++++++++++++------------------- src/_set.js | 17 +- src/index.js | 21 +-- test/src/set.js | 421 ++++++++++++++++++++++++------------------ yarn.lock | 10 +- 8 files changed, 421 insertions(+), 430 deletions(-) diff --git a/doc/scripts/header.js b/doc/scripts/header.js index ae66ba7..7bb0a2c 100644 --- a/doc/scripts/header.js +++ b/doc/scripts/header.js @@ -1,34 +1,30 @@ -var domReady = function(callback) { - var state = document.readyState ; - if ( state === 'interactive' || state === 'complete' ) { - callback() ; - } - else { +const domReady = function (callback) { + const state = document.readyState; + if (state === 'interactive' || state === 'complete') { + callback(); + } else { document.addEventListener('DOMContentLoaded', callback); } -} ; - +}; -domReady(function(){ - - var projectname = document.createElement('a'); +domReady(function () { + const projectname = document.createElement('a'); projectname.classList.add('project-name'); projectname.text = 'collection-abstraction/set'; - projectname.href = './index.html' ; + projectname.href = './index.html'; - var header = document.getElementsByTagName('header')[0] ; - header.insertBefore(projectname,header.firstChild); + const header = document.querySelectorAll('header')[0]; + header.insertBefore(projectname, header.firstChild); - var testlink = document.querySelector('header > a[data-ice="testLink"]') ; - testlink.href = 'https://coveralls.io/github/collection-abstraction/set' ; - testlink.target = '_BLANK' ; + const testlink = document.querySelector('header > a[data-ice="testLink"]'); + testlink.href = 'https://coveralls.io/github/collection-abstraction/set'; + testlink.target = '_BLANK'; - var searchBox = document.querySelector('.search-box'); - var input = document.querySelector('.search-input'); + const searchBox = document.querySelector('.search-box'); + const input = document.querySelector('.search-input'); - // active search box when focus on searchBox. - input.addEventListener('focus', function(){ + // Active search box when focus on searchBox. + input.addEventListener('focus', function () { searchBox.classList.add('active'); }); - }); diff --git a/package.json b/package.json index 3048527..4b954ff 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "travis": "npm run lint-config && npm run lint && npm run cover" }, "dependencies": { - "@aureooms/js-error": "^5.0.0" + "@failure-abstraction/error": "^6.0.1" }, "devDependencies": { "@babel/core": "7.13.10", diff --git a/src/NativeSet.js b/src/NativeSet.js index ce26214..3c2b0ba 100644 --- a/src/NativeSet.js +++ b/src/NativeSet.js @@ -1 +1 @@ -export default Set ; +export default Set; diff --git a/src/_Set.js b/src/_Set.js index a262e2c..37387c8 100644 --- a/src/_Set.js +++ b/src/_Set.js @@ -1,258 +1,198 @@ -import { KeyError } from '@aureooms/js-error' ; +import {KeyError} from '@failure-abstraction/error'; -export default function _Set ( BaseSet ) { +export default function _Set(BaseSet) { + /* eslint-disable no-use-extend-native/no-use-extend-native */ + const Set = function (iterable = null) { + this.container = new BaseSet(iterable); + }; - const Set = function ( iterable = null ) { + Set.wrap = function (A) { + if (A instanceof Set) return A; - this.container = new BaseSet( iterable ) ; + return new Set(A); + }; - } ; + Set._operator = function (method) { + return function (...args) { + return method.apply(this, Array.from(args, Set.wrap)); + }; + }; - Set.wrap = function ( A ) { + Set._inclusion = function (A, B) { + return A._ispropersubset(B) ? -1 : B._ispropersubset(A) ? 1 : 0; + }; - if ( A instanceof Set ) return A ; + Set.inclusion = Set._operator(Set._inclusion); - return new Set( A ) ; + // eslint-disable-next-line no-multi-assign + Set.prototype[Symbol.iterator] = Set.prototype.keys = function* () { + yield* this.container; + }; - } ; + Set.prototype.len = function () { + return this.container.size; + }; - Set._operator = function ( method ) { + Set.prototype.has = function (key) { + return this.container.has(key); + }; - return function ( ...args ) { + Set.prototype._isdisjoint = function (other) { + return this._commonkeys(other).next().done; + }; - return method.apply( this , Array.from( args , Set.wrap ) ) ; + Set.prototype.isdisjoint = Set._operator(Set.prototype._isdisjoint); - } ; + Set.prototype._isequal = function (other) { + return this._issubset(other) && other._issubset(this); + }; - } ; + Set.prototype.isequal = Set._operator(Set.prototype._isequal); - Set._inclusion = function ( A , B ) { + Set.prototype._issubset = function (other) { + if (this.len() > other.len()) return false; - return A._ispropersubset( B ) ? -1 : B._ispropersubset( A ) ? 1 : 0 ; + for (const key of this) if (!other.has(key)) return false; - } ; + return true; + }; - Set.inclusion = Set._operator( Set._inclusion ) ; + Set.prototype.issubset = Set._operator(Set.prototype._issubset); - Set.prototype[Symbol.iterator] = - Set.prototype.keys = function* ( ) { + Set.prototype._ispropersubset = function (other) { + return this._issubset(other) && !this._issuperset(other); + }; - yield* this.container ; + Set.prototype.ispropersubset = Set._operator(Set.prototype._ispropersubset); - } ; + Set.prototype._issuperset = function (other) { + return other._issubset(this); + }; - Set.prototype.len = function ( ) { + Set.prototype.issuperset = Set._operator(Set.prototype._issuperset); - return this.container.size ; + Set.prototype._ispropersuperset = function (other) { + return this._issuperset(other) && !this._issubset(other); + }; - } ; + Set.prototype.ispropersuperset = Set._operator( + Set.prototype._ispropersuperset, + ); - Set.prototype.has = function ( key ) { - - return this.container.has( key ) ; - - } ; - - Set.prototype._isdisjoint = function ( other ) { - - return this._commonkeys( other ).next( ).done ; - - } ; - - Set.prototype.isdisjoint = Set._operator( Set.prototype._isdisjoint ) ; - - Set.prototype._isequal = function ( other ) { - - return this._issubset( other ) && other._issubset( this ) ; - - } ; - - Set.prototype.isequal = Set._operator( Set.prototype._isequal ) ; - - Set.prototype._issubset = function ( other ) { - - if ( this.len( ) > other.len( ) ) return false ; - - for ( let key of this ) if ( !other.has( key ) ) return false ; - - return true ; - - } ; - - Set.prototype.issubset = Set._operator( Set.prototype._issubset ) ; - - Set.prototype._ispropersubset = function ( other ) { - - return this._issubset( other ) && !this._issuperset( other ) ; - - } ; - - Set.prototype.ispropersubset = Set._operator( Set.prototype._ispropersubset ) ; - - Set.prototype._issuperset = function ( other ) { - - return other._issubset( this ) ; - - } ; - - Set.prototype.issuperset = Set._operator( Set.prototype._issuperset ) ; - - Set.prototype._ispropersuperset = function ( other ) { - - return this._issuperset( other ) && !this._issubset( other ) ; - - } ; - - Set.prototype.ispropersuperset = Set._operator( Set.prototype._ispropersuperset ) ; - - Set.prototype.union = - Set.prototype._union = function ( ...others ) { - - return this.copy( )._update( ...others ) ; - - } ; - - Set.prototype._commonkeys = function* ( ...others ) { - - keys : for ( let key of this ) { - - for ( let other of others ) { - - if ( !other.has( key ) ) continue keys ; + // eslint-disable-next-line no-multi-assign + Set.prototype.union = Set.prototype._union = function (...others) { + return this.copy()._update(...others); + }; + Set.prototype._commonkeys = function* (...others) { + // eslint-disable-next-line no-labels + keys: for (const key of this) { + for (const other of others) { + // eslint-disable-next-line no-labels + if (!other.has(key)) continue keys; } - yield key ; - + yield key; } + }; - } ; - - - Set.prototype._intersection = function ( ...others ) { + Set.prototype._intersection = function (...others) { + return new Set(this._commonkeys(...others)); + }; - return new Set( this._commonkeys( ...others ) ) ; + Set.prototype.intersection = Set._operator(Set.prototype._intersection); - } ; + // eslint-disable-next-line no-multi-assign + Set.prototype.difference = Set.prototype._difference = function (...others) { + return this.copy()._difference_update(...others); + }; - Set.prototype.intersection = Set._operator( Set.prototype._intersection ) ; + // eslint-disable-next-line no-multi-assign + Set.prototype.symmetric_difference = Set.prototype._symmetric_difference = + function (other) { + return this.copy()._symmetric_difference_update(other); + }; - Set.prototype.difference = - Set.prototype._difference = function ( ...others ) { - - return this.copy( )._difference_update( ...others ) ; - - } ; - - Set.prototype.symmetric_difference = - Set.prototype._symmetric_difference = function ( other ) { - - return this.copy( )._symmetric_difference_update( other ) ; - - } ; - - Set.prototype.copy = function ( ) { - - return new Set( this ) ; - - } ; - - Set.prototype.update = - Set.prototype._update = function ( ...others ) { - - for ( let other of others ) { - - for ( let key of other ) this.add( key ) ; + Set.prototype.copy = function () { + return new Set(this); + }; + // eslint-disable-next-line no-multi-assign + Set.prototype.update = Set.prototype._update = function (...others) { + for (const other of others) { + for (const key of other) this.add(key); } - return this ; - - } ; - - Set.prototype._intersection_update = function ( ...others ) { - - const intersection = this._intersection( ...others ) ; - - this.clear( ).update( intersection ) ; + return this; + }; - return this ; + Set.prototype._intersection_update = function (...others) { + const intersection = this._intersection(...others); - } ; + this.clear().update(intersection); - Set.prototype.intersection_update = Set._operator( Set.prototype._intersection_update ) ; + return this; + }; - Set.prototype.difference_update = - Set.prototype._difference_update = function ( ...others ) { - - for ( let other of others ) { - - for ( let key of other ) this.discard( key ) ; - - } + Set.prototype.intersection_update = Set._operator( + Set.prototype._intersection_update, + ); - return this ; + // eslint-disable-next-line no-multi-assign + Set.prototype.difference_update = Set.prototype._difference_update = + function (...others) { + for (const other of others) { + for (const key of other) this.discard(key); + } - } ; + return this; + }; Set.prototype.symmetric_difference_update = - Set.prototype._symmetric_difference_update = function ( other ) { - - for ( let key of other ) { - - if ( this.has( key ) ) this.discard( key ) ; - else this.add( key ) ; - - } - - return this ; - - } ; - - Set.prototype.add = function ( key ) { - - this.container.add( key ) ; - - return this ; - - } ; - - Set.prototype.remove = function ( key ) { - - if ( !this.container.delete( key ) ) throw new KeyError( ) ; - - return this ; - - } ; - - Set.prototype.discard = function ( key ) { - - this.container.delete( key ) ; + // eslint-disable-next-line no-multi-assign + Set.prototype._symmetric_difference_update = function (other) { + for (const key of other) { + if (this.has(key)) this.discard(key); + else this.add(key); + } - return this ; + return this; + }; - } ; + Set.prototype.add = function (key) { + this.container.add(key); - Set.prototype.pop = function ( ) { + return this; + }; - if ( this.len( ) === 0 ) throw new KeyError( ) ; + Set.prototype.remove = function (key) { + if (!this.container.delete(key)) throw new KeyError(); - const key = this.keys( ).next( ).value ; + return this; + }; - this.discard( key ) ; + Set.prototype.discard = function (key) { + this.container.delete(key); - return key ; + return this; + }; - } ; + Set.prototype.pop = function () { + if (this.len() === 0) throw new KeyError(); - Set.prototype.clear = function ( ) { + const key = this.keys().next().value; - this.container.clear( ) ; + this.discard(key); - return this ; + return key; + }; - } ; + Set.prototype.clear = function () { + this.container.clear(); - return Set ; + return this; + }; + return Set; + /* eslint-enable no-use-extend-native/no-use-extend-native */ } diff --git a/src/_set.js b/src/_set.js index d7b5258..72152d0 100644 --- a/src/_set.js +++ b/src/_set.js @@ -1,14 +1,9 @@ +export default function _set(Set) { + const set = function (iterable = null) { + return new Set(iterable); + }; -export default function _set ( Set ) { - - const set = function ( iterable = null ) { - - return new Set( iterable ) ; - - } ; - - set.inclusion = Set.inclusion ; - - return set ; + set.inclusion = Set.inclusion; + return set; } diff --git a/src/index.js b/src/index.js index 2c0a88c..a03bb0f 100644 --- a/src/index.js +++ b/src/index.js @@ -1,16 +1,13 @@ -import _Set from './_Set.js' ; -import _set from './_set.js' ; -import NativeSet from './NativeSet.js' ; // Use native implementation of set +import _Set from './_Set.js'; +import _set from './_set.js'; +import NativeSet from './NativeSet.js'; // Use native implementation of set -const Set = _Set( NativeSet ) ; // overwrite native implementation +const Set = _Set(NativeSet); // Overwrite native implementation -const set = _set( Set ) ; +const set = _set(Set); -export default set ; +export default set; -export { - set , - Set , - _set , - _Set , -} ; +export {set, Set}; +export {default as _set} from './_set.js'; +export {default as _Set} from './_Set.js'; diff --git a/test/src/set.js b/test/src/set.js index 0cb14bf..91fdc6d 100644 --- a/test/src/set.js +++ b/test/src/set.js @@ -1,215 +1,278 @@ -import test from 'ava' ; +import test from 'ava'; -import { KeyError } from '@aureooms/js-error' ; +import {KeyError} from '@failure-abstraction/error'; -import set from '../../src/index.js' ; +import set from '../../src/index.js'; -test( set.name , t => { +test(set.name, (t) => { + t.is(set().len(), 0, 'len empty'); - t.is( set( ).len( ) , 0 , "len empty" ) ; + let s = set('abc'); + t.true(s.isequal('abc')); - var s = set( "abc" ) ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.len(), 3, 'len iterable'); + t.true(s.isequal('abc')); - t.is( s.len( ) , 3 , "len iterable" ) ; - t.true( s.isequal( "abc" ) ) ; + t.true(s.has('b'), 'has true'); + t.true(s.isequal('abc')); - t.true( s.has( "b" ) , "has true" ) ; - t.true( s.isequal( "abc" ) ) ; + t.false(s.has('x'), 'has false'); + t.true(s.isequal('abc')); - t.false( s.has( "x" ) , "has false" ) ; - t.true( s.isequal( "abc" ) ) ; + t.true(s.isdisjoint('xyz'), 'isdisjoint true'); + t.true(s.isequal('abc')); - t.true( s.isdisjoint( "xyz" ) , "isdisjoint true" ) ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.isdisjoint('xbz'), false, 'isdisjoint false'); + t.true(s.isequal('abc')); - t.is( s.isdisjoint( "xbz" ) , false , "isdisjoint false" ) ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.isequal('abc'), true, 'equal'); + t.true(s.isequal('abc')); - t.is( s.isequal( "abc" ) , true , "equal" ) ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.isequal('abcd'), false, 'not equal len'); + t.true(s.isequal('abc')); - t.is( s.isequal( "abcd" ) , false , "not equal len" ) ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.isequal('abd'), false, 'not equal key'); + t.true(s.isequal('abc')); - t.is( s.isequal( "abd" ) , false , "not equal key" ) ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.isequal('abd'), false, 'not equal key'); + t.true(s.isequal('abc')); - t.is( s.isequal( "abd" ) , false , "not equal key" ) ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.issubset('abcd'), true, 'subset abcd'); + t.true(s.isequal('abc')); - t.is( s.issubset( "abcd" ) , true , "subset abcd") ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.issubset('abc'), true, 'subset abc'); + t.true(s.isequal('abc')); - t.is( s.issubset( "abc" ) , true , "subset abc") ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.issubset('ab'), false, 'subset ab'); + t.true(s.isequal('abc')); - t.is( s.issubset( "ab" ) , false , "subset ab") ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.ispropersubset('abcd'), true, 'proper subset abcd'); + t.true(s.isequal('abc')); - t.is( s.ispropersubset( "abcd" ) , true , "proper subset abcd") ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.ispropersubset('abc'), false, 'proper subset abc'); + t.true(s.isequal('abc')); - t.is( s.ispropersubset( "abc" ) , false , "proper subset abc") ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.ispropersubset('ab'), false, 'proper subset ab'); + t.true(s.isequal('abc')); - t.is( s.ispropersubset( "ab" ) , false , "proper subset ab") ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.issuperset('abcd'), false, 'superset abcd'); + t.true(s.isequal('abc')); - t.is( s.issuperset( "abcd" ) , false , "superset abcd") ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.issuperset('abc'), true, 'superset abc'); + t.true(s.isequal('abc')); - t.is( s.issuperset( "abc" ) , true , "superset abc") ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.issuperset('ab'), true, 'superset ab'); + t.true(s.isequal('abc')); - t.is( s.issuperset( "ab" ) , true , "superset ab") ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.ispropersuperset('abcd'), false, 'proper superset abcd'); + t.true(s.isequal('abc')); - t.is( s.ispropersuperset( "abcd" ) , false , "proper superset abcd") ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.ispropersuperset('abc'), false, 'proper superset abc'); + t.true(s.isequal('abc')); - t.is( s.ispropersuperset( "abc" ) , false , "proper superset abc") ; - t.true( s.isequal( "abc" ) ) ; + t.is(s.ispropersuperset('ab'), true, 'proper superset ab'); + t.true(s.isequal('abc')); - t.is( s.ispropersuperset( "ab" ) , true , "proper superset ab") ; - t.true( s.isequal( "abc" ) ) ; + t.true(set.inclusion(s, 'abcd') < 0, 'set.inclusion abcd'); + t.true(s.isequal('abc')); - t.true( set.inclusion( s , "abcd" ) < 0 , "set.inclusion abcd" ) ; - t.true( s.isequal( "abc" ) ) ; + t.true(set.inclusion(s, 'abc') === 0, 'set.inclusion abc'); + t.true(s.isequal('abc')); - t.true( set.inclusion( s , "abc" ) === 0 , "set.inclusion abc" ) ; - t.true( s.isequal( "abc" ) ) ; + t.true(set.inclusion(s, 'ab') > 0, 'set.inclusion ab'); + t.true(s.isequal('abc')); - t.true( set.inclusion( s , "ab" ) > 0 , "set.inclusion ab" ) ; - t.true( s.isequal( "abc" ) ) ; + t.true(s.union('de').isequal('abcde'), 'union'); + t.true(s.isequal('abc')); - t.true( s.union( "de" ).isequal( "abcde" ) , "union" ) ; - t.true( s.isequal( "abc" ) ) ; + t.true(s.union('d', 'e').isequal('abcde'), 'union ...'); + t.true(s.isequal('abc')); - t.true( s.union( "d" , "e" ).isequal( "abcde" ) , "union ..." ) ; - t.true( s.isequal( "abc" ) ) ; + t.true(s.intersection('de').isequal(''), 'intersection empty'); + t.true(s.isequal('abc')); - t.true( s.intersection( "de" ).isequal( "" ) , "intersection empty" ) ; - t.true( s.isequal( "abc" ) ) ; + t.true(s.intersection('abc', 'de').isequal(''), 'intersection ... empty'); + t.true(s.isequal('abc')); - t.true( s.intersection( "abc" , "de" ).isequal( "" ) , "intersection ... empty" ) ; - t.true( s.isequal( "abc" ) ) ; + t.true(s.intersection('bcd').isequal('bc'), 'intersection bc'); + t.true(s.isequal('abc')); - t.true( s.intersection( "bcd" ).isequal( "bc" ) , "intersection bc" ) ; - t.true( s.isequal( "abc" ) ) ; + t.true(s.intersection('abcd', 'bcd').isequal('bc'), 'intersection ... bc'); + t.true(s.isequal('abc')); - t.true( s.intersection( "abcd" , "bcd" ).isequal( "bc" ) , "intersection ... bc" ) ; - t.true( s.isequal( "abc" ) ) ; + t.true(s.difference('de').isequal('abc'), 'difference abc'); + t.true(s.isequal('abc')); - t.true( s.difference( "de" ).isequal( "abc" ) , "difference abc" ) ; - t.true( s.isequal( "abc" ) ) ; - - t.true( s.difference( "d" , "e" ).isequal( "abc" ) , "difference ... abc" ) ; - t.true( s.isequal( "abc" ) ) ; - - t.true( s.difference( "bcd" ).isequal( "a" ) , "difference a" ) ; - t.true( s.isequal( "abc" ) ) ; - - t.true( s.difference( "bc" , "d" ).isequal( "a" ) , "difference ... a" ) ; - t.true( s.isequal( "abc" ) ) ; - - t.true( s.symmetric_difference( "de" ).isequal( "abcde" ) , "symmetric_difference abcde" ) ; - t.true( s.isequal( "abc" ) ) ; - - t.true( s.symmetric_difference( "bcd" ).isequal( "ad" ) , "symmetric_difference ad" ) ; - t.true( s.isequal( "abc" ) ) ; - - s = set( "abc" ) ; s.add( "x" ) ; - t.is( s.has( "x" ) , true , "has set" ) ; - t.true( s.isequal( "abcx" ) ) ; - - t.is( s.clear( ).update( "abc" ).add( "x" ).has( "x" ) , true , "chain has set" ) ; - t.true( s.isequal( "abcx" ) ) ; - - s = set( "abc" ) ; s.remove( "b" ) ; - t.is( s.has( "b" ) , false , "has remove" ) ; - t.true( s.isequal( "ac" ) ) ; - - t.is( s.clear( ).update( "abc" ).remove( "b" ).has( "b" ) , false , "chain has remove" ) ; - t.true( s.isequal( "ac" ) ) ; - - s = set( "abc" ) ; s.update( "de" ) ; - t.true( s.isequal( "abcde" ) , "update" ) ; - t.true( s.clear( ).update( "abc" ).update( "de" ).isequal( "abcde" ) , "chain update" ) ; - - s = set( "abc" ) ; s.update( "d" , "e" ) ; - t.true( s.isequal( "abcde" ) , "update ..." ) ; - t.true( s.clear( ).update( "abc" ).update( "d" , "e" ).isequal( "abcde" ) , "chain update ..." ) ; - - s = set( "abc" ) ; s.intersection_update( "de" ) ; - t.true( s.isequal( "" ) , "intersection update empty" ) ; - t.true( s.clear( ).update( "abc" ).intersection_update( "de" ).isequal( "" ) , "chain intersection update empty" ) ; - - s = set( "abc" ) ; s.intersection_update( "abc" , "de" ) ; - t.true( s.isequal( "" ) , "intersection update ... empty" ) ; - t.true( s.clear( ).intersection_update( "abc" , "de" ).isequal( "" ) , "chain intersection update ... empty" ) ; - - s = set( "abc" ) ; s.intersection_update( "bcd" ) ; - t.true( s.isequal( "bc" ) , "intersection update bc" ) ; - t.true( s.clear( ).update( "abc" ).intersection_update( "bcd" ).isequal( "bc" ) , "chain intersection update bc" ) ; - - s = set( "abc" ) ; s.intersection_update( "abcd" ,"bcd" ) ; - t.true( s.isequal( "bc" ) , "intersection update ... bc" ) ; - t.true( s.clear( ).update( "abc" ).intersection_update( "abcd" ,"bcd" ).isequal( "bc" ) , "chain intersection update ... bc" ) ; - s = set( "abc" ) ; s.difference_update( "de" ) ; - t.true( s.isequal( "abc" ) , "difference_update abc" ) ; - t.true( s.clear( ).update( "abc" ).difference_update( "de" ).isequal( "abc" ) , "chain difference_update abc" ) ; - - s = set( "abc" ) ; s.difference_update( "d" , "e" ) ; - t.true( s.isequal( "abc" ) , "difference_update ... abc" ) ; - t.true( s.clear( ).update( "abc" ).difference_update( "d" , "e" ).isequal( "abc" ) , "chain difference_update ... abc" ) ; - - s = set( "abc" ) ; s.difference_update( "bcd" ) ; - t.true( s.isequal( "a" ) , "difference_update a" ) ; - t.true( s.clear( ).update( "abc" ).difference_update( "bcd" ).isequal( "a" ) , "chain difference_update a" ) ; - - s = set( "abc" ) ; s.difference_update( "bc" , "d" ) ; - t.true( s.isequal( "a" ) , "difference_update ... a" ) ; - t.true( s.clear( ).update( "abc" ).difference_update( "bc" , "d" ).isequal( "a" ) , "chain difference_update ... a" ) ; - - s = set( "abc" ) ; s.symmetric_difference_update( "de" ) ; - t.true( s.isequal( "abcde" ) , "symmetric_difference_update abcde" ) ; - t.true( s.clear( ).update( "abc" ).symmetric_difference_update( "de" ).isequal( "abcde" ) , "chain symmetric_difference_update abcde" ) ; - - s = set( "abc" ) ; s.symmetric_difference_update( "bcd" ) ; - t.true( s.isequal( "ad" ) , "symmetric_difference_update ad" ) ; - t.true( s.clear( ).update( "abc" ).symmetric_difference_update( "bcd" ).isequal( "ad" ) , "chain symmetric_difference_update ad" ) ; - - t.is( set( "a" ).pop( ) , "a" , "pop" ) ; - t.is( set( "a" ).pop( ) , "a" , "pop" ) ; - - t.true( set( "abc" ).remove( "b" ).isequal( "ac" ) , "remove b" ) ; - t.true( set( "abc" ).remove( "b" ).isequal( "ac" ) , "remove b" ) ; - - t.true( set( "abc" ).discard( "b" ).isequal( "ac" ) , "discard b" ) ; - t.true( set( "abc" ).discard( "b" ).isequal( "ac" ) , "discard b" ) ; - - t.true( set( "abc" ).discard( "d" ).isequal( "abc" ) , "discard d" ) ; - t.true( set( "abc" ).discard( "d" ).isequal( "abc" ) , "discard d" ) ; - - s = set( "abcd" ) ; - - s.clear( ) ; - t.true( s.isequal( "" ) , "clear" ) ; - - t.throws( s.clear( ).pop.bind( s ) , { instanceOf: KeyError } , "pop raises" ) ; - t.throws( s.clear( ).pop.bind( s ) , { instanceOf: KeyError } , "pop raises" ) ; - - t.throws( s.clear( ).add( "x" ).remove.bind( s , "y" ) , { instanceOf: KeyError } , "remove raises" ) ; - t.throws( s.clear( ).add( "x" ).remove.bind( s , "y" ) , { instanceOf: KeyError } , "remove raises" ) ; - - t.deepEqual( s.clear( ) , s , "ref clear" ) ; - t.deepEqual( s.add( "x" ) , s , "ref add" ) ; - t.deepEqual( s.remove( "x" ) , s , "ref remove" ) ; - t.deepEqual( s.discard( "x" ) , s , "ref discard" ) ; - t.deepEqual( s.update( ) , s , "ref update" ) ; - t.deepEqual( s.intersection_update( ) , s , "ref intersection_update" ) ; - t.deepEqual( s.difference_update( ) , s , "ref difference_update" ) ; - t.deepEqual( s.symmetric_difference_update( "x" ) , s , "ref symmetric_difference_update" ) ; - -} ) ; + t.true(s.difference('d', 'e').isequal('abc'), 'difference ... abc'); + t.true(s.isequal('abc')); + + t.true(s.difference('bcd').isequal('a'), 'difference a'); + t.true(s.isequal('abc')); + + t.true(s.difference('bc', 'd').isequal('a'), 'difference ... a'); + t.true(s.isequal('abc')); + + t.true( + s.symmetric_difference('de').isequal('abcde'), + 'symmetric_difference abcde', + ); + t.true(s.isequal('abc')); + + t.true( + s.symmetric_difference('bcd').isequal('ad'), + 'symmetric_difference ad', + ); + t.true(s.isequal('abc')); + + s = set('abc'); + s.add('x'); + t.is(s.has('x'), true, 'has set'); + t.true(s.isequal('abcx')); + + t.is(s.clear().update('abc').add('x').has('x'), true, 'chain has set'); + t.true(s.isequal('abcx')); + + s = set('abc'); + s.remove('b'); + t.is(s.has('b'), false, 'has remove'); + t.true(s.isequal('ac')); + + t.is(s.clear().update('abc').remove('b').has('b'), false, 'chain has remove'); + t.true(s.isequal('ac')); + + s = set('abc'); + s.update('de'); + t.true(s.isequal('abcde'), 'update'); + t.true(s.clear().update('abc').update('de').isequal('abcde'), 'chain update'); + + s = set('abc'); + s.update('d', 'e'); + t.true(s.isequal('abcde'), 'update ...'); + t.true( + s.clear().update('abc').update('d', 'e').isequal('abcde'), + 'chain update ...', + ); + + s = set('abc'); + s.intersection_update('de'); + t.true(s.isequal(''), 'intersection update empty'); + t.true( + s.clear().update('abc').intersection_update('de').isequal(''), + 'chain intersection update empty', + ); + + s = set('abc'); + s.intersection_update('abc', 'de'); + t.true(s.isequal(''), 'intersection update ... empty'); + t.true( + s.clear().intersection_update('abc', 'de').isequal(''), + 'chain intersection update ... empty', + ); + + s = set('abc'); + s.intersection_update('bcd'); + t.true(s.isequal('bc'), 'intersection update bc'); + t.true( + s.clear().update('abc').intersection_update('bcd').isequal('bc'), + 'chain intersection update bc', + ); + + s = set('abc'); + s.intersection_update('abcd', 'bcd'); + t.true(s.isequal('bc'), 'intersection update ... bc'); + t.true( + s.clear().update('abc').intersection_update('abcd', 'bcd').isequal('bc'), + 'chain intersection update ... bc', + ); + s = set('abc'); + s.difference_update('de'); + t.true(s.isequal('abc'), 'difference_update abc'); + t.true( + s.clear().update('abc').difference_update('de').isequal('abc'), + 'chain difference_update abc', + ); + + s = set('abc'); + s.difference_update('d', 'e'); + t.true(s.isequal('abc'), 'difference_update ... abc'); + t.true( + s.clear().update('abc').difference_update('d', 'e').isequal('abc'), + 'chain difference_update ... abc', + ); + + s = set('abc'); + s.difference_update('bcd'); + t.true(s.isequal('a'), 'difference_update a'); + t.true( + s.clear().update('abc').difference_update('bcd').isequal('a'), + 'chain difference_update a', + ); + + s = set('abc'); + s.difference_update('bc', 'd'); + t.true(s.isequal('a'), 'difference_update ... a'); + t.true( + s.clear().update('abc').difference_update('bc', 'd').isequal('a'), + 'chain difference_update ... a', + ); + + s = set('abc'); + s.symmetric_difference_update('de'); + t.true(s.isequal('abcde'), 'symmetric_difference_update abcde'); + t.true( + s.clear().update('abc').symmetric_difference_update('de').isequal('abcde'), + 'chain symmetric_difference_update abcde', + ); + + s = set('abc'); + s.symmetric_difference_update('bcd'); + t.true(s.isequal('ad'), 'symmetric_difference_update ad'); + t.true( + s.clear().update('abc').symmetric_difference_update('bcd').isequal('ad'), + 'chain symmetric_difference_update ad', + ); + + t.is(set('a').pop(), 'a', 'pop'); + t.is(set('a').pop(), 'a', 'pop'); + + t.true(set('abc').remove('b').isequal('ac'), 'remove b'); + t.true(set('abc').remove('b').isequal('ac'), 'remove b'); + + t.true(set('abc').discard('b').isequal('ac'), 'discard b'); + t.true(set('abc').discard('b').isequal('ac'), 'discard b'); + + t.true(set('abc').discard('d').isequal('abc'), 'discard d'); + t.true(set('abc').discard('d').isequal('abc'), 'discard d'); + + s = set('abcd'); + + s.clear(); + t.true(s.isequal(''), 'clear'); + + t.throws(s.clear().pop.bind(s), {instanceOf: KeyError}, 'pop raises'); + t.throws(s.clear().pop.bind(s), {instanceOf: KeyError}, 'pop raises'); + + t.throws( + s.clear().add('x').remove.bind(s, 'y'), + {instanceOf: KeyError}, + 'remove raises', + ); + t.throws( + s.clear().add('x').remove.bind(s, 'y'), + {instanceOf: KeyError}, + 'remove raises', + ); + + t.deepEqual(s.clear(), s, 'ref clear'); + t.deepEqual(s.add('x'), s, 'ref add'); + t.deepEqual(s.remove('x'), s, 'ref remove'); + t.deepEqual(s.discard('x'), s, 'ref discard'); + t.deepEqual(s.update(), s, 'ref update'); + t.deepEqual(s.intersection_update(), s, 'ref intersection_update'); + t.deepEqual(s.difference_update(), s, 'ref difference_update'); + t.deepEqual( + s.symmetric_difference_update('x'), + s, + 'ref symmetric_difference_update', + ); +}); diff --git a/yarn.lock b/yarn.lock index 4fef8f8..cadc37d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10,11 +10,6 @@ "@jridgewell/gen-mapping" "^0.1.0" "@jridgewell/trace-mapping" "^0.3.9" -"@aureooms/js-error@^5.0.0": - version "5.0.1" - resolved "https://registry.yarnpkg.com/@aureooms/js-error/-/js-error-5.0.1.tgz#474e2f1dd7189f97df770b5cc6f1bda536de262d" - integrity sha512-BbbpKpp4W8L2x9vL4bas+JtuAe4PMojzTpf21puHPw5p3S+lgKd8SfS9y40pVHi/b3SrQrdpmsaEKjL4xviilQ== - "@babel/code-frame@^7.0.0": version "7.12.11" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.12.11.tgz#f4ad435aa263db935b8f10f2c552d23fb716a63f" @@ -2092,6 +2087,11 @@ minimatch "^3.1.2" strip-json-comments "^3.1.1" +"@failure-abstraction/error@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/@failure-abstraction/error/-/error-6.0.1.tgz#ab6929395c7ed3ec74d86db2976e74e31f9569e2" + integrity sha512-KvIHhvwfrgbUduQbk55WRDGL2XcXjDLwleId+pSnK7mUUIY7zMGMy3N+ouDcOFymme48tKDlarKsYj5mEEd3fg== + "@humanwhocodes/config-array@^0.10.4": version "0.10.4" resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.10.4.tgz#01e7366e57d2ad104feea63e72248f22015c520c"