<commit_before>// Copyright (c) 2013, 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.

library vmservice_test_helper;

import 'dart:async';
import 'dart:io';
import 'dart:json' as JSON;
import 'dart:utf' as UTF;
import 'package:expect/expect.dart';

abstract class VmServiceRequestHelper {
  final Uri uri;
  final HttpClient client;

  VmServiceRequestHelper(String url) :
      uri = Uri.parse(url),
      client = new HttpClient();

  Future makeRequest() {
    return client.getUrl(uri)
      .then((HttpClientRequest request) => request.close())
      .then((HttpClientResponse response) {
        return response
            .fold(new BytesBuilder(), (b, d) => b..add(d))
            .then((builder) {
              _requestCompleted(builder.takeBytes(), response);
            });
      }).catchError((error) {
        onRequestFailed(error);
      });
  }

  void _requestCompleted(List<int> data, HttpClientResponse response) {
    Expect.equals(200, response.statusCode);
    var replyAsString;
    try {
      replyAsString = UTF.decodeUtf8(data, 0, null, null);
    } catch (e) {
      onRequestFailed(e);
      return;
    }
    var reply;
    try {
      reply = JSON.parse(replyAsString);
    } catch (e) {
      onRequestFailed(e);
      return;
    }
    // Received a map.
    Expect.isTrue(reply is Map);
    // Has a 'type' key.
    Expect.isNotNull(reply['type']);
    onRequestCompleted(reply);
  }

  void onRequestFailed(dynamic error) {
    Expect.fail('Failed to make request: $error');
  }

  void onRequestCompleted(Map response);
}

class TestLauncher {
  final String script;
  Process process;

  TestLauncher(this.script);

  String get scriptPath {
    var dartScript = Platform.script;<commit_msg>Attempt to get more data from multiple_isolate_list_test<commit_after>// Copyright (c) 2013, 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.

library vmservice_test_helper;

import 'dart:async';
import 'dart:io';
import 'dart:json' as JSON;
import 'dart:utf' as UTF;
import 'package:expect/expect.dart';

abstract class VmServiceRequestHelper {
  final Uri uri;
  final HttpClient client;

  VmServiceRequestHelper(String url) :
      uri = Uri.parse(url),
      client = new HttpClient();

  Future makeRequest() {
    return client.getUrl(uri)
      .then((HttpClientRequest request) => request.close())
      .then((HttpClientResponse response) {
        return response
            .fold(new BytesBuilder(), (b, d) => b..add(d))
            .then((builder) {
              _requestCompleted(builder.takeBytes(), response);
            });
      }).catchError((error) {
        onRequestFailed(error);
      });
  }

  void _requestCompleted(List<int> data, HttpClientResponse response) {
    Expect.equals(200, response.statusCode);
    var replyAsString;
    try {
      replyAsString = UTF.decodeUtf8(data, 0, null, null);
    } catch (e) {
      onRequestFailed(e);
      return;
    }
    var reply;
    try {
      reply = JSON.parse(replyAsString);
    } catch (e) {
      onRequestFailed(e);
      return;
    }
    if (reply is! Map) {
        onRequestFailed('Reply was not a map: $reply');
        return;
    }
    if (reply['type'] == null) {
        onRequestFailed('Reply does not contain a type key: $reply');
        return;
    }
    try {
        onRequestCompleted(reply);
    } catch(e) {
        onRequestFailed('Test callback failed: $e');
    }
  }

  void onRequestFailed(dynamic error) {
    Expect.fail('Failed to make request: $error');
  }

  void onRequestCompleted(Map response);
}

class TestLauncher {
  final String script;
  Process process;

  TestLauncher(this.script);

  String get scriptPath {
    var dartScript = Platform.script;
{'fraction_non_alphanumeric': 0.11514392991239049, 'fraction_numerical': 0.004505632040050063, 'mean_word_length': 2.88715953307393, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2548195', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1184, 'n_words': 333}