<commit_before>// Copyright 2014 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

library quiver.testing.async.fake_time_test;

import 'dart:async';

import 'package:quiver/testing/async.dart';
import 'package:unittest/unittest.dart';

main() {
  group('FakeTime', () {

    FakeTime unit;
    DateTime initialTime;
    Duration elapseBy;

    setUp(() {
      initialTime = new DateTime(2000);
      unit = new FakeTime(initialTime: initialTime);
      elapseBy = const Duration(days: 1);
    });

    test('should set initial time', () {
      expect(unit.clock.now(), initialTime);
    });

    test('should default initial time to system time', () {
      expect(
          new FakeTime().clock.now().millisecondsSinceEpoch,
          closeTo(new DateTime.now().millisecondsSinceEpoch, 500));
    });

    group('elapseBlocking', () {

      test('should elapse time synchronously', () {
        unit.elapseBlocking(elapseBy);
        expect(unit.clock.now(), initialTime.add(elapseBy));
      });

      test('should throw when called with a negative duration',
          () {
            expect(() {
              unit.elapseBlocking(const Duration(days: -1));
            }, throwsA(new isInstanceOf<ArgumentError>()));
          });

    });

    group('elapse', () {

      test('should elapse time asynchronously', () {
        unit.run((time) {
          time.elapse(elapseBy);
          expect(unit.clock.now(), initialTime.add(elapseBy));
        });
      });

      test('should throw ArgumentError when called with a negative duration',
          () {
            expect(
                () => unit.elapse(const Duration(days: -1)),
                throwsA(new isInstanceOf<ArgumentError>()));
          });

      test('should throw when called before previous call is complete', () {<commit_msg>Test that elapseBlocking doesn't  call timers<commit_after>// Copyright 2014 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

library quiver.testing.async.fake_time_test;

import 'dart:async';

import 'package:quiver/testing/async.dart';
import 'package:unittest/unittest.dart';

main() {
  group('FakeTime', () {

    FakeTime unit;
    DateTime initialTime;
    Duration elapseBy;

    setUp(() {
      initialTime = new DateTime(2000);
      unit = new FakeTime(initialTime: initialTime);
      elapseBy = const Duration(days: 1);
    });

    test('should set initial time', () {
      expect(unit.clock.now(), initialTime);
    });

    test('should default initial time to system time', () {
      expect(
          new FakeTime().clock.now().millisecondsSinceEpoch,
          closeTo(new DateTime.now().millisecondsSinceEpoch, 500));
    });

    group('elapseBlocking', () {

      test('should elapse time without calling timers', () {
        var timerCalled = false;
        new Timer(elapseBy ~/ 2, () => timerCalled = true);
        unit.elapseBlocking(elapseBy);
        expect(timerCalled, isFalse);
      });

      test('should elapse time by the specified amount', () {
        unit.elapseBlocking(elapseBy);
        expect(unit.clock.now(), initialTime.add(elapseBy));
      });

      test('should throw when called with a negative duration',
          () {
            expect(() {
              unit.elapseBlocking(const Duration(days: -1));
            }, throwsA(new isInstanceOf<ArgumentError>()));
          });

    });

    group('elapse', () {

      test('should elapse time by the specified amount', () {
        unit.run((time) {
          time.elapse(elapseBy);
          expect(unit.clock.now(), initialTime.add(elapseBy));
        });
      });

      test('should throw ArgumentError when called with a negative duration',
          () {
            expect(
                () => unit.elapse(const Duration(days: -1)),
                throwsA(new isInstanceOf<ArgumentError>()));
          });

      test('should throw when called before previous call is complete', () {
{'fraction_non_alphanumeric': 0.12667332667332667, 'fraction_numerical': 0.007392607392607393, 'mean_word_length': 2.6566837107377648, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3384859', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1338, 'n_words': 404}