Skip to content

Commit

Permalink
Create a 0.29 release that works with Dart 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo committed Jul 19, 2018
1 parent db16a2c commit 8084f10
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 40 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
#### 0.29.0+1 - 2018-07-19

* Updated usage of Dart SDK constants for Dart v2.
Allows users of `pkg:quiver` to support Dart 2 gold without addressing
all of the breaking changes in `pkg:quiver` v2.

#### 0.29.0 - 2018-03-28

* BREAKING CHANGE: Deleted `createTimer` and `createTimerPeriodic`, which
Expand Down
7 changes: 5 additions & 2 deletions lib/io.dart
Expand Up @@ -18,9 +18,12 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:dart2_constant/convert.dart' as convert;
import 'package:dart2_constant/io.dart' as io;

/// Converts a [Stream] of byte lists to a [String].
Future<String> byteStreamToString(Stream<List<int>> stream,
{Encoding encoding: UTF8}) {
{Encoding encoding: convert.utf8}) {
return stream.transform(encoding.decoder).join();
}

Expand All @@ -47,7 +50,7 @@ Future visitDirectory(Directory dir, Future<bool> visit(FileSystemEntity f)) {
if (entity is! File && recurse == true) {
if (entity is Link) {
if (FileSystemEntity.typeSync(entity.path, followLinks: true) ==
FileSystemEntityType.DIRECTORY) {
io.FileSystemEntityType.directory) {
var fullPath = getFullPath(entity.path).toString();
var dirFullPath = getFullPath(dir.path).toString();
if (!dirFullPath.startsWith(fullPath)) {
Expand Down
4 changes: 3 additions & 1 deletion lib/src/time/util.dart
Expand Up @@ -23,7 +23,9 @@ const _daysInMonth = const [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
/// This function assumes the use of the Gregorian calendar or the proleptic
/// Gregorian calendar.
int daysInMonth(int year, int month) =>
(month == DateTime.FEBRUARY && isLeapYear(year)) ? 29 : _daysInMonth[month];
(month == core.DateTime.february && isLeapYear(year))
? 29
: _daysInMonth[month];

/// Returns true if [year] is a leap year.
///
Expand Down
1 change: 1 addition & 0 deletions lib/testing/async.dart
Expand Up @@ -18,6 +18,7 @@ library quiver.testing.async;
import 'dart:async';
import 'dart:collection';

import 'package:dart2_constant/core.dart' as core;
import 'package:quiver/time.dart';

part 'src/async/fake_async.dart';
4 changes: 2 additions & 2 deletions lib/testing/src/async/fake_async.dart
Expand Up @@ -118,7 +118,7 @@ abstract class FakeAsync {
}

class _FakeAsync implements FakeAsync {
Duration _elapsed = Duration.ZERO;
Duration _elapsed = core.Duration.zero;
Duration _elapsingTo;
Queue<Function> _microtasks = new Queue();
Set<_FakeTimer> _timers = new Set<_FakeTimer>();
Expand Down Expand Up @@ -275,7 +275,7 @@ class _FakeTimer implements Timer {
// http://www.w3.org/TR/html5/webappapis.html#timer-nesting-level
// Without some sort of delay this can lead to infinitely looping timers.
// What do the dart VM and dart2js timers do here?
static const _minDuration = Duration.ZERO;
static const _minDuration = core.Duration.zero;

_FakeTimer._(Duration duration, this._callback, this._isPeriodic, this._time)
: _duration = duration < _minDuration ? _minDuration : duration {
Expand Down
1 change: 1 addition & 0 deletions lib/time.dart
Expand Up @@ -14,6 +14,7 @@

library quiver.time;

import 'package:dart2_constant/core.dart' as core;
import 'package:meta/meta.dart';

part 'src/time/clock.dart';
Expand Down
5 changes: 3 additions & 2 deletions pubspec.yaml
Expand Up @@ -17,10 +17,11 @@ authors:
description: A set of utility libraries for Dart
homepage: https://github.com/google/quiver-dart
environment:
sdk: '>=1.21.0 <2.0.0'
sdk: '>=1.21.0 <3.0.0'
dependencies:
dart2_constant: ^1.0.0
matcher: '>=0.10.0 <0.13.0'
meta: '>=1.0.0 <2.0.0'
dev_dependencies:
path: '>=1.0.0 <2.0.0'
test: '>=0.12.20 <=0.13.0'
test: '>=0.12.20 <=2.0.0'
6 changes: 3 additions & 3 deletions test/async/collect_test.dart
Expand Up @@ -26,10 +26,10 @@ main() {
() => collect([]).toList().then((events) => expect(events, isEmpty)));

test('should produce events for future completions in input order', () {
var futures = new Iterable<Future>.generate(
var futures = new Iterable.generate(
5, (int i) => i.isEven ? new Future.value(i) : new Future.error(i));
var events = [];
var done = new Completer();
var done = new Completer<List>();

collect(futures).listen(events.add, onError: (i) {
events.add('e$i');
Expand All @@ -45,7 +45,7 @@ main() {
var eventCount = 0;
var maxParallel = 0;
var currentParallel = 0;
var done = new Completer();
var done = new Completer<List<dynamic>>();
var futures = new Iterable.generate(3, (_) {
maxParallel = max(++currentParallel, maxParallel);
return new Future.value();
Expand Down
4 changes: 2 additions & 2 deletions test/async/concat_test.dart
Expand Up @@ -50,8 +50,8 @@ main() {
});
['a', 'b', 'c'].forEach(controller1.add);
['d', 'e', 'f'].forEach(controller2.add);
return Future
.wait([controller1.close(), controller2.close(), expectation]);
return Future.wait(
[controller1.close(), controller2.close(), expectation]);
});

test('should concatenate stream error events', () {
Expand Down
3 changes: 2 additions & 1 deletion test/async/iteration_test.dart
Expand Up @@ -85,7 +85,8 @@ main() {
return new Future(() {
pending--;
});
}, maxTasks: 3).then((_) {
}, maxTasks: 3)
.then((_) {
expect(results, [1, 2, 3, 4]);
expect(maxPending, 3);
});
Expand Down
15 changes: 10 additions & 5 deletions test/async/metronome_test.dart
Expand Up @@ -97,7 +97,8 @@ main() {
DateTime start = DateTime.parse("2014-05-05 20:06:00");
Clock clock = async.getClock(start);
new Metronome.periodic(aMinute * 10,
clock: clock, anchor: clock.minutesAgo(59)).listen((d) {
clock: clock, anchor: clock.minutesAgo(59))
.listen((d) {
times.add(d);
});
async.elapse(anHour);
Expand All @@ -118,7 +119,8 @@ main() {
DateTime start = DateTime.parse("2014-05-05 20:06:00");
Clock clock = async.getClock(start);
new Metronome.periodic(aMinute * 10,
clock: clock, anchor: clock.minutesFromNow(61)).listen((d) {
clock: clock, anchor: clock.minutesFromNow(61))
.listen((d) {
times.add(d);
});
async.elapse(anHour);
Expand All @@ -138,7 +140,8 @@ main() {
List<DateTime> times = [];
DateTime start = DateTime.parse("2014-05-05 20:06:00.004");
new Metronome.periodic(aMillisecond * 100,
clock: async.getClock(start), anchor: start).listen((d) {
clock: async.getClock(start), anchor: start)
.listen((d) {
times.add(d);
});
async.elapse(aMillisecond * 304);
Expand All @@ -155,7 +158,8 @@ main() {
List<DateTime> times = [];
DateTime start = DateTime.parse("2014-05-05 20:06:00.004");
new Metronome.periodic(aMillisecond * 100,
clock: async.getClock(start), anchor: start).listen((d) {
clock: async.getClock(start), anchor: start)
.listen((d) {
times.add(d);
async.elapseBlocking(const Duration(milliseconds: 80));
});
Expand All @@ -173,7 +177,8 @@ main() {
List<DateTime> times = [];
DateTime start = DateTime.parse("2014-05-05 20:06:00.004");
new Metronome.periodic(aMillisecond * 100,
clock: async.getClock(start), anchor: start).listen((d) {
clock: async.getClock(start), anchor: start)
.listen((d) {
times.add(d);
async.elapseBlocking(const Duration(milliseconds: 105));
});
Expand Down
8 changes: 4 additions & 4 deletions test/async/stream_buffer_test.dart
Expand Up @@ -21,8 +21,8 @@ import 'package:quiver/async.dart';
void main() {
group("StreamBuffer", () {
test("returns orderly overlaps", () {
StreamBuffer<List<int>> buf = new StreamBuffer();
new Stream.fromIterable([
var buf = new StreamBuffer();
new Stream<Object>.fromIterable([
[1],
[2, 3, 4],
[5, 6, 7, 8]
Expand All @@ -37,8 +37,8 @@ void main() {
});

test("respects pausing of stream", () {
StreamBuffer<List<int>> buf = new StreamBuffer()..limit = 2;
new Stream.fromIterable([
var buf = new StreamBuffer()..limit = 2;
new Stream<Object>.fromIterable([
[1],
[2],
[3],
Expand Down
22 changes: 11 additions & 11 deletions test/collection/multimap_test.dart
Expand Up @@ -66,7 +66,7 @@ void main() {

group('Multimap asMap() view', () {
Multimap<String, String> mmap;
Map<String, Iterable<String>> map;
Map<String, List<String>> map;
setUp(() {
mmap = new Multimap()..add('k1', 'v1')..add('k1', 'v2')..add('k2', 'v3');
map = mmap.asMap();
Expand Down Expand Up @@ -191,8 +191,8 @@ void main() {

test('should return unmapped iterables that stay in sync on addAll', () {
var map = new ListMultimap<String, String>();
List values1 = map['k1'];
List values2 = map['k1'];
var values1 = map['k1'];
var values2 = map['k1'];
values1.addAll(['v1', 'v2']);
expect(map['k1'], ['v1', 'v2']);
expect(values2, ['v1', 'v2']);
Expand Down Expand Up @@ -555,10 +555,10 @@ void main() {
'should support operations on empty map views without breaking delegate synchronization',
() {
var mmap = new ListMultimap<String, String>();
List x = mmap['k1'];
List y = mmap['k1'];
List z = mmap['k1'];
List w = mmap['k1'];
var x = mmap['k1'];
var y = mmap['k1'];
var z = mmap['k1'];
var w = mmap['k1'];
mmap['k1'].add('v1');
expect(mmap['k1'], ['v1']);
x.add('v2');
Expand Down Expand Up @@ -618,8 +618,8 @@ void main() {

test('should return unmapped iterables that stay in sync on addAll', () {
var map = new SetMultimap<String, String>();
Set values1 = map['k1'];
Set values2 = map['k1'];
var values1 = map['k1'];
var values2 = map['k1'];
values1.addAll(['v1', 'v2']);
expect(map['k1'], unorderedEquals(['v1', 'v2']));
expect(values2, unorderedEquals(['v1', 'v2']));
Expand Down Expand Up @@ -970,8 +970,8 @@ void main() {
'should support operations on empty map views without breaking '
'delegate synchronization', () {
var mmap = new SetMultimap<String, String>();
Set x = mmap['k1'];
Set y = mmap['k1'];
var x = mmap['k1'];
var y = mmap['k1'];
mmap['k1'].add('v0');
x.add('v1');
y.addAll(['v2', 'v3']);
Expand Down
8 changes: 4 additions & 4 deletions test/io_test.dart
Expand Up @@ -15,9 +15,9 @@
library quiver.io_test;

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:dart2_constant/convert.dart' as convert;
import 'package:path/path.dart' as path;
import 'package:quiver/io.dart';
import 'package:test/test.dart';
Expand All @@ -26,7 +26,7 @@ main() {
group('byteStreamToString', () {
test('should decode UTF8 text by default', () {
var string = '箙、靫';
var encoded = UTF8.encoder.convert(string);
var encoded = convert.utf8.encoder.convert(string);
var data = [encoded.sublist(0, 3), encoded.sublist(3)];
var stream = new Stream<List<int>>.fromIterable(data);
byteStreamToString(stream).then((decoded) {
Expand All @@ -36,10 +36,10 @@ main() {

test('should decode text with the specified encoding', () {
var string = 'blåbærgrød';
var encoded = LATIN1.encoder.convert(string);
var encoded = convert.latin1.encoder.convert(string);
var data = [encoded.sublist(0, 4), encoded.sublist(4)];
var stream = new Stream<List<int>>.fromIterable(data);
byteStreamToString(stream, encoding: LATIN1).then((decoded) {
byteStreamToString(stream, encoding: convert.latin1).then((decoded) {
expect(decoded, string);
});
});
Expand Down
6 changes: 4 additions & 2 deletions test/testing/async/fake_async_test.dart
Expand Up @@ -16,6 +16,7 @@ library quiver.testing.async.fake_async_test;

import 'dart:async';

import 'package:dart2_constant/core.dart' as core;
import 'package:quiver/testing/async.dart';
import 'package:test/test.dart';

Expand Down Expand Up @@ -273,7 +274,8 @@ main() {

test('should not be additive with elapseBlocking', () {
new FakeAsync().run((async) {
new Timer(Duration.ZERO, () => async.elapseBlocking(elapseBy * 5));
new Timer(
core.Duration.zero, () => async.elapseBlocking(elapseBy * 5));
async.elapse(elapseBy);
expect(async.getClock(initialTime).now(),
initialTime.add(elapseBy * 5));
Expand Down Expand Up @@ -310,7 +312,7 @@ main() {
new FakeAsync().run((async) {
var callCount = 0;
new Future(() => callCount++);
async.elapse(Duration.ZERO);
async.elapse(core.Duration.zero);
expect(callCount, 1);
});
});
Expand Down
2 changes: 1 addition & 1 deletion tool/travis.sh
Expand Up @@ -18,7 +18,7 @@ testing_libs=$(find lib/testing -maxdepth 1 -type f -name '*.dart')
dartanalyzer $DARTANALYZER_FLAGS $libs $testing_libs test/all_tests.dart

# Verify that dartfmt has been run.
if [[ "$TRAVIS_DART_VERSION" == "stable" ]]; then
if [[ "$TRAVIS_DART_VERSION" == "dev" ]]; then
# Only test on stable to avoid CI failure due to diffs between stable and dev.
echo "Checking dartfmt..."
if [[ $(dartfmt -n --set-exit-if-changed lib/ test/) ]]; then
Expand Down

0 comments on commit 8084f10

Please sign in to comment.