| Index: dart/tests/compiler/dart2js/patch2_test.dart
|
| diff --git a/dart/tests/compiler/dart2js/patch2_test.dart b/dart/tests/compiler/dart2js/patch2_test.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3a838207f65c94d03d0c6c3f2bb966290b97e665
|
| --- /dev/null
|
| +++ b/dart/tests/compiler/dart2js/patch2_test.dart
|
| @@ -0,0 +1,48 @@
|
| +// 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.
|
| +
|
| +import "mock_compiler.dart";
|
| +
|
| +import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart"
|
| + show Element, FunctionElement;
|
| +import "../../../sdk/lib/_internal/compiler/implementation/patch_parser.dart";
|
| +import "../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.dart"
|
| + show StringScanner;
|
| +import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart";
|
| +
|
| +class TestPatchElementListener extends PatchElementListener {
|
| + TestPatchElementListener(compiler, unit)
|
| + : super(compiler, unit, compiler.getNextFreeClassId, new LinkBuilder());
|
| +
|
| + void applyPatch(Element patch) {
|
| + }
|
| +}
|
| +
|
| +Element buildElement(MockCompiler compiler, String source) {
|
| + var library = compiler.createLibrary('origin', 'external foo();');
|
| + var elements = library.localMembers.toList();
|
| + Expect.equals(1, elements.length);
|
| + return elements[0];
|
| +}
|
| +
|
| +Element buildPatchElement(MockCompiler compiler, String source) {
|
| + var library = compiler.createUnparsedLibrary('patch', source);
|
| + var unit = library.entryCompilationUnit;
|
| +
|
| + var tokens = new StringScanner(source).tokenize();
|
| + var listener = new TestPatchElementListener(compiler, unit);
|
| + new PatchParser(listener).parseUnit(tokens);
|
| +
|
| + var elements = unit.localMembers.toList();
|
| + Expect.equals(1, elements.length);
|
| + Expect.isTrue(isPatchElement(elements[0]));
|
| + return elements[0];
|
| +}
|
| +
|
| +main() {
|
| + MockCompiler compiler = new MockCompiler();
|
| + FunctionElement foo = buildElement(compiler, 'external foo();');
|
| + FunctionElement fooPatch = buildPatchElement(compiler, 'patch foo() {}');
|
| + patchElement(null, foo, fooPatch);
|
| +}
|
|
|