Commit cd34593c authored by Adam Barth's avatar Adam Barth Committed by GitHub

Test print.dart (#7406)

parent fb8179bf
...@@ -51,9 +51,9 @@ void debugPrintThrottled(String message, { int wrapWidth }) { ...@@ -51,9 +51,9 @@ void debugPrintThrottled(String message, { int wrapWidth }) {
} }
int _debugPrintedCharacters = 0; int _debugPrintedCharacters = 0;
const int _kDebugPrintCapacity = 16 * 1024; const int _kDebugPrintCapacity = 16 * 1024;
Duration _kDebugPrintPauseTime = const Duration(seconds: 1); const Duration _kDebugPrintPauseTime = const Duration(seconds: 1);
Queue<String> _debugPrintBuffer = new Queue<String>(); final Queue<String> _debugPrintBuffer = new Queue<String>();
Stopwatch _debugPrintStopwatch = new Stopwatch(); final Stopwatch _debugPrintStopwatch = new Stopwatch();
bool _debugPrintScheduled = false; bool _debugPrintScheduled = false;
void _debugPrintTask() { void _debugPrintTask() {
_debugPrintScheduled = false; _debugPrintScheduled = false;
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:quiver/testing/async.dart';
import 'package:test/test.dart';
List<String> captureOutput(VoidCallback fn) {
List<String> log = <String>[];
runZoned(fn, zoneSpecification: new ZoneSpecification(
print: (Zone self,
ZoneDelegate parent,
Zone zone,
String line) {
log.add(line);
},
));
return log;
}
void main() {
test('debugPrint', () {
expect(
captureOutput(() { debugPrintSynchronously('Hello, world'); }),
equals(<String>['Hello, world'])
);
expect(
captureOutput(() { debugPrintSynchronously('Hello, world', wrapWidth: 10); }),
equals(<String>['Hello,\nworld'])
);
for (int i = 0; i < 14; ++i) {
expect(
captureOutput(() { debugPrintSynchronously('Hello, world', wrapWidth: i); }),
equals(<String>['Hello,\nworld'])
);
}
expect(
captureOutput(() { debugPrintThrottled('Hello, world'); }),
equals(<String>['Hello, world'])
);
expect(
captureOutput(() { debugPrintThrottled('Hello, world', wrapWidth: 10); }),
equals(<String>['Hello,', 'world'])
);
});
test('debugPrint throttling', () {
new FakeAsync().run((FakeAsync async) {
List<String> log = captureOutput(() {
debugPrintThrottled('A' * (22 * 1024) + '\nB');
});
expect(log.length, 1);
async.elapse(const Duration(seconds: 2));
expect(log.length, 2);
log = captureOutput(() {
debugPrintThrottled('C' * (22 * 1024));
debugPrintThrottled('D');
});
expect(log.length, 1);
async.elapse(const Duration(seconds: 2));
expect(log.length, 2);
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment