anchor.diff:          unorderedEquals(['Object', 'A', 'B', 'C']));
     }
   }
  +
  +@reflectiveTest
  +class ImportLibraryTest extends AbstractContextTest with BuilderTestMixin {
  +  test_afterLibraryDirective_dart() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +library test;
  +
  +class A {}
  +''',
  +      uriList: ['dart:async'],
  +      expectedCode: '''
  +library test;
  +
  +import 'dart:async';
  +
  +
  +class A {}
  +''',
  +    );
  +  }
  +
  +  test_dart_beforeDart() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'dart:aaa';
  +import 'dart:ccc';
  +''',
  +      uriList: ['dart:bbb'],
  +      expectedCode: '''
  +import 'dart:aaa';
  +import 'dart:bbb';
  +import 'dart:ccc';
  +''',
  +    );
  +  }
  +
  +  test_dart_beforeDart_first() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'dart:bbb';
  +''',
  +      uriList: ['dart:aaa'],
  +      expectedCode: '''
  +import 'dart:aaa';
  +import 'dart:bbb';
  +''',
  +    );
  +  }
  +
  +  test_dart_beforePackage() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'package:foo/foo.dart';
  +''',
  +      uriList: ['dart:async'],
  +      expectedCode: '''
  +import 'dart:async';
  +
  +import 'package:foo/foo.dart';
  +''',
  +    );
  +  }
  +
  +  test_multiple_dart_then_package() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'dart:aaa';
  +import 'dart:ccc';
  +
  +import 'package:aaa/aaa.dart';
  +import 'package:ccc/ccc.dart';
  +''',
  +      uriList: ['dart:bbb', 'package:bbb/bbb.dart'],
  +      expectedCode: '''
  +import 'dart:aaa';
  +import 'dart:bbb';
  +import 'dart:ccc';
  +
  +import 'package:aaa/aaa.dart';
  +import 'package:bbb/bbb.dart';
  +import 'package:ccc/ccc.dart';
  +''',
  +    );
  +  }
  +
  +  test_multiple_package_then_dart() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'dart:aaa';
  +import 'dart:ccc';
  +
  +import 'package:aaa/aaa.dart';
  +import 'package:ccc/ccc.dart';
  +''',
  +      uriList: ['package:bbb/bbb.dart', 'dart:bbb'],
  +      expectedCode: '''
  +import 'dart:aaa';
  +import 'dart:bbb';
  +import 'dart:ccc';
  +
  +import 'package:aaa/aaa.dart';
  +import 'package:bbb/bbb.dart';
  +import 'package:ccc/ccc.dart';
  +''',
  +    );
  +  }
  +
  +  test_noDirectives_docComment() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +/// Documentation comment.
  +/// Continues.
  +void main() {}
  +''',
  +      uriList: ['dart:async'],
  +      expectedCode: '''
  +import 'dart:async';
  +
  +/// Documentation comment.
  +/// Continues.
  +void main() {}
  +''',
  +    );
  +  }
  +
  +  test_noDirectives_hashBang() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +#!/bin/dart
  +
  +void main() {}
  +''',
  +      uriList: ['dart:async'],
  +      expectedCode: '''
  +#!/bin/dart
  +
  +import 'dart:async';
  +
  +void main() {}
  +''',
  +    );
  +  }
  +
  +  test_noDirectives_lineComment() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +// Not documentation comment.
  +// Continues.
  +
  +void main() {}
  +''',
  +      uriList: ['dart:async'],
  +      expectedCode: '''
  +// Not documentation comment.
  +// Continues.
  +
  +import 'dart:async';
  +
  +void main() {}
  +''',
  +    );
  +  }
  +
  +  test_package_afterDart() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'dart:async';
  +''',
  +      uriList: ['package:aaa/aaa.dart'],
  +      expectedCode: '''
  +import 'dart:async';
  +
  +import 'package:aaa/aaa.dart';
  +''',
  +    );
  +  }
  +
  +  test_package_afterPackage() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'package:aaa/a1.dart';
  +
  +import 'foo.dart';
  +''',
  +      uriList: ['package:aaa/a2.dart'],
  +      expectedCode: '''
  +import 'package:aaa/a1.dart';
  +import 'package:aaa/a2.dart';
  +
  +import 'foo.dart';
  +''',
  +    );
  +  }
  +
  +  test_package_afterPackage_leadingComment() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +// comment
  +import 'package:aaa/a1.dart';
  +
  +import 'foo.dart';
  +''',
  +      uriList: ['package:aaa/a2.dart'],
  +      expectedCode: '''
  +// comment
  +import 'package:aaa/a1.dart';
  +import 'package:aaa/a2.dart';
  +
  +import 'foo.dart';
  +''',
  +    );
  +  }
  +
  +  test_package_afterPackage_trailingComment() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'package:aaa/a1.dart'; // comment
  +
  +import 'foo.dart';
  +''',
  +      uriList: ['package:aaa/a2.dart'],
  +      expectedCode: '''
  +import 'package:aaa/a1.dart'; // comment
  +import 'package:aaa/a2.dart';
  +
  +import 'foo.dart';
  +''',
  +    );
  +  }
  +
  +  test_package_beforePackage() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'package:aaa/a1.dart';
  +import 'package:aaa/a3.dart';
  +
  +import 'foo.dart';
  +''',
  +      uriList: ['package:aaa/a2.dart'],
  +      expectedCode: '''
  +import 'package:aaa/a1.dart';
  +import 'package:aaa/a2.dart';
  +import 'package:aaa/a3.dart';
  +
  +import 'foo.dart';
  +''',
  +    );
  +  }
  +
  +  test_package_beforePackage_first() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'package:aaa/a2.dart';
  +
  +import 'foo.dart';
  +''',
  +      uriList: ['package:aaa/a1.dart'],
  +      expectedCode: '''
  +import 'package:aaa/a1.dart';
  +import 'package:aaa/a2.dart';
  +
  +import 'foo.dart';
  +''',
  +    );
  +  }
  +
  +  test_package_beforePackage_leadingComments() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +// comment a2
  +import 'package:aaa/a2.dart';
  +
  +import 'foo.dart';
  +''',
  +      uriList: ['package:aaa/a1.dart'],
  +      expectedCode: '''
  +// comment a2
  +import 'package:aaa/a1.dart';
  +import 'package:aaa/a2.dart';
  +
  +import 'foo.dart';
  +''',
  +    );
  +  }
  +
  +  test_package_beforePackage_trailingComments() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'package:aaa/a2.dart'; // comment a2
  +
  +import 'foo.dart';
  +''',
  +      uriList: ['package:aaa/a1.dart'],
  +      expectedCode: '''
  +import 'package:aaa/a1.dart';
  +import 'package:aaa/a2.dart'; // comment a2
  +
  +import 'foo.dart';
  +''',
  +    );
  +  }
  +
  +  test_package_beforeRelative() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'foo.dart';
  +''',
  +      uriList: ['package:aaa/aaa.dart'],
  +      expectedCode: '''
  +import 'package:aaa/aaa.dart';
  +
  +import 'foo.dart';
  +''',
  +    );
  +  }
  +
  +  test_relative_afterDart() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'dart:async';
  +''',
  +      uriList: ['aaa.dart'],
  +      expectedCode: '''
  +import 'dart:async';
  +
  +import 'aaa.dart';
  +''',
  +    );
  +  }
  +
  +  test_relative_afterPackage() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'package:foo/foo.dart';
  +''',
  +      uriList: ['aaa.dart'],
  +      expectedCode: '''
  +import 'package:foo/foo.dart';
  +
  +import 'aaa.dart';
  +''',
  +    );
  +  }
  +
  +  test_relative_beforeRelative() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'dart:async';
  +
  +import 'package:foo/foo.dart';
  +
  +import 'aaa.dart';
  +import 'ccc.dart';
  +''',
  +      uriList: ['bbb.dart'],
  +      expectedCode: '''
  +import 'dart:async';
  +
  +import 'package:foo/foo.dart';
  +
  +import 'aaa.dart';
  +import 'bbb.dart';
  +import 'ccc.dart';
  +''',
  +    );
  +  }
  +
  +  test_relative_beforeRelative_first() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'dart:async';
  +
  +import 'package:foo/foo.dart';
  +
  +import 'bbb.dart';
  +''',
  +      uriList: ['aaa.dart'],
  +      expectedCode: '''
  +import 'dart:async';
  +
  +import 'package:foo/foo.dart';
  +
  +import 'aaa.dart';
  +import 'bbb.dart';
  +''',
  +    );
  +  }
  +
  +  test_relative_last() async {
  +    await _assertImportLibrary(
  +      initialCode: '''
  +import 'dart:async';
  +
  +import 'package:foo/foo.dart';
  +''',
  +      uriList: ['aaa.dart'],
  +      expectedCode: '''
  +import 'dart:async';
  +
  +import 'package:foo/foo.dart';
  +
  +import 'aaa.dart';
  +''',
  +    );
  +  }
  +
  +  Future<void> _assertImportLibrary({
  +    String initialCode,
  +    List<String> uriList,
  +    String expectedCode,
  +  }) async {
  +    String path = convertPath('/home/test/lib/test.dart');
  +    addSource(path, initialCode);
  +    DartChangeBuilderImpl builder = newBuilder();
  +    await builder.addFileEdit(path, (DartFileEditBuilder builder) {
  +      for (var i = 0; i < uriList.length; ++i) {
  +        var uri = Uri.parse(uriList[i]);
  +        builder.importLibrary(uri);
  +      }
  +    });
  +
  +    String resultCode = initialCode;
  +    List<SourceEdit> edits = getEdits(builder);
  +    for (SourceEdit edit in edits) {
  +      resultCode = edit.apply(resultCode);
  +    }
  +    expect(resultCode, expectedCode);
  +  }
  +}
  
positive.code:     defineReflectiveTests(DartEditBuilderImplTest);
      defineReflectiveTests(DartFileEditBuilderImplTest);
      defineReflectiveTests(DartLinkedEditBuilderImplTest);
    });
  }
  
  
negative.code: @reflectiveTest
  class DartEditBuilderImplTest extends AbstractContextTest
      with BuilderTestMixin {
    test_writeClassDeclaration_interfaces() async {
      String path = convertPath('/home/test/lib/test.dart');
      addSource(path, 'class A {}');
  