<commit_before>// Copyright (c) 2015, Google Inc. 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 built_collection.test.list.list_builder_test;

import 'dart:math' show Random;

import 'package:built_collection/built_collection.dart';
import 'package:test/test.dart';

import '../performance.dart';

void main() {
  group('ListBuilder', () {
    test('throws on attempt to create ListBuilder<dynamic>', () {
      expect(() => new ListBuilder(), throwsA(anything));
    });

    test('allows ListBuilder<Object>', () {
      new ListBuilder<Object>();
    });

    test('throws on null assign', () {
      var builder = new ListBuilder<int>([0]);
      expect(() => builder[0] = null, throwsA(anything));
      expect(builder.build(), orderedEquals([0]));
    });

    test('throws on null first', () {
      var builder = new ListBuilder<int>([0]);
      expect(() => builder.first = null, throwsA(anything));
      expect(builder.build(), orderedEquals([0]));
    });

    test('throws on null last', () {
      var builder = new ListBuilder<int>([0]);
      expect(() => builder.last = null, throwsA(anything));
      expect(builder.build(), orderedEquals([0]));
    });

    test('throws on null add', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.add(null), throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on null addAll', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.addAll([0, 1, null]), throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on null insert', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.insert(0, null), throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on null insertAll', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.insertAll(0, [0, 1, null]), throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on null setAll', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.setAll(0, [0, 1, null]), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on null setRange', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.setRange(0, 2, [0, 1, null]), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on null fillRange', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.fillRange(0, 2, null), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on null replaceRange', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.replaceRange(0, 2, [0, 1, null]), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on null map', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.map((x) => null), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on null expand', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.expand((x) => [x, null]), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on wrong type addAll', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.addAll(new List<int>.from([0, 1, '0'])),
          throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on wrong type insertAll', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.insertAll(0, new List<int>.from([0, 1, '0'])),
          throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on wrong type setAll', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.setAll(0, new List<int>.from([0, 1, '0'])),
          throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on wrong type setRange', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.setRange(0, 2, new List<int>.from([0, 1, '0'])),
          throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on wrong type replaceRange', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.replaceRange(0, 2, new List<int>.from([0, 1, '0'])),
          throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('has replace method that replaces all data', () {
      expect((new ListBuilder<int>()..replace([0, 1, 2])).build(), [0, 1, 2]);
    });

    // Lazy copies.

    test('does not mutate BuiltList when modifying ListBuilder assign', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder[0] = 3;
      expect(list, [1, 2]);
    });

    test('does not mutate BuiltList when modifying ListBuilder first', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder.first = 3;
      expect(list, [1, 2]);
    });

    test('does not mutate BuiltList when modifying ListBuilder last', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder.last = 3;
      expect(list, [1, 2]);
    });

    test('does not mutate BuiltList when modifying ListBuilder add', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder[0] = 3;
      expect(list, [1, 2]);
    });

    test('does not mutate BuiltList when modifying ListBuilder addAll', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder.addAll([3, 4]);
      expect(list, [1, 2]);
    });

    test('does not mutate BuiltList when modifying ListBuilder insert', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder.insert(0, 3);<commit_msg>Fix add test<commit_after>// Copyright (c) 2015, Google Inc. 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 built_collection.test.list.list_builder_test;

import 'dart:math' show Random;

import 'package:built_collection/built_collection.dart';
import 'package:test/test.dart';

import '../performance.dart';

void main() {
  group('ListBuilder', () {
    test('throws on attempt to create ListBuilder<dynamic>', () {
      expect(() => new ListBuilder(), throwsA(anything));
    });

    test('allows ListBuilder<Object>', () {
      new ListBuilder<Object>();
    });

    test('throws on null assign', () {
      var builder = new ListBuilder<int>([0]);
      expect(() => builder[0] = null, throwsA(anything));
      expect(builder.build(), orderedEquals([0]));
    });

    test('throws on null first', () {
      var builder = new ListBuilder<int>([0]);
      expect(() => builder.first = null, throwsA(anything));
      expect(builder.build(), orderedEquals([0]));
    });

    test('throws on null last', () {
      var builder = new ListBuilder<int>([0]);
      expect(() => builder.last = null, throwsA(anything));
      expect(builder.build(), orderedEquals([0]));
    });

    test('throws on null add', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.add(null), throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on null addAll', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.addAll([0, 1, null]), throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on null insert', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.insert(0, null), throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on null insertAll', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.insertAll(0, [0, 1, null]), throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on null setAll', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.setAll(0, [0, 1, null]), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on null setRange', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.setRange(0, 2, [0, 1, null]), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on null fillRange', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.fillRange(0, 2, null), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on null replaceRange', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.replaceRange(0, 2, [0, 1, null]), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on null map', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.map((x) => null), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on null expand', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.expand((x) => [x, null]), throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on wrong type addAll', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.addAll(new List<int>.from([0, 1, '0'])),
          throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on wrong type insertAll', () {
      var builder = new ListBuilder<int>();
      expect(() => builder.insertAll(0, new List<int>.from([0, 1, '0'])),
          throwsA(anything));
      expect(builder.build(), isEmpty);
    });

    test('throws on wrong type setAll', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.setAll(0, new List<int>.from([0, 1, '0'])),
          throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on wrong type setRange', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.setRange(0, 2, new List<int>.from([0, 1, '0'])),
          throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('throws on wrong type replaceRange', () {
      var builder = new ListBuilder<int>([0, 1, 2]);
      expect(() => builder.replaceRange(0, 2, new List<int>.from([0, 1, '0'])),
          throwsA(anything));
      expect(builder.build(), orderedEquals([0, 1, 2]));
    });

    test('has replace method that replaces all data', () {
      expect((new ListBuilder<int>()..replace([0, 1, 2])).build(), [0, 1, 2]);
    });

    // Lazy copies.

    test('does not mutate BuiltList when modifying ListBuilder assign', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder[0] = 3;
      expect(list, [1, 2]);
    });

    test('does not mutate BuiltList when modifying ListBuilder first', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder.first = 3;
      expect(list, [1, 2]);
    });

    test('does not mutate BuiltList when modifying ListBuilder last', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder.last = 3;
      expect(list, [1, 2]);
    });

    test('does not mutate BuiltList when modifying ListBuilder add', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder.add(3);
      expect(list, [1, 2]);
    });

    test('does not mutate BuiltList when modifying ListBuilder addAll', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder.addAll([3, 4]);
      expect(list, [1, 2]);
    });

    test('does not mutate BuiltList when modifying ListBuilder insert', () {
      var list = new BuiltList<int>([1, 2]);
      var listBuilder = list.toBuilder();
      listBuilder.insert(0, 3);
{'fraction_non_alphanumeric': 0.18875406455706242, 'fraction_numerical': 0.022602902688555793, 'mean_word_length': 3.1317169069462647, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 111, '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': '5915825', 'n_tokens_mistral': 4031, 'n_tokens_neox': 3775, 'n_words': 1048}