mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Test print.dart (#7406)
This commit is contained in:
parent
fb8179bfed
commit
cd34593ca8
@ -51,9 +51,9 @@ void debugPrintThrottled(String message, { int wrapWidth }) {
|
||||
}
|
||||
int _debugPrintedCharacters = 0;
|
||||
const int _kDebugPrintCapacity = 16 * 1024;
|
||||
Duration _kDebugPrintPauseTime = const Duration(seconds: 1);
|
||||
Queue<String> _debugPrintBuffer = new Queue<String>();
|
||||
Stopwatch _debugPrintStopwatch = new Stopwatch();
|
||||
const Duration _kDebugPrintPauseTime = const Duration(seconds: 1);
|
||||
final Queue<String> _debugPrintBuffer = new Queue<String>();
|
||||
final Stopwatch _debugPrintStopwatch = new Stopwatch();
|
||||
bool _debugPrintScheduled = false;
|
||||
void _debugPrintTask() {
|
||||
_debugPrintScheduled = false;
|
||||
|
||||
75
packages/flutter/test/foundation/print_test.dart
Normal file
75
packages/flutter/test/foundation/print_test.dart
Normal file
@ -0,0 +1,75 @@
|
||||
// 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);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user