-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
189 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
import 'package:disposal/disposal.dart'; | ||
|
||
abstract class DisposableSink { | ||
|
||
void addDisposable(Disposable disposable); | ||
void addDisposables(List<Disposable> disposables); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import 'package:test/test.dart'; | ||
import 'package:scopes/scopes.dart'; | ||
|
||
import '../../toolbox/mock_configurable.dart'; | ||
|
||
void main() { | ||
|
||
test('`scope.addDisposables` before dispose', () async { | ||
|
||
final List<String> invokes = []; | ||
|
||
final configurable = MockConfigurable((scope) { | ||
|
||
final disposable1 = Disposable(() { | ||
invokes.add('dispose1'); | ||
}); | ||
final disposable2 = Disposable(() { | ||
invokes.add('dispose2'); | ||
}); | ||
|
||
scope.addDisposables([ | ||
disposable1, | ||
disposable2, | ||
]); | ||
|
||
}); | ||
|
||
final scope = await Scope.root([ | ||
configurable, | ||
]); | ||
|
||
expect(invokes, []); | ||
scope.dispose(); | ||
expect(invokes, [ | ||
'dispose2', | ||
'dispose1', | ||
]); | ||
|
||
}); | ||
|
||
test('`scope.addDisposable` before dispose', () async { | ||
|
||
int invokes = 0; | ||
|
||
final configurable = MockConfigurable((scope) { | ||
|
||
final disposable = Disposable(() { | ||
invokes += 1; | ||
}); | ||
|
||
scope.addDisposable(disposable); | ||
|
||
}); | ||
|
||
final scope = await Scope.root([ | ||
configurable, | ||
]); | ||
|
||
expect(invokes, 0); | ||
scope.dispose(); | ||
expect(invokes, 1); | ||
|
||
}); | ||
|
||
test('`scope.addDisposables` after dispose', () async { | ||
|
||
final List<String> invokes = []; | ||
|
||
final configurable = MockConfigurable((scope) { | ||
|
||
final disposable1 = Disposable(() { | ||
invokes.add('dispose1'); | ||
}); | ||
final disposable2 = Disposable(() { | ||
invokes.add('dispose2'); | ||
}); | ||
|
||
Future(() { | ||
expect(invokes, []); | ||
scope.addDisposables([ | ||
disposable1, | ||
disposable2, | ||
]); | ||
expect(invokes, [ | ||
'dispose2', | ||
'dispose1', | ||
]); | ||
}); | ||
}); | ||
|
||
final scope = await Scope.root([ | ||
configurable, | ||
]); | ||
|
||
scope.dispose(); | ||
|
||
await Future(() {}); | ||
|
||
}); | ||
|
||
test('`scope.addDisposable` after dispose', () async { | ||
|
||
int invokes = 0; | ||
|
||
final configurable = MockConfigurable((scope) { | ||
|
||
final disposable = Disposable(() { | ||
invokes += 1; | ||
}); | ||
|
||
Future(() { | ||
expect(invokes, 0); | ||
scope.addDisposable(disposable); | ||
expect(invokes, 1); | ||
}); | ||
|
||
}); | ||
|
||
final scope = await Scope.root([ | ||
configurable, | ||
]); | ||
|
||
scope.dispose(); | ||
|
||
await Future(() {}); | ||
|
||
}); | ||
|
||
test('`scope.dispose` multiple times', () async { | ||
|
||
int invokes = 0; | ||
|
||
final configurable = MockConfigurable((scope) { | ||
|
||
final disposable = Disposable(() { | ||
invokes += 1; | ||
}); | ||
|
||
scope.addDisposable(disposable); | ||
|
||
}); | ||
|
||
final scope = await Scope.root([ | ||
configurable, | ||
]); | ||
|
||
expect(invokes, 0); | ||
scope.dispose(); | ||
expect(invokes, 1); | ||
scope.dispose(); | ||
expect(invokes, 1); | ||
|
||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
|
||
import 'scope_methods/disposable_test.dart' as disposable_test; | ||
import 'scope_methods/scope_push_test.dart' as scope_push_test; | ||
import 'scopes/scope_test.dart' as scope_test; | ||
|
||
void main() { | ||
disposable_test.main(); | ||
scope_push_test.main(); | ||
scope_test.main(); | ||
} |