OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:async'; |
| 6 |
| 7 import 'package:test/src/backend/state.dart'; |
| 8 import 'package:test/test.dart'; |
| 9 |
| 10 void main() { |
| 11 group("Timeout.parse", () { |
| 12 group('for "none"', () { |
| 13 test("successfully parses", () { |
| 14 expect(new Timeout.parse("none"), equals(Timeout.none)); |
| 15 }); |
| 16 |
| 17 test("rejects invalid input", () { |
| 18 expect(() => new Timeout.parse(" none"), throwsFormatException); |
| 19 expect(() => new Timeout.parse("none "), throwsFormatException); |
| 20 expect(() => new Timeout.parse("xnone"), throwsFormatException); |
| 21 expect(() => new Timeout.parse("nonex"), throwsFormatException); |
| 22 expect(() => new Timeout.parse("noxe"), throwsFormatException); |
| 23 }); |
| 24 }); |
| 25 |
| 26 group("for a relative timeout", () { |
| 27 test("successfully parses", () { |
| 28 expect(new Timeout.parse("1x"), equals(new Timeout.factor(1))); |
| 29 expect(new Timeout.parse("2.5x"), equals(new Timeout.factor(2.5))); |
| 30 expect(new Timeout.parse("1.2e3x"), equals(new Timeout.factor(1.2e3))); |
| 31 }); |
| 32 |
| 33 test("rejects invalid input", () { |
| 34 expect(() => new Timeout.parse(".x"), throwsFormatException); |
| 35 expect(() => new Timeout.parse("x"), throwsFormatException); |
| 36 expect(() => new Timeout.parse("ax"), throwsFormatException); |
| 37 expect(() => new Timeout.parse("1x "), throwsFormatException); |
| 38 expect(() => new Timeout.parse("1x5m"), throwsFormatException); |
| 39 }); |
| 40 }); |
| 41 |
| 42 group("for an absolute timeout", () { |
| 43 test("successfully parses all supported units", () { |
| 44 expect(new Timeout.parse("2d"), |
| 45 equals(new Timeout(new Duration(days: 2)))); |
| 46 expect(new Timeout.parse("2h"), |
| 47 equals(new Timeout(new Duration(hours: 2)))); |
| 48 expect(new Timeout.parse("2m"), |
| 49 equals(new Timeout(new Duration(minutes: 2)))); |
| 50 expect(new Timeout.parse("2s"), |
| 51 equals(new Timeout(new Duration(seconds: 2)))); |
| 52 expect(new Timeout.parse("2ms"), |
| 53 equals(new Timeout(new Duration(milliseconds: 2)))); |
| 54 expect(new Timeout.parse("2us"), |
| 55 equals(new Timeout(new Duration(microseconds: 2)))); |
| 56 }); |
| 57 |
| 58 test("supports non-integer units", () { |
| 59 expect(new Timeout.parse("2.73d"), |
| 60 equals(new Timeout(new Duration(days: 1) * 2.73))); |
| 61 }); |
| 62 |
| 63 test("supports multiple units", () { |
| 64 expect(new Timeout.parse("1d 2h3m 4s5ms\t6us"), |
| 65 equals(new Timeout(new Duration( |
| 66 days: 1, |
| 67 hours: 2, |
| 68 minutes: 3, |
| 69 seconds: 4, |
| 70 milliseconds: 5, |
| 71 microseconds: 6)))); |
| 72 }); |
| 73 |
| 74 test("rejects invalid input", () { |
| 75 expect(() => new Timeout.parse(".d"), throwsFormatException); |
| 76 expect(() => new Timeout.parse("d"), throwsFormatException); |
| 77 expect(() => new Timeout.parse("ad"), throwsFormatException); |
| 78 expect(() => new Timeout.parse("1z"), throwsFormatException); |
| 79 expect(() => new Timeout.parse("1u"), throwsFormatException); |
| 80 expect(() => new Timeout.parse("1d5x"), throwsFormatException); |
| 81 expect(() => new Timeout.parse("1d*5m"), throwsFormatException); |
| 82 }); |
| 83 }); |
| 84 }); |
| 85 } |
OLD | NEW |