<commit_before>// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';

import '../test_utils.dart';
import 'json_test_common.dart' show Category, House, Platform;
import 'json_test_example.dart';

void main() {
  group('Person', () {
    void roundTripPerson(Person p) {
      roundTripObject(p, (json) => new Person.fromJson(json));
    }

    test('null', () {
      roundTripPerson(new Person(null, null, null));
    });

    test('empty', () {
      roundTripPerson(new Person('', '', null,
          middleName: '',
          dateOfBirth: new DateTime.fromMillisecondsSinceEpoch(0)));
    });

    test('now', () {
      roundTripPerson(new Person('a', 'b', House.gryffindor,
          middleName: 'c', dateOfBirth: new DateTime.now()));
    });

    test('now toUtc', () {
      roundTripPerson(new Person('a', 'b', House.hufflepuff,
          middleName: 'c', dateOfBirth: new DateTime.now().toUtc()));
    });

    test('empty json', () {
      var person = new Person.fromJson({});
      expect(person.dateOfBirth, isNull);
      roundTripPerson(person);
    });

    test('enum map', () {
      var person = new Person(null, null, null)
        ..houseMap = {'bob': House.gryffindor};
      expect(person.dateOfBirth, isNull);
      roundTripPerson(person);
    });
  });

  group('Order', () {
    void roundTripOrder(Order p) {
      roundTripObject(p, (json) => new Order.fromJson(json));
    }

    test('null', () {
      roundTripOrder(new Order(Category.charmed));
    });

    test('empty', () {
      roundTripOrder(new Order(Category.strange, const [])
        ..count = 0
        ..isRushed = false);
    });

    test('simple', () {
      roundTripOrder(new Order(Category.top, <Item>[
        new Item(24)
          ..itemNumber = 42
          ..saleDates = [new DateTime.now()]
      ])
        ..count = 42
        ..isRushed = true);
    });

    test('almost empty json', () {
      var order = new Order.fromJson({'category': 'top'});
      expect(order.items, isEmpty);
      expect(order.category, Category.top);
      roundTripOrder(order);
    });

    test('required, but missing enum value fails', () {
      expect(() => new Order.fromJson({}), throwsArgumentError);
    });

    test('mismatched enum value fails', () {
      expect(
          () => new Order.fromJson({'category': 'weird'}), throwsArgumentError);
    });

    test('platform', () {
      var order = new Order(Category.charmed)
        ..platform = Platform.undefined
        ..altPlatforms = {
          'u': Platform.undefined,
          'f': Platform.foo,
          'null': null
        };

      roundTripOrder(order);
    });
<commit_msg>misc(test/integration): improve test expectations for ArgumentError<commit_after>// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';

import '../test_utils.dart';
import 'json_test_common.dart' show Category, House, Platform;
import 'json_test_example.dart';

Matcher _throwsArgumentError(matcher) =>
    throwsA(isArgumentError.having((e) => e.message, 'message', matcher));

void main() {
  group('Person', () {
    void roundTripPerson(Person p) {
      roundTripObject(p, (json) => new Person.fromJson(json));
    }

    test('null', () {
      roundTripPerson(new Person(null, null, null));
    });

    test('empty', () {
      roundTripPerson(new Person('', '', null,
          middleName: '',
          dateOfBirth: new DateTime.fromMillisecondsSinceEpoch(0)));
    });

    test('now', () {
      roundTripPerson(new Person('a', 'b', House.gryffindor,
          middleName: 'c', dateOfBirth: new DateTime.now()));
    });

    test('now toUtc', () {
      roundTripPerson(new Person('a', 'b', House.hufflepuff,
          middleName: 'c', dateOfBirth: new DateTime.now().toUtc()));
    });

    test('empty json', () {
      var person = new Person.fromJson({});
      expect(person.dateOfBirth, isNull);
      roundTripPerson(person);
    });

    test('enum map', () {
      var person = new Person(null, null, null)
        ..houseMap = {'bob': House.gryffindor};
      expect(person.dateOfBirth, isNull);
      roundTripPerson(person);
    });
  });

  group('Order', () {
    void roundTripOrder(Order p) {
      roundTripObject(p, (json) => new Order.fromJson(json));
    }

    test('null', () {
      roundTripOrder(new Order(Category.charmed));
    });

    test('empty', () {
      roundTripOrder(new Order(Category.strange, const [])
        ..count = 0
        ..isRushed = false);
    });

    test('simple', () {
      roundTripOrder(new Order(Category.top, <Item>[
        new Item(24)
          ..itemNumber = 42
          ..saleDates = [new DateTime.now()]
      ])
        ..count = 42
        ..isRushed = true);
    });

    test('almost empty json', () {
      var order = new Order.fromJson({'category': 'top'});
      expect(order.items, isEmpty);
      expect(order.category, Category.top);
      roundTripOrder(order);
    });

    test('required, but missing enum value fails', () {
      expect(
          () => new Order.fromJson({}),
          _throwsArgumentError('`null` is not one of the supported values: '
              'top, bottom, strange, charmed, up, down'));
    });

    test('mismatched enum value fails', () {
      expect(
          () => new Order.fromJson({'category': 'weird'}),
          _throwsArgumentError('`weird` is not one of the supported values: '
              'top, bottom, strange, charmed, up, down'));
    });

    test('platform', () {
      var order = new Order(Category.charmed)
        ..platform = Platform.undefined
        ..altPlatforms = {
          'u': Platform.undefined,
          'f': Platform.foo,
          'null': null
        };

      roundTripOrder(order);
    });

{'fraction_non_alphanumeric': 0.16226415094339622, 'fraction_numerical': 0.003937653814602133, 'mean_word_length': 2.583774250440917, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1560391', 'n_tokens_mistral': 1917, 'n_tokens_neox': 1853, 'n_words': 431}