<commit_before>// Copyright 2015 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0, found in the LICENSE file.

/// Unit tests for Shapeshift's method attributes reporter.
library method_attributes_reporter_tests;

import 'dart:convert';

import 'package:json_diff/json_diff.dart';
import 'package:shapeshift/shapeshift_cli.dart';
import 'package:shapeshift/shapeshift_common.dart';
import 'package:unittest/unittest.dart';


void main() {
  MethodAttributesReporter mar;
  ReadableStringSink io;
  Map<String, dynamic> v1, v2;

  jsonFrom(Map obj) => new JsonEncoder().convert(obj);
  expectIoContains(RegExp re) => expect(io.read(), matches(re));

  setUp(() {
    io = new ReadableStringSink();
  });

  test('Shapeshift reports on changed method attributes', () {
    v1 = base;
    v2 = base
      ..['abstract'] = true;

    diffAndReport(jsonFrom(v1), jsonFrom(v2), io);
    expectIoContains(new RegExp(
        r'''The \[foo\]\(.*\) method's `abstract` changed:

Was: `false`

Now: `true`'''));
  });

  test('Shapeshift reports on deep method attribute additions', () {
    v1 = base;
    v2 = base
      ..['annotations'].add({'name':'foo.Bar','parameters':[]});

    diffAndReport(jsonFrom(v1), jsonFrom(v2), io);
    expectIoContains(new RegExp(
        r'''The \[foo\]\(.*\) method has new annotations:

\* `@Bar\(\)`'''));
  });
}

Map<String, dynamic> get base => {
  'name': 'foo',
  'qualifiedName': 'foo.Foo.foo',
  'comment': '<p>Send a data event to a stream.</p>',
  'abstract': false,
  'annotations': [],
};

void diffAndReport(String v1, String v2, ReadableStringSink io) {
  DiffNode diff = diffApis(v1, v2);<commit_msg>Testing<commit_after>// Copyright 2015 Google Inc. All Rights Reserved.
// Licensed under the Apache License, Version 2.0, found in the LICENSE file.

/// Unit tests for Shapeshift's method attributes reporter.
library method_attributes_reporter_tests;

import 'dart:convert';

import 'package:json_diff/json_diff.dart';
import 'package:shapeshift/shapeshift_cli.dart';
import 'package:shapeshift/shapeshift_common.dart';
import 'package:unittest/unittest.dart';


void main() {
  MethodAttributesReporter mar;
  ReadableStringSink io;
  Map<String, dynamic> v1, v2;

  jsonFrom(Map obj) => new JsonEncoder().convert(obj);
  expectIoContains(RegExp re) => expect(io.read(), matches(re));

  setUp(() {
    io = new ReadableStringSink();
  });

  test('Shapeshift reports on changed method attributes', () {
    v1 = base;
    v2 = base
      ..['abstract'] = true;

    diffAndReport(jsonFrom(v1), jsonFrom(v2), io);
    expectIoContains(new RegExp(
        r'''The \[foo\]\(.*\) method's `abstract` changed:

Was: `false`

Now: `true`'''));
  });

  test('Shapeshift reports on deep method attribute additions', () {
    v1 = base;
    v2 = base
      ..['annotations'].add({'name':'foo.Bar','parameters':[]});

    diffAndReport(jsonFrom(v1), jsonFrom(v2), io);
    expectIoContains(new RegExp(
        r'''The \[foo\]\(.*\) method has new annotations:

\* `@Bar\(\)`'''));
  });

  test('Shapeshift reports on deep method attribute removals', () {
    v1 = base
      ..['annotations'].add({'name':'foo.Bar','parameters':[]});
    v2 = base;

    diffAndReport(jsonFrom(v1), jsonFrom(v2), io);
    expectIoContains(new RegExp(
        r'''The \[foo\]\(.*\) method has removed annotations:

\* `@Bar\(\)`'''));
  });
}

Map<String, dynamic> get base => {
  'name': 'foo',
  'qualifiedName': 'foo.Foo.foo',
  'comment': '<p>Send a data event to a stream.</p>',
  'commentFrom': '',
  'inheritedFrom': '',
  'static': false,
  'abstract': false,
  'constant': false,
  'return': [
    {'outer': 'dart:core.Foo', 'inner': []},
  ],
  'parameters': {},
  'annotations': [],
};

void diffAndReport(String v1, String v2, ReadableStringSink io) {
  DiffNode diff = diffApis(v1, v2);
{'fraction_non_alphanumeric': 0.17976653696498054, 'fraction_numerical': 0.011413748378728923, 'mean_word_length': 4.020833333333333, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '3744695', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1281, 'n_words': 316}