1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-03 00:08:46 +00:00

Enforce LF line endings in the git database.

BUG=
R=ricow@google.com

Review URL: https://codereview.chromium.org//1168393003.
This commit is contained in:
Stephan Herhut 2015-06-25 13:41:53 +02:00
parent fbbc4c08ed
commit b1c1606e17
44 changed files with 13537 additions and 13518 deletions

19
.gitattributes vendored Normal file
View File

@ -0,0 +1,19 @@
# Explicitly declare text files we want to be normalized.
*.c text
*.cpp text
*.h text
*.gyp text
*.gypi text
*.dart text
*.mk text
*.Makefile text
*.md text
*.yaml text
# Windows files that should not be converted.
tests/lib/mirrors/method_mirror_source_line_ending_crlf.dart -text
# Files to leave alone and not diff.
*.png binary
*.jpg binary
*.xpi binary

View File

@ -1,22 +1,22 @@
// Copyright (c) 2014, 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.
// Test that dart2js produces the expected static type warnings and
// compile-time errors for these tests.
import 'frontend_checker.dart';
/// Map of test files to run together with their associated whitelist.
///
/// For instance
/// 'language/async_await_syntax_test.dart': const ['a03b', 'a04b']
/// includes the multitest in 'language/async_await_syntax_test.dart' but
/// expects the subtests 'a03b' and 'a04c' to fail.
const Map<String, List<String>> TESTS = const <String, List<String>>{
'language/async_await_syntax_test.dart': const [],
};
void main(List<String> arguments) {
check(TESTS, arguments: arguments, options: ['--enable-async']);
}
// Copyright (c) 2014, 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.
// Test that dart2js produces the expected static type warnings and
// compile-time errors for these tests.
import 'frontend_checker.dart';
/// Map of test files to run together with their associated whitelist.
///
/// For instance
/// 'language/async_await_syntax_test.dart': const ['a03b', 'a04b']
/// includes the multitest in 'language/async_await_syntax_test.dart' but
/// expects the subtests 'a03b' and 'a04c' to fail.
const Map<String, List<String>> TESTS = const <String, List<String>>{
'language/async_await_syntax_test.dart': const [],
};
void main(List<String> arguments) {
check(TESTS, arguments: arguments, options: ['--enable-async']);
}

View File

@ -1,37 +1,37 @@
// Copyright (c) 2014, 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.
/// End-to-end test of the dart2dart compiler.
library dart_backend.end2end_test;
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/dart2jslib.dart';
import 'package:compiler/src/dart_backend/dart_backend.dart';
import 'package:expect/expect.dart';
import '../../../../pkg/analyzer2dart/test/test_helper.dart' hide TestSpec;
import '../../../../pkg/analyzer2dart/test/end2end_data.dart';
import 'test_helper.dart';
import '../output_collector.dart';
main(List<String> args) {
performTests(TEST_DATA, asyncTester, runTest, args);
}
runTest(TestSpec result) {
OutputCollector outputCollector = new OutputCollector();
asyncTest(() => compilerFor(result.input, outputProvider: outputCollector)
.then((Compiler compiler) {
String expectedOutput = result.output.trim();
compiler.phase = Compiler.PHASE_COMPILING;
DartBackend backend = compiler.backend;
backend.assembleProgram();
String output = outputCollector.getOutput('', 'dart').trim();
Expect.equals(expectedOutput, output,
'\nInput:\n${result.input}\n'
'Expected:\n$expectedOutput\n'
'Actual:\n$output\n');
}));
// Copyright (c) 2014, 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.
/// End-to-end test of the dart2dart compiler.
library dart_backend.end2end_test;
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/dart2jslib.dart';
import 'package:compiler/src/dart_backend/dart_backend.dart';
import 'package:expect/expect.dart';
import '../../../../pkg/analyzer2dart/test/test_helper.dart' hide TestSpec;
import '../../../../pkg/analyzer2dart/test/end2end_data.dart';
import 'test_helper.dart';
import '../output_collector.dart';
main(List<String> args) {
performTests(TEST_DATA, asyncTester, runTest, args);
}
runTest(TestSpec result) {
OutputCollector outputCollector = new OutputCollector();
asyncTest(() => compilerFor(result.input, outputProvider: outputCollector)
.then((Compiler compiler) {
String expectedOutput = result.output.trim();
compiler.phase = Compiler.PHASE_COMPILING;
DartBackend backend = compiler.backend;
backend.assembleProgram();
String output = outputCollector.getOutput('', 'dart').trim();
Expect.equals(expectedOutput, output,
'\nInput:\n${result.input}\n'
'Expected:\n$expectedOutput\n'
'Actual:\n$output\n');
}));
}

View File

@ -1,62 +1,62 @@
// Copyright (c) 2014, 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.
/// Unittest test of the CPS ir generated by the dart2dart compiler.
library dart_backend.sexpr2_test;
import 'package:compiler/src/dart2jslib.dart';
import 'package:compiler/src/cps_ir/cps_ir_nodes.dart';
import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart';
import 'package:compiler/src/elements/elements.dart';
import 'package:expect/expect.dart';
import '../../../../pkg/analyzer2dart/test/test_helper.dart';
import '../../../../pkg/analyzer2dart/test/sexpr_data.dart';
import 'test_helper.dart';
main(List<String> args) {
performTests(TEST_DATA, asyncTester, runTest, args);
}
runTest(TestSpec result) {
return compilerFor(result.input).then((Compiler compiler) {
void checkOutput(String elementName,
Element element,
String expectedOutput) {
FunctionDefinition ir = compiler.irBuilder.getIr(element);
if (expectedOutput == null) {
Expect.isNull(ir, "\nInput:\n${result.input}\n"
"No CPS IR expected for $element");
} else {
Expect.isNotNull(ir, "\nInput:\n${result.input}\n"
"No CPS IR for $element");
expectedOutput = expectedOutput.trim();
String output = ir.accept(new SExpressionStringifier()).trim();
Expect.equals(expectedOutput, output,
"\nInput:\n${result.input}\n"
"Expected for '$elementName':\n$expectedOutput\n"
"Actual for '$elementName':\n$output\n");
}
}
if (result.output is String) {
checkOutput('main', compiler.mainFunction, result.output);
} else {
assert(result.output is Map<String, String>);
result.output.forEach((String elementName, String output) {
Element element;
if (elementName.contains('.')) {
ClassElement cls = compiler.mainApp.localLookup(
elementName.substring(0, elementName.indexOf('.')));
element = cls.localLookup(
elementName.substring(elementName.indexOf('.') + 1));
} else {
element = compiler.mainApp.localLookup(elementName);
}
checkOutput(elementName, element, output);
});
}
});
// Copyright (c) 2014, 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.
/// Unittest test of the CPS ir generated by the dart2dart compiler.
library dart_backend.sexpr2_test;
import 'package:compiler/src/dart2jslib.dart';
import 'package:compiler/src/cps_ir/cps_ir_nodes.dart';
import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart';
import 'package:compiler/src/elements/elements.dart';
import 'package:expect/expect.dart';
import '../../../../pkg/analyzer2dart/test/test_helper.dart';
import '../../../../pkg/analyzer2dart/test/sexpr_data.dart';
import 'test_helper.dart';
main(List<String> args) {
performTests(TEST_DATA, asyncTester, runTest, args);
}
runTest(TestSpec result) {
return compilerFor(result.input).then((Compiler compiler) {
void checkOutput(String elementName,
Element element,
String expectedOutput) {
FunctionDefinition ir = compiler.irBuilder.getIr(element);
if (expectedOutput == null) {
Expect.isNull(ir, "\nInput:\n${result.input}\n"
"No CPS IR expected for $element");
} else {
Expect.isNotNull(ir, "\nInput:\n${result.input}\n"
"No CPS IR for $element");
expectedOutput = expectedOutput.trim();
String output = ir.accept(new SExpressionStringifier()).trim();
Expect.equals(expectedOutput, output,
"\nInput:\n${result.input}\n"
"Expected for '$elementName':\n$expectedOutput\n"
"Actual for '$elementName':\n$output\n");
}
}
if (result.output is String) {
checkOutput('main', compiler.mainFunction, result.output);
} else {
assert(result.output is Map<String, String>);
result.output.forEach((String elementName, String output) {
Element element;
if (elementName.contains('.')) {
ClassElement cls = compiler.mainApp.localLookup(
elementName.substring(0, elementName.indexOf('.')));
element = cls.localLookup(
elementName.substring(elementName.indexOf('.') + 1));
} else {
element = compiler.mainApp.localLookup(elementName);
}
checkOutput(elementName, element, output);
});
}
});
}

View File

@ -1,46 +1,46 @@
// Copyright (c) 2014, 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 dart_backend.test_helper;
import 'dart:async';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/compiler.dart' as api;
import 'package:compiler/src/dart2jslib.dart';
import '../../../../pkg/analyzer2dart/test/test_helper.dart';
import '../compiler_helper.dart';
/// Compiles the given dart code (which must include a 'main' function) and
/// returns the compiler.
Future<Compiler> compilerFor(String code,
{api.CompilerOutputProvider outputProvider}) {
MockCompiler compiler = new MockCompiler.internal(
emitJavaScript: false,
enableMinification: false,
outputProvider: outputProvider);
compiler.diagnosticHandler = createHandler(compiler, code);
return compiler.init().then((_) {
compiler.parseScript(code);
Element element = compiler.mainApp.find('main');
if (element == null) return null;
compiler.mainFunction = element;
compiler.phase = Compiler.PHASE_RESOLVING;
compiler.backend.enqueueHelpers(compiler.enqueuer.resolution,
compiler.globalDependencies);
compiler.processQueue(compiler.enqueuer.resolution, element);
compiler.world.populate();
compiler.backend.onResolutionComplete();
compiler.irBuilder.buildNodes();
return compiler;
});
}
/// Test group using async_helper.
asyncTester(Group group, RunTest runTest) {
asyncTest(() => Future.forEach(group.results, runTest));
}
// Copyright (c) 2014, 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 dart_backend.test_helper;
import 'dart:async';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/compiler.dart' as api;
import 'package:compiler/src/dart2jslib.dart';
import '../../../../pkg/analyzer2dart/test/test_helper.dart';
import '../compiler_helper.dart';
/// Compiles the given dart code (which must include a 'main' function) and
/// returns the compiler.
Future<Compiler> compilerFor(String code,
{api.CompilerOutputProvider outputProvider}) {
MockCompiler compiler = new MockCompiler.internal(
emitJavaScript: false,
enableMinification: false,
outputProvider: outputProvider);
compiler.diagnosticHandler = createHandler(compiler, code);
return compiler.init().then((_) {
compiler.parseScript(code);
Element element = compiler.mainApp.find('main');
if (element == null) return null;
compiler.mainFunction = element;
compiler.phase = Compiler.PHASE_RESOLVING;
compiler.backend.enqueueHelpers(compiler.enqueuer.resolution,
compiler.globalDependencies);
compiler.processQueue(compiler.enqueuer.resolution, element);
compiler.world.populate();
compiler.backend.onResolutionComplete();
compiler.irBuilder.buildNodes();
return compiler;
});
}
/// Test group using async_helper.
asyncTester(Group group, RunTest runTest) {
asyncTest(() => Future.forEach(group.results, runTest));
}

View File

@ -1,53 +1,53 @@
// 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.
// Test that dart2js produces the expected static type warnings for least upper
// bound language tests. This ensures that the analyzer and dart2js agrees
// on these tests.
import 'warnings_checker.dart';
/// Map from test files to a map of their expected status. If the status map is
/// `null` no warnings must be missing or unexpected, otherwise the status map
/// can contain a list of line numbers for keys 'missing' and 'unexpected' for
/// the warnings of each category.
const Map<String, dynamic> TESTS = const {
// Instance methods.
'co19/src/Language/07_Classes/1_Instance_Methods_A01_t01.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A01_t02.dart': null,
'language/check_method_override_test.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A06_t01.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A06_t02.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t01.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t02.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t03.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t04.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t05.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t06.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t01.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t02.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t03.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t04.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t05.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t06.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t01.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t02.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t04.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t05.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t06.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t07.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t08.dart': null,
// Getters.
'co19/src/Language/07_Classes/2_Getters_A05_t01.dart': null,
'co19/src/Language/07_Classes/2_Getters_A05_t02.dart': null,
'co19/src/Language/07_Classes/2_Getters_A05_t03.dart': null,
'co19/src/Language/07_Classes/2_Getters_A05_t04.dart': null,
};
void main() {
checkWarnings(TESTS);
}
// 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.
// Test that dart2js produces the expected static type warnings for least upper
// bound language tests. This ensures that the analyzer and dart2js agrees
// on these tests.
import 'warnings_checker.dart';
/// Map from test files to a map of their expected status. If the status map is
/// `null` no warnings must be missing or unexpected, otherwise the status map
/// can contain a list of line numbers for keys 'missing' and 'unexpected' for
/// the warnings of each category.
const Map<String, dynamic> TESTS = const {
// Instance methods.
'co19/src/Language/07_Classes/1_Instance_Methods_A01_t01.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A01_t02.dart': null,
'language/check_method_override_test.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A06_t01.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A06_t02.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t01.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t02.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t03.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t04.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t05.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A02_t06.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t01.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t02.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t03.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t04.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t05.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A03_t06.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t01.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t02.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t04.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t05.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t06.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t07.dart': null,
'co19/src/Language/07_Classes/1_Instance_Methods_A05_t08.dart': null,
// Getters.
'co19/src/Language/07_Classes/2_Getters_A05_t01.dart': null,
'co19/src/Language/07_Classes/2_Getters_A05_t02.dart': null,
'co19/src/Language/07_Classes/2_Getters_A05_t03.dart': null,
'co19/src/Language/07_Classes/2_Getters_A05_t04.dart': null,
};
void main() {
checkWarnings(TESTS);
}

View File

@ -1,237 +1,237 @@
// Copyright (c) 2015, 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 dart2js.constants.expressions.evaluate_test;
import 'dart:async';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'package:compiler/src/constants/expressions.dart';
import 'package:compiler/src/constants/values.dart';
import 'package:compiler/src/constant_system_dart.dart';
import 'package:compiler/src/core_types.dart';
import 'package:compiler/src/dart2jslib.dart';
import 'package:compiler/src/elements/elements.dart';
import 'memory_compiler.dart';
class TestData {
/// Declarations needed for the [constants].
final String declarations;
/// Tested constants.
final List constants;
const TestData(this.declarations, this.constants);
}
class ConstantData {
/// Source code for the constant expression.
final String code;
/// Map from environment to expected constant value as structured text.
final Map<Map<String, String>, String> expectedValues;
const ConstantData(this.code,
this.expectedValues);
}
class MemoryEnvironment implements Environment {
final Compiler compiler;
final Map<String, String> env;
MemoryEnvironment(this.compiler,
[this.env = const <String, String>{}]);
@override
String readFromEnvironment(String name) => env[name];
}
const List<TestData> DATA = const [
const TestData('', const [
const ConstantData('null', const { const {} : 'NullConstant' }),
const ConstantData('false', const { const {} : 'BoolConstant(false)' }),
const ConstantData('true', const { const {} : 'BoolConstant(true)' }),
const ConstantData('0', const { const {} : 'IntConstant(0)' }),
const ConstantData('0.0', const { const {} : 'DoubleConstant(0.0)' }),
const ConstantData('"foo"', const { const {} : 'StringConstant("foo")' }),
const ConstantData('1 + 2', const { const {} : 'IntConstant(3)' }),
const ConstantData('-(1)', const { const {} : 'IntConstant(-1)' }),
const ConstantData('"foo".length', const { const {} : 'IntConstant(3)' }),
const ConstantData('identical(0, 1)',
const { const {} : 'BoolConstant(false)' }),
const ConstantData('"a" "b"', const { const {} : 'StringConstant("ab")' }),
const ConstantData('identical',
const { const {} : 'FunctionConstant(identical)' }),
const ConstantData('true ? 0 : 1', const { const {} : 'IntConstant(0)' }),
const ConstantData('proxy',
const { const {} : 'ConstructedConstant(_Proxy())' }),
const ConstantData('Object', const { const {} : 'TypeConstant(Object)' }),
const ConstantData('const [0, 1]',
const { const {} : 'ListConstant([IntConstant(0), IntConstant(1)])' }),
const ConstantData('const <int>[0, 1]', const {
const {} : 'ListConstant(<int>[IntConstant(0), IntConstant(1)])' }),
const ConstantData('const {0: 1, 2: 3}',
const { const {} :
'MapConstant({IntConstant(0): IntConstant(1), '
'IntConstant(2): IntConstant(3)})' }),
const ConstantData('const <int, int>{0: 1, 2: 3}',
const { const {} :
'MapConstant(<int, int>{IntConstant(0): IntConstant(1), '
'IntConstant(2): IntConstant(3)})' }),
const ConstantData(
'const bool.fromEnvironment("foo", defaultValue: false)',
const { const {} : 'BoolConstant(false)',
const {'foo': 'true'} : 'BoolConstant(true)'}),
const ConstantData(
'const int.fromEnvironment("foo", defaultValue: 42)',
const { const {} : 'IntConstant(42)',
const {'foo': '87'} : 'IntConstant(87)'}),
const ConstantData(
'const String.fromEnvironment("foo", defaultValue: "bar")',
const { const {} : 'StringConstant("bar")',
const {'foo': 'foo'} : 'StringConstant("foo")'}),
]),
const TestData('''
const a = const bool.fromEnvironment("foo", defaultValue: true);
const b = const int.fromEnvironment("bar", defaultValue: 42);
class A {
const A();
}
class B {
final field1;
const B(this.field1);
}
class C extends B {
final field2;
const C({field1: 42, this.field2: false}) : super(field1);
const C.named([field = false]) : this(field1: field, field2: field);
}
''', const [
const ConstantData('const Object()',
const { const {} : 'ConstructedConstant(Object())' }),
const ConstantData('const A()',
const { const {} : 'ConstructedConstant(A())' }),
const ConstantData('const B(0)',
const { const {} : 'ConstructedConstant(B(field1=IntConstant(0)))' }),
const ConstantData('const B(const A())',
const { const {} :
'ConstructedConstant(B(field1=ConstructedConstant(A())))' }),
const ConstantData('const C()', const { const {} :
'ConstructedConstant(C(field1=IntConstant(42),'
'field2=BoolConstant(false)))' }),
const ConstantData('const C(field1: 87)', const { const {} :
'ConstructedConstant(C(field1=IntConstant(87),'
'field2=BoolConstant(false)))' }),
const ConstantData('const C(field2: true)', const { const {} :
'ConstructedConstant(C(field1=IntConstant(42),'
'field2=BoolConstant(true)))' }),
const ConstantData('const C.named()', const { const {} :
'ConstructedConstant(C(field1=BoolConstant(false),'
'field2=BoolConstant(false)))' }),
const ConstantData('const C.named(87)', const { const {} :
'ConstructedConstant(C(field1=IntConstant(87),'
'field2=IntConstant(87)))' }),
const ConstantData('const C(field1: a, field2: b)', const {
const {} :
'ConstructedConstant(C(field1=BoolConstant(true),'
'field2=IntConstant(42)))',
const {'foo': 'false', 'bar': '87'} :
'ConstructedConstant(C(field1=BoolConstant(false),'
'field2=IntConstant(87)))', }),
]),
const TestData('''
class A<T> implements B {
final field1;
const A({this.field1:42});
}
class B<S> implements C {
const factory B({field1}) = A<B<S>>;
const factory B.named() = A<S>;
}
class C<U> {
const factory C({field1}) = A<B<double>>;
}
''', const [
const ConstantData('const A()',
const { const {} :
'ConstructedConstant(A<dynamic>(field1=IntConstant(42)))' }),
const ConstantData('const A<int>(field1: 87)',
const { const {} :
'ConstructedConstant(A<int>(field1=IntConstant(87)))' }),
const ConstantData('const B()',
const { const {} :
'ConstructedConstant(A<B<dynamic>>(field1=IntConstant(42)))' }),
const ConstantData('const B<int>()',
const { const {} :
'ConstructedConstant(A<B<int>>(field1=IntConstant(42)))' }),
const ConstantData('const B<int>(field1: 87)',
const { const {} :
'ConstructedConstant(A<B<int>>(field1=IntConstant(87)))' }),
const ConstantData('const C<int>(field1: 87)',
const { const {} :
'ConstructedConstant(A<B<double>>(field1=IntConstant(87)))' }),
const ConstantData('const B<int>.named()',
const { const {} :
'ConstructedConstant(A<int>(field1=IntConstant(42)))' }),
]),
const TestData('''
const c = const int.fromEnvironment("foo", defaultValue: 5);
const d = const int.fromEnvironment("bar", defaultValue: 10);
class A {
final field;
const A(a, b) : field = a + b;
}
class B extends A {
const B(a) : super(a, a * 2);
}
''', const [
const ConstantData('const A(c, d)', const {
const {} :
'ConstructedConstant(A(field=IntConstant(15)))',
const {'foo': '7', 'bar': '11'} :
'ConstructedConstant(A(field=IntConstant(18)))', }),
const ConstantData('const B(d)', const {
const {} :
'ConstructedConstant(B(field=IntConstant(30)))',
const {'bar': '42'} :
'ConstructedConstant(B(field=IntConstant(126)))', }),
]),
];
main() {
asyncTest(() => Future.forEach(DATA, testData));
}
Future testData(TestData data) {
StringBuffer sb = new StringBuffer();
sb.write('${data.declarations}\n');
Map constants = {};
data.constants.forEach((ConstantData constantData) {
String name = 'c${constants.length}';
sb.write('const $name = ${constantData.code};\n');
constants[name] = constantData;
});
sb.write('main() {}\n');
String source = sb.toString();
Compiler compiler = compilerFor(
{'main.dart': source}, options: ['--analyze-all']);
return compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) {
var library = compiler.mainApp;
constants.forEach((String name, ConstantData data) {
FieldElement field = library.localLookup(name);
ConstantExpression constant = field.constant;
data.expectedValues.forEach(
(Map<String, String> env, String expectedText) {
Environment environment = new MemoryEnvironment(compiler, env);
ConstantValue value =
constant.evaluate(environment, DART_CONSTANT_SYSTEM);
String valueText = value.toStructuredString();
Expect.equals(expectedText, valueText,
"Unexpected value '${valueText}' for contant "
"`${constant.getText()}`, expected '${expectedText}'.");
});
});
});
}
// Copyright (c) 2015, 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 dart2js.constants.expressions.evaluate_test;
import 'dart:async';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'package:compiler/src/constants/expressions.dart';
import 'package:compiler/src/constants/values.dart';
import 'package:compiler/src/constant_system_dart.dart';
import 'package:compiler/src/core_types.dart';
import 'package:compiler/src/dart2jslib.dart';
import 'package:compiler/src/elements/elements.dart';
import 'memory_compiler.dart';
class TestData {
/// Declarations needed for the [constants].
final String declarations;
/// Tested constants.
final List constants;
const TestData(this.declarations, this.constants);
}
class ConstantData {
/// Source code for the constant expression.
final String code;
/// Map from environment to expected constant value as structured text.
final Map<Map<String, String>, String> expectedValues;
const ConstantData(this.code,
this.expectedValues);
}
class MemoryEnvironment implements Environment {
final Compiler compiler;
final Map<String, String> env;
MemoryEnvironment(this.compiler,
[this.env = const <String, String>{}]);
@override
String readFromEnvironment(String name) => env[name];
}
const List<TestData> DATA = const [
const TestData('', const [
const ConstantData('null', const { const {} : 'NullConstant' }),
const ConstantData('false', const { const {} : 'BoolConstant(false)' }),
const ConstantData('true', const { const {} : 'BoolConstant(true)' }),
const ConstantData('0', const { const {} : 'IntConstant(0)' }),
const ConstantData('0.0', const { const {} : 'DoubleConstant(0.0)' }),
const ConstantData('"foo"', const { const {} : 'StringConstant("foo")' }),
const ConstantData('1 + 2', const { const {} : 'IntConstant(3)' }),
const ConstantData('-(1)', const { const {} : 'IntConstant(-1)' }),
const ConstantData('"foo".length', const { const {} : 'IntConstant(3)' }),
const ConstantData('identical(0, 1)',
const { const {} : 'BoolConstant(false)' }),
const ConstantData('"a" "b"', const { const {} : 'StringConstant("ab")' }),
const ConstantData('identical',
const { const {} : 'FunctionConstant(identical)' }),
const ConstantData('true ? 0 : 1', const { const {} : 'IntConstant(0)' }),
const ConstantData('proxy',
const { const {} : 'ConstructedConstant(_Proxy())' }),
const ConstantData('Object', const { const {} : 'TypeConstant(Object)' }),
const ConstantData('const [0, 1]',
const { const {} : 'ListConstant([IntConstant(0), IntConstant(1)])' }),
const ConstantData('const <int>[0, 1]', const {
const {} : 'ListConstant(<int>[IntConstant(0), IntConstant(1)])' }),
const ConstantData('const {0: 1, 2: 3}',
const { const {} :
'MapConstant({IntConstant(0): IntConstant(1), '
'IntConstant(2): IntConstant(3)})' }),
const ConstantData('const <int, int>{0: 1, 2: 3}',
const { const {} :
'MapConstant(<int, int>{IntConstant(0): IntConstant(1), '
'IntConstant(2): IntConstant(3)})' }),
const ConstantData(
'const bool.fromEnvironment("foo", defaultValue: false)',
const { const {} : 'BoolConstant(false)',
const {'foo': 'true'} : 'BoolConstant(true)'}),
const ConstantData(
'const int.fromEnvironment("foo", defaultValue: 42)',
const { const {} : 'IntConstant(42)',
const {'foo': '87'} : 'IntConstant(87)'}),
const ConstantData(
'const String.fromEnvironment("foo", defaultValue: "bar")',
const { const {} : 'StringConstant("bar")',
const {'foo': 'foo'} : 'StringConstant("foo")'}),
]),
const TestData('''
const a = const bool.fromEnvironment("foo", defaultValue: true);
const b = const int.fromEnvironment("bar", defaultValue: 42);
class A {
const A();
}
class B {
final field1;
const B(this.field1);
}
class C extends B {
final field2;
const C({field1: 42, this.field2: false}) : super(field1);
const C.named([field = false]) : this(field1: field, field2: field);
}
''', const [
const ConstantData('const Object()',
const { const {} : 'ConstructedConstant(Object())' }),
const ConstantData('const A()',
const { const {} : 'ConstructedConstant(A())' }),
const ConstantData('const B(0)',
const { const {} : 'ConstructedConstant(B(field1=IntConstant(0)))' }),
const ConstantData('const B(const A())',
const { const {} :
'ConstructedConstant(B(field1=ConstructedConstant(A())))' }),
const ConstantData('const C()', const { const {} :
'ConstructedConstant(C(field1=IntConstant(42),'
'field2=BoolConstant(false)))' }),
const ConstantData('const C(field1: 87)', const { const {} :
'ConstructedConstant(C(field1=IntConstant(87),'
'field2=BoolConstant(false)))' }),
const ConstantData('const C(field2: true)', const { const {} :
'ConstructedConstant(C(field1=IntConstant(42),'
'field2=BoolConstant(true)))' }),
const ConstantData('const C.named()', const { const {} :
'ConstructedConstant(C(field1=BoolConstant(false),'
'field2=BoolConstant(false)))' }),
const ConstantData('const C.named(87)', const { const {} :
'ConstructedConstant(C(field1=IntConstant(87),'
'field2=IntConstant(87)))' }),
const ConstantData('const C(field1: a, field2: b)', const {
const {} :
'ConstructedConstant(C(field1=BoolConstant(true),'
'field2=IntConstant(42)))',
const {'foo': 'false', 'bar': '87'} :
'ConstructedConstant(C(field1=BoolConstant(false),'
'field2=IntConstant(87)))', }),
]),
const TestData('''
class A<T> implements B {
final field1;
const A({this.field1:42});
}
class B<S> implements C {
const factory B({field1}) = A<B<S>>;
const factory B.named() = A<S>;
}
class C<U> {
const factory C({field1}) = A<B<double>>;
}
''', const [
const ConstantData('const A()',
const { const {} :
'ConstructedConstant(A<dynamic>(field1=IntConstant(42)))' }),
const ConstantData('const A<int>(field1: 87)',
const { const {} :
'ConstructedConstant(A<int>(field1=IntConstant(87)))' }),
const ConstantData('const B()',
const { const {} :
'ConstructedConstant(A<B<dynamic>>(field1=IntConstant(42)))' }),
const ConstantData('const B<int>()',
const { const {} :
'ConstructedConstant(A<B<int>>(field1=IntConstant(42)))' }),
const ConstantData('const B<int>(field1: 87)',
const { const {} :
'ConstructedConstant(A<B<int>>(field1=IntConstant(87)))' }),
const ConstantData('const C<int>(field1: 87)',
const { const {} :
'ConstructedConstant(A<B<double>>(field1=IntConstant(87)))' }),
const ConstantData('const B<int>.named()',
const { const {} :
'ConstructedConstant(A<int>(field1=IntConstant(42)))' }),
]),
const TestData('''
const c = const int.fromEnvironment("foo", defaultValue: 5);
const d = const int.fromEnvironment("bar", defaultValue: 10);
class A {
final field;
const A(a, b) : field = a + b;
}
class B extends A {
const B(a) : super(a, a * 2);
}
''', const [
const ConstantData('const A(c, d)', const {
const {} :
'ConstructedConstant(A(field=IntConstant(15)))',
const {'foo': '7', 'bar': '11'} :
'ConstructedConstant(A(field=IntConstant(18)))', }),
const ConstantData('const B(d)', const {
const {} :
'ConstructedConstant(B(field=IntConstant(30)))',
const {'bar': '42'} :
'ConstructedConstant(B(field=IntConstant(126)))', }),
]),
];
main() {
asyncTest(() => Future.forEach(DATA, testData));
}
Future testData(TestData data) {
StringBuffer sb = new StringBuffer();
sb.write('${data.declarations}\n');
Map constants = {};
data.constants.forEach((ConstantData constantData) {
String name = 'c${constants.length}';
sb.write('const $name = ${constantData.code};\n');
constants[name] = constantData;
});
sb.write('main() {}\n');
String source = sb.toString();
Compiler compiler = compilerFor(
{'main.dart': source}, options: ['--analyze-all']);
return compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) {
var library = compiler.mainApp;
constants.forEach((String name, ConstantData data) {
FieldElement field = library.localLookup(name);
ConstantExpression constant = field.constant;
data.expectedValues.forEach(
(Map<String, String> env, String expectedText) {
Environment environment = new MemoryEnvironment(compiler, env);
ConstantValue value =
constant.evaluate(environment, DART_CONSTANT_SYSTEM);
String valueText = value.toStructuredString();
Expect.equals(expectedText, valueText,
"Unexpected value '${valueText}' for contant "
"`${constant.getText()}`, expected '${expectedText}'.");
});
});
});
}

View File

@ -1,3 +1,3 @@
void main() {
void main() {
}

View File

@ -1,110 +1,110 @@
// Copyright (c) 2014, 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.
// Checks that dart2js produces the expected static type warnings and
// compile-time errors for the provided multitests.
import 'dart:async';
import 'dart:io';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/util/uri_extras.dart'
show relativize;
import 'memory_compiler.dart';
import '../../../tools/testing/dart/multitest.dart'
show ExtractTestsFromMultitest;
import '../../../tools/testing/dart/path.dart'
show Path;
/// Check the analysis of the multitests in [testFiles] to result in the
/// expected static warnings and compile-time errors.
///
/// [testFiles] is a map of the test files to be checked together with their
/// associated white listing.
///
/// For instance if [testFiles] contain the mapping
/// 'language/async_await_syntax_test.dart': const ['a03b', 'a04b']
/// the multitests in 'language/async_await_syntax_test.dart' are checked but
/// the subtests 'a03b' and 'a04c' are expected to fail.
void check(Map<String, List<String>> testFiles,
{List<String> arguments: const <String>[],
List<String> options: const <String>[]}) {
bool outcomeMismatch = false;
bool verbose = arguments.contains('-v');
var cachedCompiler;
asyncTest(() => Future.forEach(testFiles.keys, (String testFile) {
Map<String, String> testSources = {};
Map<String, Set<String>> testOutcomes = {};
String fileName = 'tests/$testFile';
ExtractTestsFromMultitest(new Path(fileName), testSources, testOutcomes);
return Future.forEach(testSources.keys, (String testName) {
String testFileName = '$fileName/$testName';
Set<String> expectedOutcome = testOutcomes[testName];
bool expectFailure = testFiles[testFile].contains(testName);
DiagnosticCollector collector = new DiagnosticCollector();
var compiler = compilerFor(
{testFileName: testSources[testName]},
diagnosticHandler: collector,
options: ['--analyze-only']..addAll(options),
showDiagnostics: verbose,
cachedCompiler: cachedCompiler);
return compiler.run(Uri.parse('memory:$testFileName')).then((_) {
bool unexpectedResult = false;
if (expectedOutcome.contains('compile-time error')) {
if (collector.errors.isEmpty) {
print('$testFileName: Missing compile-time error.');
unexpectedResult = true;
}
} else if (expectedOutcome.contains('static type warning')) {
if (collector.warnings.isEmpty) {
print('$testFileName: Missing static type warning.');
unexpectedResult = true;
}
} else {
// Expect ok.
if (!collector.errors.isEmpty ||
!collector.warnings.isEmpty) {
collector.errors.forEach((message) {
print('$testFileName: Unexpected error: ${message.message}');
});
collector.warnings.forEach((message) {
print('$testFileName: Unexpected warning: ${message.message}');
});
unexpectedResult = true;
}
}
if (expectFailure) {
if (unexpectedResult) {
unexpectedResult = false;
} else {
print('$testFileName: The test is white-listed '
'and therefore expected to fail.');
unexpectedResult = true;
}
}
if (unexpectedResult) {
outcomeMismatch = true;
}
cachedCompiler = compiler;
});
});
}).then((_) {
if (outcomeMismatch) {
String testFileName =
relativize(Uri.base, Platform.script, Platform.isWindows);
print('''
===
=== ERROR: Unexpected result of analysis.
===
=== Please update the white-listing in $testFileName
===
''');
exit(1);
}
}));
}
// Copyright (c) 2014, 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.
// Checks that dart2js produces the expected static type warnings and
// compile-time errors for the provided multitests.
import 'dart:async';
import 'dart:io';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/util/uri_extras.dart'
show relativize;
import 'memory_compiler.dart';
import '../../../tools/testing/dart/multitest.dart'
show ExtractTestsFromMultitest;
import '../../../tools/testing/dart/path.dart'
show Path;
/// Check the analysis of the multitests in [testFiles] to result in the
/// expected static warnings and compile-time errors.
///
/// [testFiles] is a map of the test files to be checked together with their
/// associated white listing.
///
/// For instance if [testFiles] contain the mapping
/// 'language/async_await_syntax_test.dart': const ['a03b', 'a04b']
/// the multitests in 'language/async_await_syntax_test.dart' are checked but
/// the subtests 'a03b' and 'a04c' are expected to fail.
void check(Map<String, List<String>> testFiles,
{List<String> arguments: const <String>[],
List<String> options: const <String>[]}) {
bool outcomeMismatch = false;
bool verbose = arguments.contains('-v');
var cachedCompiler;
asyncTest(() => Future.forEach(testFiles.keys, (String testFile) {
Map<String, String> testSources = {};
Map<String, Set<String>> testOutcomes = {};
String fileName = 'tests/$testFile';
ExtractTestsFromMultitest(new Path(fileName), testSources, testOutcomes);
return Future.forEach(testSources.keys, (String testName) {
String testFileName = '$fileName/$testName';
Set<String> expectedOutcome = testOutcomes[testName];
bool expectFailure = testFiles[testFile].contains(testName);
DiagnosticCollector collector = new DiagnosticCollector();
var compiler = compilerFor(
{testFileName: testSources[testName]},
diagnosticHandler: collector,
options: ['--analyze-only']..addAll(options),
showDiagnostics: verbose,
cachedCompiler: cachedCompiler);
return compiler.run(Uri.parse('memory:$testFileName')).then((_) {
bool unexpectedResult = false;
if (expectedOutcome.contains('compile-time error')) {
if (collector.errors.isEmpty) {
print('$testFileName: Missing compile-time error.');
unexpectedResult = true;
}
} else if (expectedOutcome.contains('static type warning')) {
if (collector.warnings.isEmpty) {
print('$testFileName: Missing static type warning.');
unexpectedResult = true;
}
} else {
// Expect ok.
if (!collector.errors.isEmpty ||
!collector.warnings.isEmpty) {
collector.errors.forEach((message) {
print('$testFileName: Unexpected error: ${message.message}');
});
collector.warnings.forEach((message) {
print('$testFileName: Unexpected warning: ${message.message}');
});
unexpectedResult = true;
}
}
if (expectFailure) {
if (unexpectedResult) {
unexpectedResult = false;
} else {
print('$testFileName: The test is white-listed '
'and therefore expected to fail.');
unexpectedResult = true;
}
}
if (unexpectedResult) {
outcomeMismatch = true;
}
cachedCompiler = compiler;
});
});
}).then((_) {
if (outcomeMismatch) {
String testFileName =
relativize(Uri.base, Platform.script, Platform.isWindows);
print('''
===
=== ERROR: Unexpected result of analysis.
===
=== Please update the white-listing in $testFileName
===
''');
exit(1);
}
}));
}

View File

@ -1,413 +1,413 @@
// Copyright (c) 2014, 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.
// Test that the compiler emits a warning on import of 'dart:mirrors' unless
// the flag --enable-experimental-mirrors is used.
library dart2js.test.import;
import 'dart:async';
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/dart2jslib.dart' show MessageKind;
import 'memory_compiler.dart';
const DIRECT_IMPORT = const {
'/main.dart': '''
import 'dart:mirrors';
main() {}
''',
'paths':
"main.dart => dart:mirrors",
};
const INDIRECT_IMPORT1 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => dart:mirrors",
};
const INDIRECT_IMPORT2 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'second.dart';
''',
'/second.dart': '''
import 'dart:mirrors';
''',
'paths':
"second.dart => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => second.dart => dart:mirrors",
};
const INDIRECT_PACKAGE_IMPORT1 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:second/second.dart';
''',
'/pkg/second/second.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => package:second => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:second/second.dart => dart:mirrors",
};
const INDIRECT_PACKAGE_IMPORT2 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:packagename/second.dart';
''',
'/pkg/packagename/second.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => package:packagename => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:packagename/second.dart "
"=> dart:mirrors",
};
const INDIRECT_PACKAGE_IMPORT3 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:package1/second.dart';
''',
'/pkg/package1/second.dart': '''
import 'package:package2/third.dart';
''',
'/pkg/package2/third.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => package:package1 => package:package2 => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:package1/second.dart "
"=> package:package2/third.dart => dart:mirrors",
};
const INDIRECT_PACKAGE_IMPORT4 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:package1/second.dart';
''',
'/pkg/package1/second.dart': '''
import 'sub/third.dart';
''',
'/pkg/package1/sub/third.dart': '''
import 'package:package2/fourth.dart';
''',
'/pkg/package2/fourth.dart': '''
import 'lib/src/fifth.dart';
''',
'/pkg/package2/lib/src/fifth.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => package:package1 => package:package2 => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:package1/second.dart "
"=> package:package1/sub/third.dart => package:package2/fourth.dart "
"=> package:package2/lib/src/fifth.dart => dart:mirrors",
};
const DUAL_DIRECT_IMPORT = const {
'/main.dart': '''
import 'dart:mirrors';
import 'dart:mirrors';
main() {}
''',
'paths':
"main.dart => dart:mirrors",
};
const DUAL_INDIRECT_IMPORT1 = const {
'/main.dart': '''
import 'dart:mirrors';
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'dart:mirrors';
''',
'paths': const
["main.dart => dart:mirrors",
"first.dart => dart:mirrors"],
'verbosePaths': const
["main.dart => dart:mirrors",
"main.dart => first.dart => dart:mirrors"],
};
const DUAL_INDIRECT_IMPORT2 = const {
'/main.dart': '''
import 'first.dart';
import 'second.dart';
main() {}
''',
'/first.dart': '''
import 'dart:mirrors';
''',
'/second.dart': '''
import 'dart:mirrors';
''',
'paths': const
["first.dart => dart:mirrors",
"second.dart => dart:mirrors"],
'verbosePaths': const
["main.dart => first.dart => dart:mirrors",
"main.dart => second.dart => dart:mirrors"],
};
const DUAL_INDIRECT_IMPORT3 = const {
'/main.dart': '''
import 'first.dart';
import 'second.dart';
main() {}
''',
'/first.dart': '''
import 'third.dart';
''',
'/second.dart': '''
import 'third.dart';
''',
'/third.dart': '''
import 'dart:mirrors';
''',
'paths':
"third.dart => dart:mirrors",
'verbosePaths': const
["main.dart => first.dart => third.dart => dart:mirrors",
"main.dart => second.dart => third.dart => dart:mirrors"],
};
const DUAL_INDIRECT_PACKAGE_IMPORT1 = const {
'/main.dart': '''
import 'package:package1/second.dart';
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:package2/third.dart';
''',
'/pkg/package1/second.dart': '''
import 'dart:mirrors';
''',
'/pkg/package2/third.dart': '''
import 'dart:mirrors';
''',
'paths': const
["main.dart => package:package1 => dart:mirrors",
"first.dart => package:package2 => dart:mirrors"],
'verbosePaths': const
["main.dart => package:package1/second.dart => dart:mirrors",
"main.dart => first.dart => package:package2/third.dart => dart:mirrors"]
};
const DIRECT_EXPORT = const {
'/main.dart': '''
export 'dart:mirrors';
main() {}
''',
'paths':
"main.dart => dart:mirrors",
};
const INDIRECT_EXPORT1 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
export 'dart:mirrors';
''',
'paths':
"first.dart => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => dart:mirrors",
};
const INDIRECT_EXPORT2 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'second.dart';
''',
'/second.dart': '''
export 'dart:mirrors';
''',
'paths':
"second.dart => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => second.dart => dart:mirrors",
};
const INDIRECT_PACKAGE_EXPORT1 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:packagename/second.dart';
''',
'/pkg/packagename/second.dart': '''
export 'dart:mirrors';
''',
'paths':
"first.dart => package:packagename => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:packagename/second.dart "
"=> dart:mirrors",
};
const INDIRECT_PACKAGE_EXPORT2 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
export 'package:packagename/second.dart';
''',
'/pkg/packagename/second.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => package:packagename => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:packagename/second.dart "
"=> dart:mirrors",
};
Future test(Map sourceFiles,
{expectedPaths,
bool verbose: false,
bool enableExperimentalMirrors: false}) {
if (expectedPaths is! List) {
expectedPaths = [expectedPaths];
}
var collector = new DiagnosticCollector();
var options = [];
if (verbose) {
options.add('--verbose');
}
if (enableExperimentalMirrors) {
options.add('--enable-experimental-mirrors');
}
var compiler = compilerFor(sourceFiles, diagnosticHandler: collector,
packageRoot: Uri.parse('memory:/pkg/'),
options: options);
return compiler.run(Uri.parse('memory:/main.dart')).then((_) {
Expect.equals(0, collector.errors.length, 'Errors: ${collector.errors}');
if (enableExperimentalMirrors) {
Expect.equals(0, collector.warnings.length,
'Warnings: ${collector.errors}');
} else {
Expect.equals(1, collector.warnings.length,
'Warnings: ${collector.errors}');
Expect.equals(
MessageKind.IMPORT_EXPERIMENTAL_MIRRORS.message(
{'importChain': expectedPaths.join(
MessageKind.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}).toString(),
collector.warnings.first.message);
}
});
}
Future checkPaths(Map sourceData) {
Map sourceFiles = sourceData;
var expectedPaths = sourceData['paths'];
var expectedVerbosePaths = sourceData['verbosePaths'];
if (expectedVerbosePaths == null) {
expectedVerbosePaths = expectedPaths;
}
return test(sourceFiles, expectedPaths: expectedPaths).then((_) {
return test(
sourceFiles, expectedPaths: expectedVerbosePaths, verbose: true);
}).then((_) {
return test(sourceFiles, enableExperimentalMirrors: true);
});
}
void main() {
asyncTest(() => Future.forEach([
DIRECT_IMPORT,
INDIRECT_IMPORT1,
INDIRECT_IMPORT2,
INDIRECT_PACKAGE_IMPORT1,
INDIRECT_PACKAGE_IMPORT2,
INDIRECT_PACKAGE_IMPORT3,
INDIRECT_PACKAGE_IMPORT4,
DUAL_DIRECT_IMPORT,
DUAL_INDIRECT_IMPORT1,
DUAL_INDIRECT_IMPORT2,
DUAL_INDIRECT_IMPORT3,
DUAL_INDIRECT_PACKAGE_IMPORT1,
DIRECT_EXPORT,
INDIRECT_EXPORT1,
INDIRECT_EXPORT2,
INDIRECT_PACKAGE_EXPORT1,
INDIRECT_PACKAGE_EXPORT2],
(map) => checkPaths(map)
));
}
// Copyright (c) 2014, 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.
// Test that the compiler emits a warning on import of 'dart:mirrors' unless
// the flag --enable-experimental-mirrors is used.
library dart2js.test.import;
import 'dart:async';
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/dart2jslib.dart' show MessageKind;
import 'memory_compiler.dart';
const DIRECT_IMPORT = const {
'/main.dart': '''
import 'dart:mirrors';
main() {}
''',
'paths':
"main.dart => dart:mirrors",
};
const INDIRECT_IMPORT1 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => dart:mirrors",
};
const INDIRECT_IMPORT2 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'second.dart';
''',
'/second.dart': '''
import 'dart:mirrors';
''',
'paths':
"second.dart => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => second.dart => dart:mirrors",
};
const INDIRECT_PACKAGE_IMPORT1 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:second/second.dart';
''',
'/pkg/second/second.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => package:second => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:second/second.dart => dart:mirrors",
};
const INDIRECT_PACKAGE_IMPORT2 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:packagename/second.dart';
''',
'/pkg/packagename/second.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => package:packagename => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:packagename/second.dart "
"=> dart:mirrors",
};
const INDIRECT_PACKAGE_IMPORT3 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:package1/second.dart';
''',
'/pkg/package1/second.dart': '''
import 'package:package2/third.dart';
''',
'/pkg/package2/third.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => package:package1 => package:package2 => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:package1/second.dart "
"=> package:package2/third.dart => dart:mirrors",
};
const INDIRECT_PACKAGE_IMPORT4 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:package1/second.dart';
''',
'/pkg/package1/second.dart': '''
import 'sub/third.dart';
''',
'/pkg/package1/sub/third.dart': '''
import 'package:package2/fourth.dart';
''',
'/pkg/package2/fourth.dart': '''
import 'lib/src/fifth.dart';
''',
'/pkg/package2/lib/src/fifth.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => package:package1 => package:package2 => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:package1/second.dart "
"=> package:package1/sub/third.dart => package:package2/fourth.dart "
"=> package:package2/lib/src/fifth.dart => dart:mirrors",
};
const DUAL_DIRECT_IMPORT = const {
'/main.dart': '''
import 'dart:mirrors';
import 'dart:mirrors';
main() {}
''',
'paths':
"main.dart => dart:mirrors",
};
const DUAL_INDIRECT_IMPORT1 = const {
'/main.dart': '''
import 'dart:mirrors';
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'dart:mirrors';
''',
'paths': const
["main.dart => dart:mirrors",
"first.dart => dart:mirrors"],
'verbosePaths': const
["main.dart => dart:mirrors",
"main.dart => first.dart => dart:mirrors"],
};
const DUAL_INDIRECT_IMPORT2 = const {
'/main.dart': '''
import 'first.dart';
import 'second.dart';
main() {}
''',
'/first.dart': '''
import 'dart:mirrors';
''',
'/second.dart': '''
import 'dart:mirrors';
''',
'paths': const
["first.dart => dart:mirrors",
"second.dart => dart:mirrors"],
'verbosePaths': const
["main.dart => first.dart => dart:mirrors",
"main.dart => second.dart => dart:mirrors"],
};
const DUAL_INDIRECT_IMPORT3 = const {
'/main.dart': '''
import 'first.dart';
import 'second.dart';
main() {}
''',
'/first.dart': '''
import 'third.dart';
''',
'/second.dart': '''
import 'third.dart';
''',
'/third.dart': '''
import 'dart:mirrors';
''',
'paths':
"third.dart => dart:mirrors",
'verbosePaths': const
["main.dart => first.dart => third.dart => dart:mirrors",
"main.dart => second.dart => third.dart => dart:mirrors"],
};
const DUAL_INDIRECT_PACKAGE_IMPORT1 = const {
'/main.dart': '''
import 'package:package1/second.dart';
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:package2/third.dart';
''',
'/pkg/package1/second.dart': '''
import 'dart:mirrors';
''',
'/pkg/package2/third.dart': '''
import 'dart:mirrors';
''',
'paths': const
["main.dart => package:package1 => dart:mirrors",
"first.dart => package:package2 => dart:mirrors"],
'verbosePaths': const
["main.dart => package:package1/second.dart => dart:mirrors",
"main.dart => first.dart => package:package2/third.dart => dart:mirrors"]
};
const DIRECT_EXPORT = const {
'/main.dart': '''
export 'dart:mirrors';
main() {}
''',
'paths':
"main.dart => dart:mirrors",
};
const INDIRECT_EXPORT1 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
export 'dart:mirrors';
''',
'paths':
"first.dart => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => dart:mirrors",
};
const INDIRECT_EXPORT2 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'second.dart';
''',
'/second.dart': '''
export 'dart:mirrors';
''',
'paths':
"second.dart => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => second.dart => dart:mirrors",
};
const INDIRECT_PACKAGE_EXPORT1 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
import 'package:packagename/second.dart';
''',
'/pkg/packagename/second.dart': '''
export 'dart:mirrors';
''',
'paths':
"first.dart => package:packagename => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:packagename/second.dart "
"=> dart:mirrors",
};
const INDIRECT_PACKAGE_EXPORT2 = const {
'/main.dart': '''
import 'first.dart';
main() {}
''',
'/first.dart': '''
export 'package:packagename/second.dart';
''',
'/pkg/packagename/second.dart': '''
import 'dart:mirrors';
''',
'paths':
"first.dart => package:packagename => dart:mirrors",
'verbosePaths':
"main.dart => first.dart => package:packagename/second.dart "
"=> dart:mirrors",
};
Future test(Map sourceFiles,
{expectedPaths,
bool verbose: false,
bool enableExperimentalMirrors: false}) {
if (expectedPaths is! List) {
expectedPaths = [expectedPaths];
}
var collector = new DiagnosticCollector();
var options = [];
if (verbose) {
options.add('--verbose');
}
if (enableExperimentalMirrors) {
options.add('--enable-experimental-mirrors');
}
var compiler = compilerFor(sourceFiles, diagnosticHandler: collector,
packageRoot: Uri.parse('memory:/pkg/'),
options: options);
return compiler.run(Uri.parse('memory:/main.dart')).then((_) {
Expect.equals(0, collector.errors.length, 'Errors: ${collector.errors}');
if (enableExperimentalMirrors) {
Expect.equals(0, collector.warnings.length,
'Warnings: ${collector.errors}');
} else {
Expect.equals(1, collector.warnings.length,
'Warnings: ${collector.errors}');
Expect.equals(
MessageKind.IMPORT_EXPERIMENTAL_MIRRORS.message(
{'importChain': expectedPaths.join(
MessageKind.IMPORT_EXPERIMENTAL_MIRRORS_PADDING)}).toString(),
collector.warnings.first.message);
}
});
}
Future checkPaths(Map sourceData) {
Map sourceFiles = sourceData;
var expectedPaths = sourceData['paths'];
var expectedVerbosePaths = sourceData['verbosePaths'];
if (expectedVerbosePaths == null) {
expectedVerbosePaths = expectedPaths;
}
return test(sourceFiles, expectedPaths: expectedPaths).then((_) {
return test(
sourceFiles, expectedPaths: expectedVerbosePaths, verbose: true);
}).then((_) {
return test(sourceFiles, enableExperimentalMirrors: true);
});
}
void main() {
asyncTest(() => Future.forEach([
DIRECT_IMPORT,
INDIRECT_IMPORT1,
INDIRECT_IMPORT2,
INDIRECT_PACKAGE_IMPORT1,
INDIRECT_PACKAGE_IMPORT2,
INDIRECT_PACKAGE_IMPORT3,
INDIRECT_PACKAGE_IMPORT4,
DUAL_DIRECT_IMPORT,
DUAL_INDIRECT_IMPORT1,
DUAL_INDIRECT_IMPORT2,
DUAL_INDIRECT_IMPORT3,
DUAL_INDIRECT_PACKAGE_IMPORT1,
DIRECT_EXPORT,
INDIRECT_EXPORT1,
INDIRECT_EXPORT2,
INDIRECT_PACKAGE_EXPORT1,
INDIRECT_PACKAGE_EXPORT2],
(map) => checkPaths(map)
));
}

View File

@ -1,85 +1,85 @@
// Copyright (c) 2014, 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 instantiated_classes_test;
import 'dart:async';
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/elements/elements.dart'
show ClassElement;
import 'type_test_helper.dart';
void main() {
asyncTest(() => Future.forEach([
() => test("class Class {}", ["Class"]),
() => test("""abstract class A {}
class Class extends A {}""",
["Class"]),
() => test("""class A {}
class Class extends A {}""",
["Class"]),
() => test("""class A {}
class B {}
class Class extends A {}""",
["Class"]),
() => test("""class A {}
class Class implements A {}""",
["Class"]),
() => test("""class A {}
class Class extends Object with A {}""",
["Class"]),
() => test("""class A {}
class B {}
class Class extends Object with B implements A {}""",
["Class"]),
() => test("""class A {}
class Class {}""",
["Class", "A"], ["Class", "A"]),
() => test("""class A {}
class Class extends A {}""",
["Class", "A"], ["Class", "A"]),
() => test("""class A {}
class Class implements A {}""",
["Class", "A"], ["Class", "A"]),
() => test("""class A {}
class B extends A {}
class Class extends B {}""",
["Class", "A"], ["Class", "A"]),
() => test("""class A {}
class B {}
class Class extends B with A {}""",
["Class", "A"], ["Class", "A"]),
// TODO(johnniwinther): Avoid registration of `Class` as instantiated.
() => test("""class A {}
class Class implements A {
factory Class() = A;
}""",
["Class", "A"], ["Class"]),
], (f) => f()));
}
Future test(String source, List<String> directlyInstantiatedClasses,
[List<String> newClasses = const <String>["Class"]]) {
StringBuffer mainSource = new StringBuffer();
mainSource.write('main() {\n');
for (String newClass in newClasses) {
mainSource.write(' new $newClass();\n');
}
mainSource.write('}');
return TypeEnvironment.create(source,
mainSource: mainSource.toString(),
useMockCompiler: true).then((env) {
Iterable<ClassElement> expectedClasses =
directlyInstantiatedClasses.map(env.getElement);
Iterable<ClassElement> actualClasses =
env.compiler.resolverWorld.directlyInstantiatedClasses.where(
(c) => c.library == env.compiler.mainApp);
Expect.setEquals(expectedClasses, actualClasses);
});
}
// Copyright (c) 2014, 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 instantiated_classes_test;
import 'dart:async';
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/elements/elements.dart'
show ClassElement;
import 'type_test_helper.dart';
void main() {
asyncTest(() => Future.forEach([
() => test("class Class {}", ["Class"]),
() => test("""abstract class A {}
class Class extends A {}""",
["Class"]),
() => test("""class A {}
class Class extends A {}""",
["Class"]),
() => test("""class A {}
class B {}
class Class extends A {}""",
["Class"]),
() => test("""class A {}
class Class implements A {}""",
["Class"]),
() => test("""class A {}
class Class extends Object with A {}""",
["Class"]),
() => test("""class A {}
class B {}
class Class extends Object with B implements A {}""",
["Class"]),
() => test("""class A {}
class Class {}""",
["Class", "A"], ["Class", "A"]),
() => test("""class A {}
class Class extends A {}""",
["Class", "A"], ["Class", "A"]),
() => test("""class A {}
class Class implements A {}""",
["Class", "A"], ["Class", "A"]),
() => test("""class A {}
class B extends A {}
class Class extends B {}""",
["Class", "A"], ["Class", "A"]),
() => test("""class A {}
class B {}
class Class extends B with A {}""",
["Class", "A"], ["Class", "A"]),
// TODO(johnniwinther): Avoid registration of `Class` as instantiated.
() => test("""class A {}
class Class implements A {
factory Class() = A;
}""",
["Class", "A"], ["Class"]),
], (f) => f()));
}
Future test(String source, List<String> directlyInstantiatedClasses,
[List<String> newClasses = const <String>["Class"]]) {
StringBuffer mainSource = new StringBuffer();
mainSource.write('main() {\n');
for (String newClass in newClasses) {
mainSource.write(' new $newClass();\n');
}
mainSource.write('}');
return TypeEnvironment.create(source,
mainSource: mainSource.toString(),
useMockCompiler: true).then((env) {
Iterable<ClassElement> expectedClasses =
directlyInstantiatedClasses.map(env.getElement);
Iterable<ClassElement> actualClasses =
env.compiler.resolverWorld.directlyInstantiatedClasses.where(
(c) => c.library == env.compiler.mainApp);
Expect.setEquals(expectedClasses, actualClasses);
});
}

View File

@ -1,22 +1,22 @@
// 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.
// Test that dart2js produces the expected static type warnings for least upper
// bound language tests. This ensures that the analyzer and dart2js agrees
// on these tests.
import 'warnings_checker.dart';
/// Map from test files to a map of their expected status. If the status map is
/// `null` no warnings must be missing or unexpected, otherwise the status map
/// can contain a list of line numbers for keys 'missing' and 'unexpected' for
/// the warnings of each category.
const Map<String, dynamic> TESTS = const {
'language/least_upper_bound_test.dart': null,
'language/least_upper_bound_expansive_test.dart': null,
};
void main() {
checkWarnings(TESTS);
}
// 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.
// Test that dart2js produces the expected static type warnings for least upper
// bound language tests. This ensures that the analyzer and dart2js agrees
// on these tests.
import 'warnings_checker.dart';
/// Map from test files to a map of their expected status. If the status map is
/// `null` no warnings must be missing or unexpected, otherwise the status map
/// can contain a list of line numbers for keys 'missing' and 'unexpected' for
/// the warnings of each category.
const Map<String, dynamic> TESTS = const {
'language/least_upper_bound_test.dart': null,
'language/least_upper_bound_expansive_test.dart': null,
};
void main() {
checkWarnings(TESTS);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,84 +1,84 @@
// Copyright (c) 2015, 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.
// Unittest for the [LineColumnCollector].
import 'package:expect/expect.dart';
import 'package:compiler/src/io/code_output.dart';
import 'package:compiler/src/io/line_column_provider.dart';
import 'output_collector.dart';
test(List events, Map<int, List<int>> expectedPositions) {
BufferedEventSink sink = new BufferedEventSink();
LineColumnProvider lineColumnProvider = new LineColumnCollector();
CodeOutput output = new StreamCodeOutput(sink, [lineColumnProvider]);
for (var event in events) {
if (event is String) {
output.add(event);
} else if (event is CodeBuffer) {
output.addBuffer(event);
}
}
output.close();
expectedPositions.forEach((int offset, List<int> expectedPosition) {
if (expectedPosition == null) {
Expect.throws(() => lineColumnProvider.getLine(offset),
(e) => true,
'Expected out-of-bounds offset: $offset\n'
'text:"""${sink.text}"""\n'
'lineColumnProvider:$lineColumnProvider');
} else {
int line = lineColumnProvider.getLine(offset);
int column = lineColumnProvider.getColumn(line, offset);
Expect.equals(expectedPosition[0], line,
'Unexpected result: $offset -> $expectedPosition = [$line,$column]\n'
'text:"""${sink.text}"""\n'
'lineColumnProvider:$lineColumnProvider');
Expect.equals(expectedPosition[1], column,
'Unexpected result: $offset -> $expectedPosition = [$line,$column]\n'
'text:"""${sink.text}"""\n'
'lineColumnProvider:$lineColumnProvider');
}
});
}
main() {
test([""], {0: [0, 0], 1: null});
test([" "], {0: [0, 0], 1: [0, 1], 2: null});
test(["\n "], {0: [0, 0], 1: [1, 0], 2: [1, 1], 3: null});
Map positions = {0: [0, 0],
1: [0, 1],
2: [1, 0],
3: [1, 1],
4: [2, 0],
5: [2, 1],
6: null};
test(["a\nb\nc"], positions);
test(["a", "\nb\nc"], positions);
test(["a", "\n", "b\nc"], positions);
CodeBuffer buffer1 = new CodeBuffer();
buffer1.add("a\nb\nc");
test([buffer1], positions);
CodeBuffer buffer2 = new CodeBuffer();
buffer2.add("\nb\nc");
test(["a", buffer2], positions);
CodeBuffer buffer3 = new CodeBuffer();
buffer3.add("a");
test([buffer3, buffer2], positions);
CodeBuffer buffer4 = new CodeBuffer();
buffer4.addBuffer(buffer3);
test([buffer4, buffer2], positions);
}
// Copyright (c) 2015, 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.
// Unittest for the [LineColumnCollector].
import 'package:expect/expect.dart';
import 'package:compiler/src/io/code_output.dart';
import 'package:compiler/src/io/line_column_provider.dart';
import 'output_collector.dart';
test(List events, Map<int, List<int>> expectedPositions) {
BufferedEventSink sink = new BufferedEventSink();
LineColumnProvider lineColumnProvider = new LineColumnCollector();
CodeOutput output = new StreamCodeOutput(sink, [lineColumnProvider]);
for (var event in events) {
if (event is String) {
output.add(event);
} else if (event is CodeBuffer) {
output.addBuffer(event);
}
}
output.close();
expectedPositions.forEach((int offset, List<int> expectedPosition) {
if (expectedPosition == null) {
Expect.throws(() => lineColumnProvider.getLine(offset),
(e) => true,
'Expected out-of-bounds offset: $offset\n'
'text:"""${sink.text}"""\n'
'lineColumnProvider:$lineColumnProvider');
} else {
int line = lineColumnProvider.getLine(offset);
int column = lineColumnProvider.getColumn(line, offset);
Expect.equals(expectedPosition[0], line,
'Unexpected result: $offset -> $expectedPosition = [$line,$column]\n'
'text:"""${sink.text}"""\n'
'lineColumnProvider:$lineColumnProvider');
Expect.equals(expectedPosition[1], column,
'Unexpected result: $offset -> $expectedPosition = [$line,$column]\n'
'text:"""${sink.text}"""\n'
'lineColumnProvider:$lineColumnProvider');
}
});
}
main() {
test([""], {0: [0, 0], 1: null});
test([" "], {0: [0, 0], 1: [0, 1], 2: null});
test(["\n "], {0: [0, 0], 1: [1, 0], 2: [1, 1], 3: null});
Map positions = {0: [0, 0],
1: [0, 1],
2: [1, 0],
3: [1, 1],
4: [2, 0],
5: [2, 1],
6: null};
test(["a\nb\nc"], positions);
test(["a", "\nb\nc"], positions);
test(["a", "\n", "b\nc"], positions);
CodeBuffer buffer1 = new CodeBuffer();
buffer1.add("a\nb\nc");
test([buffer1], positions);
CodeBuffer buffer2 = new CodeBuffer();
buffer2.add("\nb\nc");
test(["a", buffer2], positions);
CodeBuffer buffer3 = new CodeBuffer();
buffer3.add("a");
test([buffer3, buffer2], positions);
CodeBuffer buffer4 = new CodeBuffer();
buffer4.addBuffer(buffer3);
test([buffer4, buffer2], positions);
}

View File

@ -1,139 +1,139 @@
// 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 mirror_system_helper;
import 'dart:async';
import 'package:compiler/src/mirrors/source_mirrors.dart';
import 'package:compiler/src/mirrors/dart2js_mirrors.dart';
import 'mock_compiler.dart';
export 'package:compiler/src/mirrors/source_mirrors.dart';
export 'package:compiler/src/mirrors/mirrors_util.dart';
const String SOURCE = 'source';
final Uri SOURCE_URI = new Uri(scheme: SOURCE, path: SOURCE);
// TODO(johnniwinther): Move this to a mirrors helper library.
Future<MirrorSystem> createMirrorSystem(String source) {
MockCompiler compiler = new MockCompiler.internal(
analyzeOnly: true,
analyzeAll: true,
preserveComments: true);
compiler.registerSource(SOURCE_URI, source);
compiler.librariesToAnalyzeWhenRun = <Uri>[SOURCE_URI];
return compiler.runCompiler(null).then((_) {
return new Dart2JsMirrorSystem(compiler);
});
}
/**
* Returns [:true:] if [type] is an instance of [:decl:] with type arguments
* equal to [typeArgument].
*/
bool isInstance(ClassMirror decl, List<TypeMirror> typeArguments,
ClassMirror type) {
if (type.isOriginalDeclaration) return false;
if (!isSameDeclaration(decl, type)) return false;
return areEqualsTypes(typeArguments, type.typeArguments);
}
/**
* Returns [:true:] if [type] is the same type as [expected]. This method
* equates a non-generic declaration with its instantiation.
*/
bool isEqualType(TypeMirror expected, TypeMirror type) {
if (expected == type) return true;
if (expected is ClassMirror && type is ClassMirror) {
if (!isSameDeclaration(expected, type)) return false;
if (expected.isOriginalDeclaration || expected.typeArguments.isEmpty) {
return type.isOriginalDeclaration || type.typeArguments.isEmpty;
}
return areEqualsTypes(expected.typeArguments, type.typeArguments);
}
return true;
}
/**
* Returns [:true:] if [types] are equals to [expected] using the equalitry
* defined by [isEqualType].
*/
bool areEqualsTypes(List<TypeMirror> expected, List<TypeMirror> types) {
return checkSameList(expected, types, isEqualType);
}
/**
* Returns [:true:] if an instance of [type] with type arguments equal to
* [typeArguments] is found in [types].
*/
bool containsType(ClassMirror decl, List<TypeMirror> typeArguments,
Iterable<TypeMirror> types) {
return types.any((type) => isInstance(decl, typeArguments, type));
}
/**
* Returns the declaration of [type].
*/
TypeMirror toDeclaration(TypeMirror type) {
return type is ClassMirror ? type.originalDeclaration : type;
}
/**
* Returns [:true:] if [type] is of the same declaration as [expected].
*/
bool isSameDeclaration(TypeMirror expected, TypeMirror type) {
return toDeclaration(expected) == toDeclaration(type);
}
/**
* Returns [:true:] if a type of the declaration of [expected] is in [types].
*/
bool containsDeclaration(TypeMirror expected, Iterable<TypeMirror> types) {
for (var type in types) {
if (isSameDeclaration(expected, type)) {
return true;
}
}
return false;
}
/**
* Returns [:true:] if declarations of [expected] are the same as those of
* [types], taking order into account.
*/
bool isSameDeclarationList(Iterable<TypeMirror> expected,
Iterable<TypeMirror> types) {
return checkSameList(expected, types, isSameDeclaration);
}
/**
* Returns [:true:] if declarations of [expected] are the same as those of
* [iterable], not taking order into account.
*/
bool isSameDeclarationSet(Iterable<TypeMirror> expected,
Iterable<TypeMirror> types) {
Set<TypeMirror> expectedSet = expected.map(toDeclaration).toSet();
Set<TypeMirror> typesSet = types.map(toDeclaration).toSet();
return expectedSet.length == typesSet.length &&
expectedSet.containsAll(typesSet);
}
/**
* Utility method for checking whether [expected] and [iterable] contains the
* same elements with respect to the checking function [check], takin order
* into account.
*/
bool checkSameList(Iterable<TypeMirror> expected,
Iterable<TypeMirror> types,
bool check(TypeMirror a, TypeMirror b)) {
if (expected.length != types.length) return false;
Iterator<TypeMirror> expectedIterator = expected.iterator;
Iterator<TypeMirror> typesIterator = types.iterator;
while (expectedIterator.moveNext() && typesIterator.moveNext()) {
if (!check(expectedIterator.current, typesIterator.current)) {
return false;
}
}
return true;
}
// 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 mirror_system_helper;
import 'dart:async';
import 'package:compiler/src/mirrors/source_mirrors.dart';
import 'package:compiler/src/mirrors/dart2js_mirrors.dart';
import 'mock_compiler.dart';
export 'package:compiler/src/mirrors/source_mirrors.dart';
export 'package:compiler/src/mirrors/mirrors_util.dart';
const String SOURCE = 'source';
final Uri SOURCE_URI = new Uri(scheme: SOURCE, path: SOURCE);
// TODO(johnniwinther): Move this to a mirrors helper library.
Future<MirrorSystem> createMirrorSystem(String source) {
MockCompiler compiler = new MockCompiler.internal(
analyzeOnly: true,
analyzeAll: true,
preserveComments: true);
compiler.registerSource(SOURCE_URI, source);
compiler.librariesToAnalyzeWhenRun = <Uri>[SOURCE_URI];
return compiler.runCompiler(null).then((_) {
return new Dart2JsMirrorSystem(compiler);
});
}
/**
* Returns [:true:] if [type] is an instance of [:decl:] with type arguments
* equal to [typeArgument].
*/
bool isInstance(ClassMirror decl, List<TypeMirror> typeArguments,
ClassMirror type) {
if (type.isOriginalDeclaration) return false;
if (!isSameDeclaration(decl, type)) return false;
return areEqualsTypes(typeArguments, type.typeArguments);
}
/**
* Returns [:true:] if [type] is the same type as [expected]. This method
* equates a non-generic declaration with its instantiation.
*/
bool isEqualType(TypeMirror expected, TypeMirror type) {
if (expected == type) return true;
if (expected is ClassMirror && type is ClassMirror) {
if (!isSameDeclaration(expected, type)) return false;
if (expected.isOriginalDeclaration || expected.typeArguments.isEmpty) {
return type.isOriginalDeclaration || type.typeArguments.isEmpty;
}
return areEqualsTypes(expected.typeArguments, type.typeArguments);
}
return true;
}
/**
* Returns [:true:] if [types] are equals to [expected] using the equalitry
* defined by [isEqualType].
*/
bool areEqualsTypes(List<TypeMirror> expected, List<TypeMirror> types) {
return checkSameList(expected, types, isEqualType);
}
/**
* Returns [:true:] if an instance of [type] with type arguments equal to
* [typeArguments] is found in [types].
*/
bool containsType(ClassMirror decl, List<TypeMirror> typeArguments,
Iterable<TypeMirror> types) {
return types.any((type) => isInstance(decl, typeArguments, type));
}
/**
* Returns the declaration of [type].
*/
TypeMirror toDeclaration(TypeMirror type) {
return type is ClassMirror ? type.originalDeclaration : type;
}
/**
* Returns [:true:] if [type] is of the same declaration as [expected].
*/
bool isSameDeclaration(TypeMirror expected, TypeMirror type) {
return toDeclaration(expected) == toDeclaration(type);
}
/**
* Returns [:true:] if a type of the declaration of [expected] is in [types].
*/
bool containsDeclaration(TypeMirror expected, Iterable<TypeMirror> types) {
for (var type in types) {
if (isSameDeclaration(expected, type)) {
return true;
}
}
return false;
}
/**
* Returns [:true:] if declarations of [expected] are the same as those of
* [types], taking order into account.
*/
bool isSameDeclarationList(Iterable<TypeMirror> expected,
Iterable<TypeMirror> types) {
return checkSameList(expected, types, isSameDeclaration);
}
/**
* Returns [:true:] if declarations of [expected] are the same as those of
* [iterable], not taking order into account.
*/
bool isSameDeclarationSet(Iterable<TypeMirror> expected,
Iterable<TypeMirror> types) {
Set<TypeMirror> expectedSet = expected.map(toDeclaration).toSet();
Set<TypeMirror> typesSet = types.map(toDeclaration).toSet();
return expectedSet.length == typesSet.length &&
expectedSet.containsAll(typesSet);
}
/**
* Utility method for checking whether [expected] and [iterable] contains the
* same elements with respect to the checking function [check], takin order
* into account.
*/
bool checkSameList(Iterable<TypeMirror> expected,
Iterable<TypeMirror> types,
bool check(TypeMirror a, TypeMirror b)) {
if (expected.length != types.length) return false;
Iterator<TypeMirror> expectedIterator = expected.iterator;
Iterator<TypeMirror> typesIterator = types.iterator;
while (expectedIterator.moveNext() && typesIterator.moveNext()) {
if (!check(expectedIterator.current, typesIterator.current)) {
return false;
}
}
return true;
}

View File

@ -1,42 +1,42 @@
// 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/class_mirror_type_variables_expect.dart";
class CompileTimeEnv implements Env {
final MirrorSystem mirrors;
CompileTimeEnv(this.mirrors);
LibraryMirror get core => mirrors.libraries[Uri.parse('dart:core')];
LibraryMirror get test =>
mirrors.findLibrary(#class_mirror_type_variables_data);
ClassMirror getA() => test.declarations[#A];
ClassMirror getB() => test.declarations[#B];
ClassMirror getC() => test.declarations[#C];
ClassMirror getD() => test.declarations[#D];
ClassMirror getE() => test.declarations[#E];
ClassMirror getF() => test.declarations[#F];
ClassMirror getNoTypeParams() => test.declarations[#NoTypeParams];
ClassMirror getObject() => core.declarations[#Object];
ClassMirror getString() => core.declarations[#String];
ClassMirror getHelperOfString() =>
createInstantiation(test.declarations[#Helper], [getString()]);
}
main() {
asyncTest(() => analyze("class_mirror_type_variables_data.dart").
then((MirrorSystem mirrors) {
test(new CompileTimeEnv(mirrors));
}));
}
// 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/class_mirror_type_variables_expect.dart";
class CompileTimeEnv implements Env {
final MirrorSystem mirrors;
CompileTimeEnv(this.mirrors);
LibraryMirror get core => mirrors.libraries[Uri.parse('dart:core')];
LibraryMirror get test =>
mirrors.findLibrary(#class_mirror_type_variables_data);
ClassMirror getA() => test.declarations[#A];
ClassMirror getB() => test.declarations[#B];
ClassMirror getC() => test.declarations[#C];
ClassMirror getD() => test.declarations[#D];
ClassMirror getE() => test.declarations[#E];
ClassMirror getF() => test.declarations[#F];
ClassMirror getNoTypeParams() => test.declarations[#NoTypeParams];
ClassMirror getObject() => core.declarations[#Object];
ClassMirror getString() => core.declarations[#String];
ClassMirror getHelperOfString() =>
createInstantiation(test.declarations[#Helper], [getString()]);
}
main() {
asyncTest(() => analyze("class_mirror_type_variables_data.dart").
then((MirrorSystem mirrors) {
test(new CompileTimeEnv(mirrors));
}));
}

View File

@ -1,62 +1,62 @@
// 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
import "../memory_compiler.dart";
const SOURCE = const {
'main.dart': """
library main;
class Class {
var a, b, c, d, e, f, g, h;
Class.optional(this.a, int b, void this.c(),
[this.d, int this.e, void this.f(),
this.g = 0, int this.h = 0]);
Class.named(this.a, int b, void this.c(),
{this.d, int this.e, void this.f(),
this.g: 0, int this.h: 0});
methodOptional(a, int b, void c(),
[d, int e, void f(),
g = 0, int h = 0]) {}
methodNamed(a, int b, void c(),
{d, int e, void f(),
g: 0, int h: 0}) {}
}
""",
};
main() {
asyncTest(() => mirrorSystemFor(SOURCE).then((MirrorSystem mirrors) {
LibraryMirror dartCore = mirrors.libraries[Uri.parse('memory:main.dart')];
ClassMirror classMirror = dartCore.declarations[#Class];
testMethod(classMirror.declarations[#optional]);
testMethod(classMirror.declarations[#named]);
testMethod(classMirror.declarations[#methodOptional]);
testMethod(classMirror.declarations[#methodNamed]);
}));
}
testMethod(MethodMirror mirror) {
Expect.equals(8, mirror.parameters.length);
for (int i = 0 ; i < 6 ; i++) {
testParameter(mirror.parameters[i], false);
}
for (int i = 6 ; i < 8 ; i++) {
testParameter(mirror.parameters[i], true);
}
}
testParameter(ParameterMirror mirror, bool expectDefaultValue) {
if (expectDefaultValue) {
Expect.isTrue(mirror.hasDefaultValue);
Expect.isNotNull(mirror.defaultValue);
} else {
Expect.isFalse(mirror.hasDefaultValue);
Expect.isNull(mirror.defaultValue);
}
}
// 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "package:expect/expect.dart";
import "../memory_compiler.dart";
const SOURCE = const {
'main.dart': """
library main;
class Class {
var a, b, c, d, e, f, g, h;
Class.optional(this.a, int b, void this.c(),
[this.d, int this.e, void this.f(),
this.g = 0, int this.h = 0]);
Class.named(this.a, int b, void this.c(),
{this.d, int this.e, void this.f(),
this.g: 0, int this.h: 0});
methodOptional(a, int b, void c(),
[d, int e, void f(),
g = 0, int h = 0]) {}
methodNamed(a, int b, void c(),
{d, int e, void f(),
g: 0, int h: 0}) {}
}
""",
};
main() {
asyncTest(() => mirrorSystemFor(SOURCE).then((MirrorSystem mirrors) {
LibraryMirror dartCore = mirrors.libraries[Uri.parse('memory:main.dart')];
ClassMirror classMirror = dartCore.declarations[#Class];
testMethod(classMirror.declarations[#optional]);
testMethod(classMirror.declarations[#named]);
testMethod(classMirror.declarations[#methodOptional]);
testMethod(classMirror.declarations[#methodNamed]);
}));
}
testMethod(MethodMirror mirror) {
Expect.equals(8, mirror.parameters.length);
for (int i = 0 ; i < 6 ; i++) {
testParameter(mirror.parameters[i], false);
}
for (int i = 6 ; i < 8 ; i++) {
testParameter(mirror.parameters[i], true);
}
}
testParameter(ParameterMirror mirror, bool expectDefaultValue) {
if (expectDefaultValue) {
Expect.isTrue(mirror.hasDefaultValue);
Expect.isNotNull(mirror.defaultValue);
} else {
Expect.isFalse(mirror.hasDefaultValue);
Expect.isNull(mirror.defaultValue);
}
}

View File

@ -1,17 +1,17 @@
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_exports_hidden_test.dart";
main() {
asyncTest(() => analyze("library_exports_hidden_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_exports_hidden_test.dart";
main() {
asyncTest(() => analyze("library_exports_hidden_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}

View File

@ -1,17 +1,17 @@
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_exports_shown_test.dart";
main() {
asyncTest(() => analyze("library_exports_shown_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_exports_shown_test.dart";
main() {
asyncTest(() => analyze("library_exports_shown_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}

View File

@ -1,17 +1,17 @@
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_imports_hidden_test.dart";
main() {
asyncTest(() => analyze("library_imports_hidden_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_imports_hidden_test.dart";
main() {
asyncTest(() => analyze("library_imports_hidden_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}

View File

@ -1,17 +1,17 @@
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_imports_prefixed_show_hide_test.dart";
main() {
asyncTest(() => analyze("library_imports_prefixed_show_hide_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_imports_prefixed_show_hide_test.dart";
main() {
asyncTest(() => analyze("library_imports_prefixed_show_hide_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}

View File

@ -1,17 +1,17 @@
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_imports_prefixed_test.dart";
main() {
asyncTest(() => analyze("library_imports_prefixed_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_imports_prefixed_test.dart";
main() {
asyncTest(() => analyze("library_imports_prefixed_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}

View File

@ -1,17 +1,17 @@
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_imports_shown_test.dart";
main() {
asyncTest(() => analyze("library_imports_shown_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}
// Copyright (c) 2014, 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/library_imports_shown_test.dart";
main() {
asyncTest(() => analyze("library_imports_shown_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}

View File

@ -1,141 +1,141 @@
// 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.
// Test that everything reachable from a [MirrorSystem] can be accessed.
library test.mirrors.reader;
import "dart:mirrors" hide SourceLocation;
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/mirrors_reader.dart";
import "package:compiler/src/util/util.dart";
import "package:compiler/src/mirrors/dart2js_mirrors.dart";
import "package:compiler/src/mirrors/source_mirrors.dart";
class SourceMirrorsReader extends MirrorsReader {
final Dart2JsMirrorSystem mirrorSystem;
SourceMirrorsReader(this.mirrorSystem,
{bool verbose: false, bool includeStackTrace: false})
: super(verbose: verbose, includeStackTrace: includeStackTrace);
evaluate(f()) {
try {
return f();
} on SpannableAssertionFailure catch (e) {
mirrorSystem.compiler.reportAssertionFailure(e);
rethrow;
}
}
visitMirror(Mirror mirror) {
if (mirror is CombinatorMirror) {
visitCombinatorMirror(mirror);
} else if (mirror is LibraryDependencyMirror) {
visitLibraryDependencyMirror(mirror);
} else if (mirror is CommentInstanceMirror) {
visitCommentInstanceMirror(mirror);
} else if (mirror is ListInstanceMirror) {
visitListInstanceMirror(mirror);
} else if (mirror is MapInstanceMirror) {
visitMapInstanceMirror(mirror);
} else if (mirror is TypeInstanceMirror) {
visitTypeInstanceMirror(mirror);
} else {
super.visitMirror(mirror);
}
}
visitDeclarationMirror(DeclarationSourceMirror mirror) {
super.visitDeclarationMirror(mirror);
visit(mirror, 'isNameSynthetic', () => mirror.isNameSynthetic);
}
visitClassMirror(ClassSourceMirror mirror) {
super.visitClassMirror(mirror);
visit(mirror, 'isAbstract', () => mirror.isAbstract);
}
visitLibraryMirror(LibrarySourceMirror mirror) {
super.visitLibraryMirror(mirror);
visit(mirror, 'libraryDependencies', () => mirror.libraryDependencies);
}
visitParameterMirror(ParameterMirror mirror) {
super.visitParameterMirror(mirror);
if (mirror is ParameterSourceMirror) {
visit(mirror, 'isInitializingFormal', () => mirror.isInitializingFormal);
visit(mirror, 'initializedField', () => mirror.initializedField);
}
}
visitTypeMirror(TypeSourceMirror mirror) {
super.visitTypeMirror(mirror);
visit(mirror, 'isVoid', () => mirror.isVoid);
visit(mirror, 'isDynamic', () => mirror.isDynamic);
}
visitSourceLocation(SourceLocation location) {
super.visitSourceLocation(location);
visit(location, 'line', () => location.line);
visit(location, 'column', () => location.column);
visit(location, 'offset', () => location.offset);
visit(location, 'length', () => location.length);
visit(location, 'text', () => location.text);
visit(location, 'sourceUri', () => location.sourceUri);
visit(location, 'sourceText', () => location.sourceText);
}
visitCombinatorMirror(CombinatorMirror mirror) {
visit(mirror, 'identifiers', () => mirror.identifiers);
visit(mirror, 'isShow', () => mirror.isShow);
visit(mirror, 'isHide', () => mirror.isHide);
}
visitLibraryDependencyMirror(LibraryDependencyMirror mirror) {
visit(mirror, 'isImport', () => mirror.isImport);
visit(mirror, 'isExport', () => mirror.isExport);
visit(mirror, 'sourceLibrary', () => mirror.sourceLibrary);
visit(mirror, 'targetLibrary', () => mirror.targetLibrary);
visit(mirror, 'prefix', () => mirror.prefix);
visit(mirror, 'combinators', () => mirror.combinators);
visit(mirror, 'location', () => mirror.location);
}
visitCommentInstanceMirror(CommentInstanceMirror mirror) {
visitInstanceMirror(mirror);
visit(mirror, 'text', () => mirror.text);
visit(mirror, 'trimmedText', () => mirror.trimmedText);
visit(mirror, 'isDocComment', () => mirror.isDocComment);
}
visitListInstanceMirror(ListInstanceMirror mirror) {
visitInstanceMirror(mirror);
visit(mirror, 'length', () => mirror.length);
}
visitMapInstanceMirror(MapInstanceMirror mirror) {
visitInstanceMirror(mirror);
visit(mirror, 'keys', () => mirror.keys);
visit(mirror, 'length', () => mirror.length);
}
visitTypeInstanceMirror(TypeInstanceMirror mirror) {
visitInstanceMirror(mirror);
visit(mirror, 'representedType', () => mirror.representedType);
}
}
main(List<String> arguments) {
asyncTest(() => analyzeUri(Uri.parse('dart:core')).
then((MirrorSystem mirrors) {
MirrorsReader reader = new SourceMirrorsReader(mirrors,
verbose: arguments.contains('-v'),
includeStackTrace: arguments.contains('-s'));
reader.checkMirrorSystem(mirrors);
}));
}
// 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.
// Test that everything reachable from a [MirrorSystem] can be accessed.
library test.mirrors.reader;
import "dart:mirrors" hide SourceLocation;
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/mirrors_reader.dart";
import "package:compiler/src/util/util.dart";
import "package:compiler/src/mirrors/dart2js_mirrors.dart";
import "package:compiler/src/mirrors/source_mirrors.dart";
class SourceMirrorsReader extends MirrorsReader {
final Dart2JsMirrorSystem mirrorSystem;
SourceMirrorsReader(this.mirrorSystem,
{bool verbose: false, bool includeStackTrace: false})
: super(verbose: verbose, includeStackTrace: includeStackTrace);
evaluate(f()) {
try {
return f();
} on SpannableAssertionFailure catch (e) {
mirrorSystem.compiler.reportAssertionFailure(e);
rethrow;
}
}
visitMirror(Mirror mirror) {
if (mirror is CombinatorMirror) {
visitCombinatorMirror(mirror);
} else if (mirror is LibraryDependencyMirror) {
visitLibraryDependencyMirror(mirror);
} else if (mirror is CommentInstanceMirror) {
visitCommentInstanceMirror(mirror);
} else if (mirror is ListInstanceMirror) {
visitListInstanceMirror(mirror);
} else if (mirror is MapInstanceMirror) {
visitMapInstanceMirror(mirror);
} else if (mirror is TypeInstanceMirror) {
visitTypeInstanceMirror(mirror);
} else {
super.visitMirror(mirror);
}
}
visitDeclarationMirror(DeclarationSourceMirror mirror) {
super.visitDeclarationMirror(mirror);
visit(mirror, 'isNameSynthetic', () => mirror.isNameSynthetic);
}
visitClassMirror(ClassSourceMirror mirror) {
super.visitClassMirror(mirror);
visit(mirror, 'isAbstract', () => mirror.isAbstract);
}
visitLibraryMirror(LibrarySourceMirror mirror) {
super.visitLibraryMirror(mirror);
visit(mirror, 'libraryDependencies', () => mirror.libraryDependencies);
}
visitParameterMirror(ParameterMirror mirror) {
super.visitParameterMirror(mirror);
if (mirror is ParameterSourceMirror) {
visit(mirror, 'isInitializingFormal', () => mirror.isInitializingFormal);
visit(mirror, 'initializedField', () => mirror.initializedField);
}
}
visitTypeMirror(TypeSourceMirror mirror) {
super.visitTypeMirror(mirror);
visit(mirror, 'isVoid', () => mirror.isVoid);
visit(mirror, 'isDynamic', () => mirror.isDynamic);
}
visitSourceLocation(SourceLocation location) {
super.visitSourceLocation(location);
visit(location, 'line', () => location.line);
visit(location, 'column', () => location.column);
visit(location, 'offset', () => location.offset);
visit(location, 'length', () => location.length);
visit(location, 'text', () => location.text);
visit(location, 'sourceUri', () => location.sourceUri);
visit(location, 'sourceText', () => location.sourceText);
}
visitCombinatorMirror(CombinatorMirror mirror) {
visit(mirror, 'identifiers', () => mirror.identifiers);
visit(mirror, 'isShow', () => mirror.isShow);
visit(mirror, 'isHide', () => mirror.isHide);
}
visitLibraryDependencyMirror(LibraryDependencyMirror mirror) {
visit(mirror, 'isImport', () => mirror.isImport);
visit(mirror, 'isExport', () => mirror.isExport);
visit(mirror, 'sourceLibrary', () => mirror.sourceLibrary);
visit(mirror, 'targetLibrary', () => mirror.targetLibrary);
visit(mirror, 'prefix', () => mirror.prefix);
visit(mirror, 'combinators', () => mirror.combinators);
visit(mirror, 'location', () => mirror.location);
}
visitCommentInstanceMirror(CommentInstanceMirror mirror) {
visitInstanceMirror(mirror);
visit(mirror, 'text', () => mirror.text);
visit(mirror, 'trimmedText', () => mirror.trimmedText);
visit(mirror, 'isDocComment', () => mirror.isDocComment);
}
visitListInstanceMirror(ListInstanceMirror mirror) {
visitInstanceMirror(mirror);
visit(mirror, 'length', () => mirror.length);
}
visitMapInstanceMirror(MapInstanceMirror mirror) {
visitInstanceMirror(mirror);
visit(mirror, 'keys', () => mirror.keys);
visit(mirror, 'length', () => mirror.length);
}
visitTypeInstanceMirror(TypeInstanceMirror mirror) {
visitInstanceMirror(mirror);
visit(mirror, 'representedType', () => mirror.representedType);
}
}
main(List<String> arguments) {
asyncTest(() => analyzeUri(Uri.parse('dart:core')).
then((MirrorSystem mirrors) {
MirrorsReader reader = new SourceMirrorsReader(mirrors,
verbose: arguments.contains('-v'),
includeStackTrace: arguments.contains('-s'));
reader.checkMirrorSystem(mirrors);
}));
}

View File

@ -1,37 +1,37 @@
// 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 'dart:io';
import 'dart:async';
import 'package:compiler/src/mirrors/source_mirrors.dart';
import 'package:compiler/src/mirrors/analyze.dart' as source_mirrors;
import 'package:compiler/src/source_file_provider.dart';
TypeMirror createInstantiation(TypeSourceMirror type,
List<TypeMirror> typeArguments) {
return type.createInstantiation(typeArguments);
}
Future<MirrorSystem> analyze(String test) {
Uri repository = Platform.script.resolve('../../../../');
Uri testUri = repository.resolve('tests/lib/mirrors/$test');
return analyzeUri(testUri);
}
Future<MirrorSystem> analyzeUri(Uri testUri) {
Uri repository = Platform.script.resolve('../../../../');
Uri libraryRoot = repository.resolve('sdk/');
Uri packageRoot = Uri.base.resolveUri(
new Uri.file('${Platform.packageRoot}/'));
var provider = new CompilerSourceFileProvider();
var handler = new FormattingDiagnosticHandler(provider);
return source_mirrors.analyze(
[testUri],
libraryRoot,
packageRoot,
provider,
handler);
// 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 'dart:io';
import 'dart:async';
import 'package:compiler/src/mirrors/source_mirrors.dart';
import 'package:compiler/src/mirrors/analyze.dart' as source_mirrors;
import 'package:compiler/src/source_file_provider.dart';
TypeMirror createInstantiation(TypeSourceMirror type,
List<TypeMirror> typeArguments) {
return type.createInstantiation(typeArguments);
}
Future<MirrorSystem> analyze(String test) {
Uri repository = Platform.script.resolve('../../../../');
Uri testUri = repository.resolve('tests/lib/mirrors/$test');
return analyzeUri(testUri);
}
Future<MirrorSystem> analyzeUri(Uri testUri) {
Uri repository = Platform.script.resolve('../../../../');
Uri libraryRoot = repository.resolve('sdk/');
Uri packageRoot = Uri.base.resolveUri(
new Uri.file('${Platform.packageRoot}/'));
var provider = new CompilerSourceFileProvider();
var handler = new FormattingDiagnosticHandler(provider);
return source_mirrors.analyze(
[testUri],
libraryRoot,
packageRoot,
provider,
handler);
}

View File

@ -1,17 +1,17 @@
// 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/relation_assignable_test.dart";
main() {
asyncTest(() => analyze("relation_assignable_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}
// 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/relation_assignable_test.dart";
main() {
asyncTest(() => analyze("relation_assignable_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}

View File

@ -1,17 +1,17 @@
// 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/relation_subclass_test.dart";
main() {
asyncTest(() => analyze("relation_subclass_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}
// 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/relation_subclass_test.dart";
main() {
asyncTest(() => analyze("relation_subclass_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}

View File

@ -1,17 +1,17 @@
// 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/relation_subtype_test.dart";
main() {
asyncTest(() => analyze("relation_subtype_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}
// 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 "dart:mirrors";
import "package:async_helper/async_helper.dart";
import "mirrors_test_helper.dart";
import "../../../lib/mirrors/relation_subtype_test.dart";
main() {
asyncTest(() => analyze("relation_subtype_test.dart").
then((MirrorSystem mirrors) {
test(mirrors);
}));
}

View File

@ -1,183 +1,183 @@
// Copyright (c) 2012, 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 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'dart:async';
import 'memory_compiler.dart';
import 'package:compiler/src/mirrors/source_mirrors.dart';
const SOURCE_FILES = const {
'main.dart': '''
import 'a.dart' show A1, A2;
import 'b.dart' as b hide B1;
export 'a.dart' show A2 hide A3, A1;
export 'b.dart' hide B1, B2 show B3;
import 'dart:core' as core;
import 'c.dart' deferred as c;
main() {}
''',
'a.dart': '''
class A1 {}
class A2 {}
class A3 {}
''',
'b.dart': '''
class B1 {}
class B2 {}
class B3 {}
''',
'c.dart': '''
foo() => 499;
'''
};
void main() {
asyncTest(() => mirrorSystemFor(SOURCE_FILES).then((MirrorSystem mirrors) {
LibrarySourceMirror mainLibrary =
mirrors.libraries[Uri.parse('memory:main.dart')];
Expect.isNotNull(mainLibrary);
LibrarySourceMirror aLibrary =
mirrors.libraries[Uri.parse('memory:a.dart')];
Expect.isNotNull(aLibrary);
LibrarySourceMirror bLibrary =
mirrors.libraries[Uri.parse('memory:b.dart')];
Expect.isNotNull(bLibrary);
LibrarySourceMirror cLibrary =
mirrors.libraries[Uri.parse('memory:c.dart')];
Expect.isNotNull(cLibrary);
LibrarySourceMirror coreLibrary =
mirrors.libraries[Uri.parse('dart:core')];
Expect.isNotNull(coreLibrary);
var dependencies = mainLibrary.libraryDependencies;
Expect.isNotNull(dependencies);
Expect.equals(6, dependencies.length);
// import 'a.dart' show A1, A2;
var dependency = dependencies[0];
Expect.isNotNull(dependency);
Expect.isTrue(dependency.isImport);
Expect.isFalse(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(aLibrary, dependency.targetLibrary);
Expect.isNull(dependency.prefix);
Expect.isFalse(dependency.isDeferred);
var combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(1, combinators.length);
var combinator = combinators[0];
Expect.isNotNull(combinator);
Expect.isTrue(combinator.isShow);
Expect.isFalse(combinator.isHide);
Expect.listEquals(['A1', 'A2'], combinator.identifiers);
// import 'b.dart' as b hide B1;
dependency = dependencies[1];
Expect.isNotNull(dependency);
Expect.isTrue(dependency.isImport);
Expect.isFalse(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(bLibrary, dependency.targetLibrary);
Expect.equals('b', dependency.prefix);
Expect.isFalse(dependency.isDeferred);
combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(1, combinators.length);
combinator = combinators[0];
Expect.isNotNull(combinator);
Expect.isFalse(combinator.isShow);
Expect.isTrue(combinator.isHide);
Expect.listEquals(['B1'], combinator.identifiers);
// export 'a.dart' show A2 hide A3, A1;
dependency = dependencies[2];
Expect.isNotNull(dependency);
Expect.isFalse(dependency.isImport);
Expect.isTrue(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(aLibrary, dependency.targetLibrary);
Expect.isNull(dependency.prefix);
Expect.isFalse(dependency.isDeferred);
combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(2, combinators.length);
combinator = combinators[0];
Expect.isNotNull(combinator);
Expect.isTrue(combinator.isShow);
Expect.isFalse(combinator.isHide);
Expect.listEquals(['A2'], combinator.identifiers);
combinator = combinators[1];
Expect.isNotNull(combinator);
Expect.isFalse(combinator.isShow);
Expect.isTrue(combinator.isHide);
Expect.listEquals(['A3', 'A1'], combinator.identifiers);
// export 'b.dart' hide B1, B2 show B3;
dependency = dependencies[3];
Expect.isNotNull(dependency);
Expect.isFalse(dependency.isImport);
Expect.isTrue(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(bLibrary, dependency.targetLibrary);
Expect.isNull(dependency.prefix);
Expect.isFalse(dependency.isDeferred);
combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(2, combinators.length);
combinator = combinators[0];
Expect.isNotNull(combinator);
Expect.isFalse(combinator.isShow);
Expect.isTrue(combinator.isHide);
Expect.listEquals(['B1', 'B2'], combinator.identifiers);
combinator = combinators[1];
Expect.isNotNull(combinator);
Expect.isTrue(combinator.isShow);
Expect.isFalse(combinator.isHide);
Expect.listEquals(['B3'], combinator.identifiers);
// import 'dart:core' as core;
dependency = dependencies[4];
Expect.isNotNull(dependency);
Expect.isTrue(dependency.isImport);
Expect.isFalse(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(coreLibrary, dependency.targetLibrary);
Expect.equals('core', dependency.prefix);
Expect.isFalse(dependency.isDeferred);
combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(0, combinators.length);
// import 'c.dart' deferred as c;
dependency = dependencies[5];
Expect.isNotNull(dependency);
Expect.isTrue(dependency.isImport);
Expect.isFalse(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(cLibrary, dependency.targetLibrary);
Expect.equals('c', dependency.prefix);
Expect.isTrue(dependency.isDeferred);
combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(0, combinators.length);
}));
// Copyright (c) 2012, 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 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'dart:async';
import 'memory_compiler.dart';
import 'package:compiler/src/mirrors/source_mirrors.dart';
const SOURCE_FILES = const {
'main.dart': '''
import 'a.dart' show A1, A2;
import 'b.dart' as b hide B1;
export 'a.dart' show A2 hide A3, A1;
export 'b.dart' hide B1, B2 show B3;
import 'dart:core' as core;
import 'c.dart' deferred as c;
main() {}
''',
'a.dart': '''
class A1 {}
class A2 {}
class A3 {}
''',
'b.dart': '''
class B1 {}
class B2 {}
class B3 {}
''',
'c.dart': '''
foo() => 499;
'''
};
void main() {
asyncTest(() => mirrorSystemFor(SOURCE_FILES).then((MirrorSystem mirrors) {
LibrarySourceMirror mainLibrary =
mirrors.libraries[Uri.parse('memory:main.dart')];
Expect.isNotNull(mainLibrary);
LibrarySourceMirror aLibrary =
mirrors.libraries[Uri.parse('memory:a.dart')];
Expect.isNotNull(aLibrary);
LibrarySourceMirror bLibrary =
mirrors.libraries[Uri.parse('memory:b.dart')];
Expect.isNotNull(bLibrary);
LibrarySourceMirror cLibrary =
mirrors.libraries[Uri.parse('memory:c.dart')];
Expect.isNotNull(cLibrary);
LibrarySourceMirror coreLibrary =
mirrors.libraries[Uri.parse('dart:core')];
Expect.isNotNull(coreLibrary);
var dependencies = mainLibrary.libraryDependencies;
Expect.isNotNull(dependencies);
Expect.equals(6, dependencies.length);
// import 'a.dart' show A1, A2;
var dependency = dependencies[0];
Expect.isNotNull(dependency);
Expect.isTrue(dependency.isImport);
Expect.isFalse(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(aLibrary, dependency.targetLibrary);
Expect.isNull(dependency.prefix);
Expect.isFalse(dependency.isDeferred);
var combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(1, combinators.length);
var combinator = combinators[0];
Expect.isNotNull(combinator);
Expect.isTrue(combinator.isShow);
Expect.isFalse(combinator.isHide);
Expect.listEquals(['A1', 'A2'], combinator.identifiers);
// import 'b.dart' as b hide B1;
dependency = dependencies[1];
Expect.isNotNull(dependency);
Expect.isTrue(dependency.isImport);
Expect.isFalse(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(bLibrary, dependency.targetLibrary);
Expect.equals('b', dependency.prefix);
Expect.isFalse(dependency.isDeferred);
combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(1, combinators.length);
combinator = combinators[0];
Expect.isNotNull(combinator);
Expect.isFalse(combinator.isShow);
Expect.isTrue(combinator.isHide);
Expect.listEquals(['B1'], combinator.identifiers);
// export 'a.dart' show A2 hide A3, A1;
dependency = dependencies[2];
Expect.isNotNull(dependency);
Expect.isFalse(dependency.isImport);
Expect.isTrue(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(aLibrary, dependency.targetLibrary);
Expect.isNull(dependency.prefix);
Expect.isFalse(dependency.isDeferred);
combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(2, combinators.length);
combinator = combinators[0];
Expect.isNotNull(combinator);
Expect.isTrue(combinator.isShow);
Expect.isFalse(combinator.isHide);
Expect.listEquals(['A2'], combinator.identifiers);
combinator = combinators[1];
Expect.isNotNull(combinator);
Expect.isFalse(combinator.isShow);
Expect.isTrue(combinator.isHide);
Expect.listEquals(['A3', 'A1'], combinator.identifiers);
// export 'b.dart' hide B1, B2 show B3;
dependency = dependencies[3];
Expect.isNotNull(dependency);
Expect.isFalse(dependency.isImport);
Expect.isTrue(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(bLibrary, dependency.targetLibrary);
Expect.isNull(dependency.prefix);
Expect.isFalse(dependency.isDeferred);
combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(2, combinators.length);
combinator = combinators[0];
Expect.isNotNull(combinator);
Expect.isFalse(combinator.isShow);
Expect.isTrue(combinator.isHide);
Expect.listEquals(['B1', 'B2'], combinator.identifiers);
combinator = combinators[1];
Expect.isNotNull(combinator);
Expect.isTrue(combinator.isShow);
Expect.isFalse(combinator.isHide);
Expect.listEquals(['B3'], combinator.identifiers);
// import 'dart:core' as core;
dependency = dependencies[4];
Expect.isNotNull(dependency);
Expect.isTrue(dependency.isImport);
Expect.isFalse(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(coreLibrary, dependency.targetLibrary);
Expect.equals('core', dependency.prefix);
Expect.isFalse(dependency.isDeferred);
combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(0, combinators.length);
// import 'c.dart' deferred as c;
dependency = dependencies[5];
Expect.isNotNull(dependency);
Expect.isTrue(dependency.isImport);
Expect.isFalse(dependency.isExport);
Expect.equals(mainLibrary, dependency.sourceLibrary);
Expect.equals(cLibrary, dependency.targetLibrary);
Expect.equals('c', dependency.prefix);
Expect.isTrue(dependency.isDeferred);
combinators = dependency.combinators;
Expect.isNotNull(combinators);
Expect.equals(0, combinators.length);
}));
}

View File

@ -1,240 +1,240 @@
// 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 mirrors_mixin_test;
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'mirror_system_helper.dart';
const String CLASS_SOURCE = '''
class A {}
class S {}
class M1<T> {}
class M2 {}
class C extends S with M1<A> {}
class D extends S with M1, M2 {}
class E extends S with M2, M1 implements A, M1 {}
class E2 extends E {}
class F = S with M1<A>;
abstract class G = S with M1, M2;
class H = S with M2, M1 implements A, M1;
class H2 extends H {}
''';
void main() {
asyncTest(() => createMirrorSystem(CLASS_SOURCE).then((MirrorSystem mirrors) {
LibraryMirror library = mirrors.libraries[SOURCE_URI];
checkSimpleClass(var cls) {
Expect.isNotNull(cls);
Expect.isTrue(cls is ClassMirror);
Expect.isFalse(isMixinApplication(cls));
Expect.isFalse(cls.isNameSynthetic);
Expect.isFalse(isObject(cls));
Expect.isTrue(isObject(cls.superclass));
Expect.equals(0, cls.superinterfaces.length);
Expect.isTrue(isObject(getSuperclass(cls)));
Expect.isTrue(getAppliedMixins(cls).isEmpty);
Expect.isTrue(getExplicitInterfaces(cls).isEmpty);
}
// class A {}
var A = library.declarations[#A];
checkSimpleClass(A);
// class S {}
var S = library.declarations[#S];
checkSimpleClass(S);
// class M1 {}
var M1 = library.declarations[#M1];
checkSimpleClass(M1);
// class M2 {}
var M2 = library.declarations[#M2];
checkSimpleClass(M2);
// class C extends S with M1<A> {}
var C = library.declarations[#C];
Expect.isNotNull(C);
Expect.isTrue(C is ClassMirror);
Expect.isFalse(isMixinApplication(C));
Expect.isFalse(isObject(C));
Expect.equals(0, C.superinterfaces.length);
var C_super = C.superclass;
Expect.isNotNull(C_super);
Expect.isTrue(C_super is ClassMirror);
Expect.isTrue(isMixinApplication(C_super));
Expect.isTrue(C_super.isNameSynthetic);
Expect.equals(1, C_super.superinterfaces.length);
Expect.isTrue(containsType(M1, [A], C_super.superinterfaces));
Expect.isTrue(isInstance(M1, [A], C_super.mixin));
Expect.isFalse(isObject(C_super));
Expect.isTrue(isSameDeclaration(S, C_super.superclass));
Expect.isTrue(isSameDeclaration(S, getSuperclass(C)));
Expect.isTrue(isSameDeclarationList([M1], getAppliedMixins(C)));
Expect.isTrue(getExplicitInterfaces(C).isEmpty);
// D extends S with M1, M2 {}
var D = library.declarations[#D];
Expect.isNotNull(D);
Expect.isTrue(D is ClassMirror);
Expect.isFalse(isMixinApplication(D));
Expect.isFalse(isObject(D));
Expect.equals(0, D.superinterfaces.length);
var D_super = D.superclass;
Expect.isNotNull(D_super);
Expect.isTrue(D_super is ClassMirror);
Expect.isTrue(isMixinApplication(D_super));
Expect.isTrue(D_super.isNameSynthetic);
Expect.equals(1, D_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M2, D_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M2, D_super.mixin));
Expect.isFalse(isObject(D_super));
Expect.isFalse(isSameDeclaration(S, D_super.superclass));
var D_super_super = D_super.superclass;
Expect.isNotNull(D_super_super);
Expect.isTrue(D_super_super is ClassMirror);
Expect.isTrue(isMixinApplication(D_super_super));
Expect.isTrue(D_super_super.isNameSynthetic);
Expect.equals(1, D_super_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M1, D_super_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M1, D_super_super.mixin));
Expect.isFalse(isObject(D_super_super));
Expect.isTrue(isSameDeclaration(S, D_super_super.superclass));
Expect.isTrue(isSameDeclaration(S, getSuperclass(D)));
Expect.isTrue(isSameDeclarationList([M1, M2], getAppliedMixins(D)));
Expect.isTrue(getExplicitInterfaces(D).isEmpty);
// class E extends S with M2, M1 implements A, M1 {}
var E = library.declarations[#E];
Expect.isNotNull(E);
Expect.isTrue(E is ClassMirror);
Expect.isFalse(isMixinApplication(E));
Expect.isFalse(isObject(E));
Expect.equals(2, E.superinterfaces.length);
Expect.isTrue(containsDeclaration(A, E.superinterfaces));
Expect.isTrue(containsDeclaration(M1, E.superinterfaces));
var E_super = E.superclass;
Expect.isNotNull(E_super);
Expect.isTrue(E_super is ClassMirror);
Expect.isTrue(isMixinApplication(E_super));
Expect.isTrue(E_super.isNameSynthetic);
Expect.equals(1, E_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M1, E_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M1, E_super.mixin));
Expect.isFalse(isObject(E_super));
Expect.isFalse(isSameDeclaration(S, E_super.superclass));
var E_super_super = E_super.superclass;
Expect.isNotNull(E_super_super);
Expect.isTrue(E_super_super is ClassMirror);
Expect.isTrue(isMixinApplication(E_super_super));
Expect.isTrue(E_super_super.isNameSynthetic);
Expect.equals(1, E_super_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M2, E_super_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M2, E_super_super.mixin));
Expect.isFalse(isObject(E_super_super));
Expect.isTrue(isSameDeclaration(S, E_super_super.superclass));
Expect.isTrue(isSameDeclaration(S, getSuperclass(E)));
Expect.isTrue(isSameDeclarationList([M2, M1], getAppliedMixins(E)));
Expect.isTrue(isSameDeclarationSet([A, M1], getExplicitInterfaces(E)));
// class E2 extends E {}
var E2 = library.declarations[#E2];
Expect.isTrue(isSameDeclaration(E, getSuperclass(E2)));
Expect.isTrue(getAppliedMixins(E2).isEmpty);
Expect.isTrue(getExplicitInterfaces(E2).isEmpty);
// class F = S with M1<A>;
var F = library.declarations[#F];
Expect.isNotNull(F);
Expect.isTrue(F is ClassMirror);
Expect.isFalse(F.isAbstract);
Expect.isTrue(isMixinApplication(F));
Expect.isFalse(F.isNameSynthetic);
Expect.equals(#F, F.simpleName);
Expect.isFalse(isObject(F));
Expect.equals(1, F.superinterfaces.length);
Expect.isTrue(containsDeclaration(M1, F.superinterfaces));
Expect.isTrue(isInstance(M1, [A], F.mixin));
var F_super = F.superclass;
Expect.isNotNull(F_super);
Expect.isTrue(F_super is ClassMirror);
Expect.isFalse(isMixinApplication(F_super));
Expect.isFalse(isObject(F_super));
Expect.isTrue(isSameDeclaration(S, F_super));
Expect.isTrue(isSameDeclaration(S, getSuperclass(F)));
Expect.isTrue(isSameDeclarationList([M1], getAppliedMixins(F)));
Expect.isTrue(getExplicitInterfaces(F).isEmpty);
// typedef G = abstract S with M1, M2;
var G = library.declarations[#G];
Expect.isNotNull(G);
Expect.isTrue(G is ClassMirror);
Expect.isTrue(G.isAbstract);
Expect.isTrue(isMixinApplication(G));
Expect.isFalse(G.isNameSynthetic);
Expect.equals(#G, G.simpleName);
Expect.isFalse(isObject(G));
Expect.equals(1, G.superinterfaces.length);
Expect.isTrue(containsDeclaration(M2, G.superinterfaces));
Expect.isTrue(isSameDeclaration(M2, G.mixin));
var G_super = G.superclass;
Expect.isNotNull(G_super);
Expect.isTrue(G_super is ClassMirror);
Expect.isTrue(isMixinApplication(G_super));
Expect.equals(1, G_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M1, G_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M1, G_super.mixin));
Expect.isFalse(isObject(G_super));
Expect.isTrue(isSameDeclaration(S, G_super.superclass));
Expect.isTrue(isSameDeclaration(S, getSuperclass(G)));
Expect.isTrue(isSameDeclarationList([M1, M2], getAppliedMixins(G)));
Expect.isTrue(getExplicitInterfaces(G).isEmpty);
// typedef H = S with M2, M1 implements A, M1;
var H = library.declarations[#H];
Expect.isNotNull(H);
Expect.isTrue(H is ClassMirror);
Expect.isFalse(H.isAbstract);
Expect.isTrue(isMixinApplication(H));
Expect.isFalse(H.isNameSynthetic);
Expect.equals(#H, H.simpleName);
Expect.isFalse(isObject(H));
Expect.equals(3, H.superinterfaces.length);
Expect.isTrue(containsDeclaration(A, H.superinterfaces));
Expect.isTrue(containsDeclaration(M1, H.superinterfaces));
Expect.isFalse(containsDeclaration(M2, H.superinterfaces));
Expect.isTrue(isSameDeclaration(M1, H.mixin));
var H_super = H.superclass;
Expect.isNotNull(H_super);
Expect.isTrue(H_super is ClassMirror);
Expect.isTrue(isMixinApplication(H_super));
Expect.equals(1, H_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M2, H_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M2, H_super.mixin));
Expect.isFalse(isObject(H_super));
Expect.isTrue(isSameDeclaration(S, H_super.superclass));
Expect.isTrue(isSameDeclaration(S, getSuperclass(H)));
Expect.isTrue(isSameDeclarationList([M2, M1], getAppliedMixins(H)));
Expect.isTrue(isSameDeclarationSet([A, M1], getExplicitInterfaces(H)));
// class H2 extends H {}
var H2 = library.declarations[#H2];
Expect.isTrue(isSameDeclaration(H, getSuperclass(H2)));
Expect.isTrue(getAppliedMixins(H2).isEmpty);
Expect.isTrue(getExplicitInterfaces(H2).isEmpty);
}));
// 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 mirrors_mixin_test;
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'mirror_system_helper.dart';
const String CLASS_SOURCE = '''
class A {}
class S {}
class M1<T> {}
class M2 {}
class C extends S with M1<A> {}
class D extends S with M1, M2 {}
class E extends S with M2, M1 implements A, M1 {}
class E2 extends E {}
class F = S with M1<A>;
abstract class G = S with M1, M2;
class H = S with M2, M1 implements A, M1;
class H2 extends H {}
''';
void main() {
asyncTest(() => createMirrorSystem(CLASS_SOURCE).then((MirrorSystem mirrors) {
LibraryMirror library = mirrors.libraries[SOURCE_URI];
checkSimpleClass(var cls) {
Expect.isNotNull(cls);
Expect.isTrue(cls is ClassMirror);
Expect.isFalse(isMixinApplication(cls));
Expect.isFalse(cls.isNameSynthetic);
Expect.isFalse(isObject(cls));
Expect.isTrue(isObject(cls.superclass));
Expect.equals(0, cls.superinterfaces.length);
Expect.isTrue(isObject(getSuperclass(cls)));
Expect.isTrue(getAppliedMixins(cls).isEmpty);
Expect.isTrue(getExplicitInterfaces(cls).isEmpty);
}
// class A {}
var A = library.declarations[#A];
checkSimpleClass(A);
// class S {}
var S = library.declarations[#S];
checkSimpleClass(S);
// class M1 {}
var M1 = library.declarations[#M1];
checkSimpleClass(M1);
// class M2 {}
var M2 = library.declarations[#M2];
checkSimpleClass(M2);
// class C extends S with M1<A> {}
var C = library.declarations[#C];
Expect.isNotNull(C);
Expect.isTrue(C is ClassMirror);
Expect.isFalse(isMixinApplication(C));
Expect.isFalse(isObject(C));
Expect.equals(0, C.superinterfaces.length);
var C_super = C.superclass;
Expect.isNotNull(C_super);
Expect.isTrue(C_super is ClassMirror);
Expect.isTrue(isMixinApplication(C_super));
Expect.isTrue(C_super.isNameSynthetic);
Expect.equals(1, C_super.superinterfaces.length);
Expect.isTrue(containsType(M1, [A], C_super.superinterfaces));
Expect.isTrue(isInstance(M1, [A], C_super.mixin));
Expect.isFalse(isObject(C_super));
Expect.isTrue(isSameDeclaration(S, C_super.superclass));
Expect.isTrue(isSameDeclaration(S, getSuperclass(C)));
Expect.isTrue(isSameDeclarationList([M1], getAppliedMixins(C)));
Expect.isTrue(getExplicitInterfaces(C).isEmpty);
// D extends S with M1, M2 {}
var D = library.declarations[#D];
Expect.isNotNull(D);
Expect.isTrue(D is ClassMirror);
Expect.isFalse(isMixinApplication(D));
Expect.isFalse(isObject(D));
Expect.equals(0, D.superinterfaces.length);
var D_super = D.superclass;
Expect.isNotNull(D_super);
Expect.isTrue(D_super is ClassMirror);
Expect.isTrue(isMixinApplication(D_super));
Expect.isTrue(D_super.isNameSynthetic);
Expect.equals(1, D_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M2, D_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M2, D_super.mixin));
Expect.isFalse(isObject(D_super));
Expect.isFalse(isSameDeclaration(S, D_super.superclass));
var D_super_super = D_super.superclass;
Expect.isNotNull(D_super_super);
Expect.isTrue(D_super_super is ClassMirror);
Expect.isTrue(isMixinApplication(D_super_super));
Expect.isTrue(D_super_super.isNameSynthetic);
Expect.equals(1, D_super_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M1, D_super_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M1, D_super_super.mixin));
Expect.isFalse(isObject(D_super_super));
Expect.isTrue(isSameDeclaration(S, D_super_super.superclass));
Expect.isTrue(isSameDeclaration(S, getSuperclass(D)));
Expect.isTrue(isSameDeclarationList([M1, M2], getAppliedMixins(D)));
Expect.isTrue(getExplicitInterfaces(D).isEmpty);
// class E extends S with M2, M1 implements A, M1 {}
var E = library.declarations[#E];
Expect.isNotNull(E);
Expect.isTrue(E is ClassMirror);
Expect.isFalse(isMixinApplication(E));
Expect.isFalse(isObject(E));
Expect.equals(2, E.superinterfaces.length);
Expect.isTrue(containsDeclaration(A, E.superinterfaces));
Expect.isTrue(containsDeclaration(M1, E.superinterfaces));
var E_super = E.superclass;
Expect.isNotNull(E_super);
Expect.isTrue(E_super is ClassMirror);
Expect.isTrue(isMixinApplication(E_super));
Expect.isTrue(E_super.isNameSynthetic);
Expect.equals(1, E_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M1, E_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M1, E_super.mixin));
Expect.isFalse(isObject(E_super));
Expect.isFalse(isSameDeclaration(S, E_super.superclass));
var E_super_super = E_super.superclass;
Expect.isNotNull(E_super_super);
Expect.isTrue(E_super_super is ClassMirror);
Expect.isTrue(isMixinApplication(E_super_super));
Expect.isTrue(E_super_super.isNameSynthetic);
Expect.equals(1, E_super_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M2, E_super_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M2, E_super_super.mixin));
Expect.isFalse(isObject(E_super_super));
Expect.isTrue(isSameDeclaration(S, E_super_super.superclass));
Expect.isTrue(isSameDeclaration(S, getSuperclass(E)));
Expect.isTrue(isSameDeclarationList([M2, M1], getAppliedMixins(E)));
Expect.isTrue(isSameDeclarationSet([A, M1], getExplicitInterfaces(E)));
// class E2 extends E {}
var E2 = library.declarations[#E2];
Expect.isTrue(isSameDeclaration(E, getSuperclass(E2)));
Expect.isTrue(getAppliedMixins(E2).isEmpty);
Expect.isTrue(getExplicitInterfaces(E2).isEmpty);
// class F = S with M1<A>;
var F = library.declarations[#F];
Expect.isNotNull(F);
Expect.isTrue(F is ClassMirror);
Expect.isFalse(F.isAbstract);
Expect.isTrue(isMixinApplication(F));
Expect.isFalse(F.isNameSynthetic);
Expect.equals(#F, F.simpleName);
Expect.isFalse(isObject(F));
Expect.equals(1, F.superinterfaces.length);
Expect.isTrue(containsDeclaration(M1, F.superinterfaces));
Expect.isTrue(isInstance(M1, [A], F.mixin));
var F_super = F.superclass;
Expect.isNotNull(F_super);
Expect.isTrue(F_super is ClassMirror);
Expect.isFalse(isMixinApplication(F_super));
Expect.isFalse(isObject(F_super));
Expect.isTrue(isSameDeclaration(S, F_super));
Expect.isTrue(isSameDeclaration(S, getSuperclass(F)));
Expect.isTrue(isSameDeclarationList([M1], getAppliedMixins(F)));
Expect.isTrue(getExplicitInterfaces(F).isEmpty);
// typedef G = abstract S with M1, M2;
var G = library.declarations[#G];
Expect.isNotNull(G);
Expect.isTrue(G is ClassMirror);
Expect.isTrue(G.isAbstract);
Expect.isTrue(isMixinApplication(G));
Expect.isFalse(G.isNameSynthetic);
Expect.equals(#G, G.simpleName);
Expect.isFalse(isObject(G));
Expect.equals(1, G.superinterfaces.length);
Expect.isTrue(containsDeclaration(M2, G.superinterfaces));
Expect.isTrue(isSameDeclaration(M2, G.mixin));
var G_super = G.superclass;
Expect.isNotNull(G_super);
Expect.isTrue(G_super is ClassMirror);
Expect.isTrue(isMixinApplication(G_super));
Expect.equals(1, G_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M1, G_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M1, G_super.mixin));
Expect.isFalse(isObject(G_super));
Expect.isTrue(isSameDeclaration(S, G_super.superclass));
Expect.isTrue(isSameDeclaration(S, getSuperclass(G)));
Expect.isTrue(isSameDeclarationList([M1, M2], getAppliedMixins(G)));
Expect.isTrue(getExplicitInterfaces(G).isEmpty);
// typedef H = S with M2, M1 implements A, M1;
var H = library.declarations[#H];
Expect.isNotNull(H);
Expect.isTrue(H is ClassMirror);
Expect.isFalse(H.isAbstract);
Expect.isTrue(isMixinApplication(H));
Expect.isFalse(H.isNameSynthetic);
Expect.equals(#H, H.simpleName);
Expect.isFalse(isObject(H));
Expect.equals(3, H.superinterfaces.length);
Expect.isTrue(containsDeclaration(A, H.superinterfaces));
Expect.isTrue(containsDeclaration(M1, H.superinterfaces));
Expect.isFalse(containsDeclaration(M2, H.superinterfaces));
Expect.isTrue(isSameDeclaration(M1, H.mixin));
var H_super = H.superclass;
Expect.isNotNull(H_super);
Expect.isTrue(H_super is ClassMirror);
Expect.isTrue(isMixinApplication(H_super));
Expect.equals(1, H_super.superinterfaces.length);
Expect.isTrue(containsDeclaration(M2, H_super.superinterfaces));
Expect.isTrue(isSameDeclaration(M2, H_super.mixin));
Expect.isFalse(isObject(H_super));
Expect.isTrue(isSameDeclaration(S, H_super.superclass));
Expect.isTrue(isSameDeclaration(S, getSuperclass(H)));
Expect.isTrue(isSameDeclarationList([M2, M1], getAppliedMixins(H)));
Expect.isTrue(isSameDeclarationSet([A, M1], getExplicitInterfaces(H)));
// class H2 extends H {}
var H2 = library.declarations[#H2];
Expect.isTrue(isSameDeclaration(H, getSuperclass(H2)));
Expect.isTrue(getAppliedMixins(H2).isEmpty);
Expect.isTrue(getExplicitInterfaces(H2).isEmpty);
}));
}

View File

@ -1,21 +1,21 @@
// 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.
// Test that dart2js produces the expected static type warnings for these
// language tests. This ensures that the analyzer and dart2js agrees on the
// tests.
import 'warnings_checker.dart';
/// Map from test files to a map of their expected status. If the status map is
/// `null` no warnings must be missing or unexpected, otherwise the status map
/// can contain a list of line numbers for keys 'missing' and 'unexpected' for
/// the warnings of each category.
const Map<String, dynamic> TESTS = const {
'language/typevariable_substitution2_test.dart': null,
};
void main(List<String> arguments) {
checkWarnings(TESTS, arguments);
}
// 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.
// Test that dart2js produces the expected static type warnings for these
// language tests. This ensures that the analyzer and dart2js agrees on the
// tests.
import 'warnings_checker.dart';
/// Map from test files to a map of their expected status. If the status map is
/// `null` no warnings must be missing or unexpected, otherwise the status map
/// can contain a list of line numbers for keys 'missing' and 'unexpected' for
/// the warnings of each category.
const Map<String, dynamic> TESTS = const {
'language/typevariable_substitution2_test.dart': null,
};
void main(List<String> arguments) {
checkWarnings(TESTS, arguments);
}

View File

@ -1,158 +1,158 @@
// 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 mixin_typevariable_test;
import 'package:expect/expect.dart';
import "package:async_helper/async_helper.dart";
import 'type_test_helper.dart';
import 'package:compiler/src/dart_types.dart';
import "package:compiler/src/elements/elements.dart"
show Element, ClassElement;
void main() {
testMixinSupertypes();
testNonTrivialSubstitutions();
}
void testMixinSupertypes() {
asyncTest(() => TypeEnvironment.create(r"""
class S<S_T> {}
class M1<M1_T> {}
class M2<M2_T> {}
class M3<M3_T> {}
class C1<C1_T> extends S<C1_T> with M1<C1_T>, M2<C1_T>, M3<C1_T> {}
class C2<C2_T> = S<C2_T> with M1<C2_T>, M2<C2_T>, M3<C2_T>;
""", expectNoWarningsOrErrors: true).then((env) {
ClassElement Object = env.getElement('Object');
ClassElement S = env.getElement('S');
ClassElement M1 = env.getElement('M1');
ClassElement M2 = env.getElement('M2');
ClassElement M3 = env.getElement('M3');
ClassElement C1 = env.getElement('C1');
ClassElement C2 = env.getElement('C2');
ClassElement C1_S_M1_M2_M3 = C1.superclass;
ClassElement C1_S_M1_M2 = C1_S_M1_M2_M3.superclass;
ClassElement C1_S_M1 = C1_S_M1_M2.superclass;
ClassElement C2_S_M1_M2 = C2.superclass;
ClassElement C2_S_M1 = C2_S_M1_M2.superclass;
void testSupertypes(ClassElement element) {
if (element != Object) {
Expect.isTrue(element.typeVariables.length == 1);
Expect.equals(element,
element.typeVariables.first.element.enclosingElement);
}
for (InterfaceType supertype in element.allSupertypesAndSelf.types) {
if (!supertype.typeArguments.isEmpty) {
Expect.listEquals(element.typeVariables, supertype.typeArguments,
"Type argument mismatch on supertype $supertype of $element.");
} else {
Expect.equals(Object, supertype.element);
}
}
}
testSupertypes(Object);
testSupertypes(S);
testSupertypes(M1);
testSupertypes(M2);
testSupertypes(C1_S_M1);
testSupertypes(C1_S_M1_M2);
testSupertypes(C1_S_M1_M2_M3);
testSupertypes(C1);
testSupertypes(C2_S_M1);
testSupertypes(C2_S_M1_M2);
testSupertypes(C2);
}));
}
void testNonTrivialSubstitutions() {
asyncTest(() => TypeEnvironment.create(r"""
class _ {}
class A<A_T> {}
class B<B_T, B_S> {}
class C1<C1_T> extends A with B {}
class C2<C2_T> = A with B;
class D1<D1_T> extends A<D1_T> with B<D1_T, A<D1_T>> {}
class D2<D2_T> = A<D2_T> with B<D2_T, A<D2_T>>;
class E1<E1_T> extends A<_> with B<_, A<_>> {}
class E2<E2_T> = A<_> with B<_, A<_>>;
class F1<F1_T> extends A<_> with B<_, B<F1_T, _>> {}
class F2<F2_T> = A<_> with B<_, B<F2_T, _>>;
""", expectNoWarningsOrErrors: true).then((env) {
DartType _dynamic = env['dynamic'];
DartType _ = env['_'];
ClassElement Object = env.getElement('Object');
ClassElement A = env.getElement('A');
ClassElement B = env.getElement('B');
ClassElement C1 = env.getElement('C1');
ClassElement C2 = env.getElement('C2');
ClassElement D1 = env.getElement('D1');
ClassElement D2 = env.getElement('D2');
ClassElement E1 = env.getElement('E1');
ClassElement E2 = env.getElement('E2');
ClassElement F1 = env.getElement('F1');
ClassElement F2 = env.getElement('F2');
ClassElement C1_A_B = C1.superclass;
ClassElement D1_A_B = D1.superclass;
ClassElement E1_A_B = E1.superclass;
ClassElement F1_A_B = F1.superclass;
void testSupertypes(ClassElement element,
Map<ClassElement, List<DartType>> typeArguments) {
if (element != Object) {
Expect.isTrue(element.typeVariables.length == 1);
Expect.equals(element,
element.typeVariables.first.element.enclosingElement);
}
for (InterfaceType supertype in element.allSupertypesAndSelf.types) {
if (typeArguments.containsKey(supertype.element)) {
Expect.listEquals(typeArguments[supertype.element],
supertype.typeArguments,
"Type argument mismatch on supertype $supertype of $element.");
} else if (!supertype.typeArguments.isEmpty) {
Expect.listEquals(element.typeVariables, supertype.typeArguments,
"Type argument mismatch on supertype $supertype of $element.");
} else {
Expect.equals(Object, supertype.element);
}
}
}
testSupertypes(C1, {A: [_dynamic], B: [_dynamic, _dynamic]});
testSupertypes(C1.superclass, {A: [_dynamic], B: [_dynamic, _dynamic]});
testSupertypes(C2, {A: [_dynamic], B: [_dynamic, _dynamic]});
DartType D1_T = D1.typeVariables.first;
testSupertypes(D1, {A: [D1_T], B: [D1_T, instantiate(A, [D1_T])]});
DartType D1_superclass_T = D1.superclass.typeVariables.first;
testSupertypes(D1.superclass,
{A: [D1_superclass_T],
B: [D1_superclass_T, instantiate(A, [D1_superclass_T])]});
DartType D2_T = D2.typeVariables.first;
testSupertypes(D2, {A: [D2_T], B: [D2_T, instantiate(A, [D2_T])]});
testSupertypes(E1, {A: [_], B: [_, instantiate(A, [_])]});
testSupertypes(E1.superclass, {A: [_], B: [_, instantiate(A, [_])]});
testSupertypes(E2, {A: [_], B: [_, instantiate(A, [_])]});
DartType F1_T = F1.typeVariables.first;
testSupertypes(F1, {A: [_], B: [_, instantiate(B, [F1_T, _])]});
DartType F1_superclass_T = F1.superclass.typeVariables.first;
testSupertypes(F1.superclass, {A: [_], B: [_, instantiate(B, [F1_superclass_T, _])]});
DartType F2_T = F2.typeVariables.first;
testSupertypes(F2, {A: [_], B: [_, instantiate(B, [F2_T, _])]});
}));
}
// 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 mixin_typevariable_test;
import 'package:expect/expect.dart';
import "package:async_helper/async_helper.dart";
import 'type_test_helper.dart';
import 'package:compiler/src/dart_types.dart';
import "package:compiler/src/elements/elements.dart"
show Element, ClassElement;
void main() {
testMixinSupertypes();
testNonTrivialSubstitutions();
}
void testMixinSupertypes() {
asyncTest(() => TypeEnvironment.create(r"""
class S<S_T> {}
class M1<M1_T> {}
class M2<M2_T> {}
class M3<M3_T> {}
class C1<C1_T> extends S<C1_T> with M1<C1_T>, M2<C1_T>, M3<C1_T> {}
class C2<C2_T> = S<C2_T> with M1<C2_T>, M2<C2_T>, M3<C2_T>;
""", expectNoWarningsOrErrors: true).then((env) {
ClassElement Object = env.getElement('Object');
ClassElement S = env.getElement('S');
ClassElement M1 = env.getElement('M1');
ClassElement M2 = env.getElement('M2');
ClassElement M3 = env.getElement('M3');
ClassElement C1 = env.getElement('C1');
ClassElement C2 = env.getElement('C2');
ClassElement C1_S_M1_M2_M3 = C1.superclass;
ClassElement C1_S_M1_M2 = C1_S_M1_M2_M3.superclass;
ClassElement C1_S_M1 = C1_S_M1_M2.superclass;
ClassElement C2_S_M1_M2 = C2.superclass;
ClassElement C2_S_M1 = C2_S_M1_M2.superclass;
void testSupertypes(ClassElement element) {
if (element != Object) {
Expect.isTrue(element.typeVariables.length == 1);
Expect.equals(element,
element.typeVariables.first.element.enclosingElement);
}
for (InterfaceType supertype in element.allSupertypesAndSelf.types) {
if (!supertype.typeArguments.isEmpty) {
Expect.listEquals(element.typeVariables, supertype.typeArguments,
"Type argument mismatch on supertype $supertype of $element.");
} else {
Expect.equals(Object, supertype.element);
}
}
}
testSupertypes(Object);
testSupertypes(S);
testSupertypes(M1);
testSupertypes(M2);
testSupertypes(C1_S_M1);
testSupertypes(C1_S_M1_M2);
testSupertypes(C1_S_M1_M2_M3);
testSupertypes(C1);
testSupertypes(C2_S_M1);
testSupertypes(C2_S_M1_M2);
testSupertypes(C2);
}));
}
void testNonTrivialSubstitutions() {
asyncTest(() => TypeEnvironment.create(r"""
class _ {}
class A<A_T> {}
class B<B_T, B_S> {}
class C1<C1_T> extends A with B {}
class C2<C2_T> = A with B;
class D1<D1_T> extends A<D1_T> with B<D1_T, A<D1_T>> {}
class D2<D2_T> = A<D2_T> with B<D2_T, A<D2_T>>;
class E1<E1_T> extends A<_> with B<_, A<_>> {}
class E2<E2_T> = A<_> with B<_, A<_>>;
class F1<F1_T> extends A<_> with B<_, B<F1_T, _>> {}
class F2<F2_T> = A<_> with B<_, B<F2_T, _>>;
""", expectNoWarningsOrErrors: true).then((env) {
DartType _dynamic = env['dynamic'];
DartType _ = env['_'];
ClassElement Object = env.getElement('Object');
ClassElement A = env.getElement('A');
ClassElement B = env.getElement('B');
ClassElement C1 = env.getElement('C1');
ClassElement C2 = env.getElement('C2');
ClassElement D1 = env.getElement('D1');
ClassElement D2 = env.getElement('D2');
ClassElement E1 = env.getElement('E1');
ClassElement E2 = env.getElement('E2');
ClassElement F1 = env.getElement('F1');
ClassElement F2 = env.getElement('F2');
ClassElement C1_A_B = C1.superclass;
ClassElement D1_A_B = D1.superclass;
ClassElement E1_A_B = E1.superclass;
ClassElement F1_A_B = F1.superclass;
void testSupertypes(ClassElement element,
Map<ClassElement, List<DartType>> typeArguments) {
if (element != Object) {
Expect.isTrue(element.typeVariables.length == 1);
Expect.equals(element,
element.typeVariables.first.element.enclosingElement);
}
for (InterfaceType supertype in element.allSupertypesAndSelf.types) {
if (typeArguments.containsKey(supertype.element)) {
Expect.listEquals(typeArguments[supertype.element],
supertype.typeArguments,
"Type argument mismatch on supertype $supertype of $element.");
} else if (!supertype.typeArguments.isEmpty) {
Expect.listEquals(element.typeVariables, supertype.typeArguments,
"Type argument mismatch on supertype $supertype of $element.");
} else {
Expect.equals(Object, supertype.element);
}
}
}
testSupertypes(C1, {A: [_dynamic], B: [_dynamic, _dynamic]});
testSupertypes(C1.superclass, {A: [_dynamic], B: [_dynamic, _dynamic]});
testSupertypes(C2, {A: [_dynamic], B: [_dynamic, _dynamic]});
DartType D1_T = D1.typeVariables.first;
testSupertypes(D1, {A: [D1_T], B: [D1_T, instantiate(A, [D1_T])]});
DartType D1_superclass_T = D1.superclass.typeVariables.first;
testSupertypes(D1.superclass,
{A: [D1_superclass_T],
B: [D1_superclass_T, instantiate(A, [D1_superclass_T])]});
DartType D2_T = D2.typeVariables.first;
testSupertypes(D2, {A: [D2_T], B: [D2_T, instantiate(A, [D2_T])]});
testSupertypes(E1, {A: [_], B: [_, instantiate(A, [_])]});
testSupertypes(E1.superclass, {A: [_], B: [_, instantiate(A, [_])]});
testSupertypes(E2, {A: [_], B: [_, instantiate(A, [_])]});
DartType F1_T = F1.typeVariables.first;
testSupertypes(F1, {A: [_], B: [_, instantiate(B, [F1_T, _])]});
DartType F1_superclass_T = F1.superclass.typeVariables.first;
testSupertypes(F1.superclass, {A: [_], B: [_, instantiate(B, [F1_superclass_T, _])]});
DartType F2_T = F2.typeVariables.first;
testSupertypes(F2, {A: [_], B: [_, instantiate(B, [F2_T, _])]});
}));
}

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,22 @@
// 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.
// Test that dart2js produces the expected static type warnings for proxy
// language tests. This ensures that the analyzer and dart2js agrees on these
// tests.
import 'warnings_checker.dart';
/// Map from test files to a map of their expected status. If the status map is
/// `null` no warnings must be missing or unexpected, otherwise the status map
/// can contain a list of line numbers for keys 'missing' and 'unexpected' for
/// the warnings of each category.
const Map<String, dynamic> TESTS = const {
'language/proxy_test.dart': null,
'language/proxy2_test.dart': null,
};
void main() {
checkWarnings(TESTS);
}
// 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.
// Test that dart2js produces the expected static type warnings for proxy
// language tests. This ensures that the analyzer and dart2js agrees on these
// tests.
import 'warnings_checker.dart';
/// Map from test files to a map of their expected status. If the status map is
/// `null` no warnings must be missing or unexpected, otherwise the status map
/// can contain a list of line numbers for keys 'missing' and 'unexpected' for
/// the warnings of each category.
const Map<String, dynamic> TESTS = const {
'language/proxy_test.dart': null,
'language/proxy2_test.dart': null,
};
void main() {
checkWarnings(TESTS);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,483 +1,483 @@
// Copyright (c) 2015, 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.
part of dart2js.semantics_visitor_test;
class SemanticDeclarationTestVisitor extends SemanticTestVisitor {
SemanticDeclarationTestVisitor(TreeElements elements) : super(elements);
@override
errorUnresolvedSuperConstructorInvoke(
Send node,
Element element,
NodeList arguments,
Selector selector,
arg) {
// TODO: implement errorUnresolvedSuperConstructorInvoke
}
@override
errorUnresolvedThisConstructorInvoke(
Send node,
Element element,
NodeList arguments,
Selector selector,
arg) {
// TODO: implement errorUnresolvedThisConstructorInvoke
}
@override
visitAbstractMethodDeclaration(
FunctionExpression node,
MethodElement method,
NodeList parameters,
arg) {
visits.add(new Visit(VisitKind.VISIT_ABSTRACT_METHOD_DECL,
element: method, parameters: parameters));
applyParameters(parameters, arg);
}
@override
visitClosureDeclaration(
FunctionExpression node,
LocalFunctionElement function,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_CLOSURE_DECL,
element: function, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitFactoryConstructorDeclaration(
FunctionExpression node,
ConstructorElement constructor,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_FACTORY_CONSTRUCTOR_DECL,
element: constructor, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitFieldInitializer(
SendSet node,
FieldElement field,
Node initializer,
arg) {
visits.add(new Visit(VisitKind.VISIT_FIELD_INITIALIZER,
element: field, rhs: initializer));
apply(initializer, arg);
}
@override
visitGenerativeConstructorDeclaration(
FunctionExpression node,
ConstructorElement constructor,
NodeList parameters,
NodeList initializers,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_GENERATIVE_CONSTRUCTOR_DECL,
element: constructor, parameters: parameters, body: body));
applyParameters(parameters, arg);
applyInitializers(node, arg);
apply(body, arg);
}
@override
visitInstanceMethodDeclaration(
FunctionExpression node,
MethodElement method,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_INSTANCE_METHOD_DECL,
element: method, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitLocalFunctionDeclaration(
FunctionExpression node,
LocalFunctionElement function,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_LOCAL_FUNCTION_DECL,
element: function, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitRedirectingFactoryConstructorDeclaration(
FunctionExpression node,
ConstructorElement constructor,
NodeList parameters,
InterfaceType redirectionType,
ConstructorElement redirectionTarget,
arg) {
visits.add(new Visit(
VisitKind.VISIT_REDIRECTING_FACTORY_CONSTRUCTOR_DECL,
element: constructor,
parameters: parameters,
target: redirectionTarget,
type: redirectionType));
applyParameters(parameters, arg);
}
@override
visitRedirectingGenerativeConstructorDeclaration(
FunctionExpression node,
ConstructorElement constructor,
NodeList parameters,
NodeList initializers,
arg) {
visits.add(new Visit(
VisitKind.VISIT_REDIRECTING_GENERATIVE_CONSTRUCTOR_DECL,
element: constructor,
parameters: parameters,
initializers: initializers));
applyParameters(parameters, arg);
applyInitializers(node, arg);
}
@override
visitStaticFunctionDeclaration(
FunctionExpression node,
MethodElement function,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_STATIC_FUNCTION_DECL,
element: function, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitSuperConstructorInvoke(
Send node,
ConstructorElement superConstructor,
InterfaceType type,
NodeList arguments,
CallStructure callStructure,
arg) {
visits.add(new Visit(VisitKind.VISIT_SUPER_CONSTRUCTOR_INVOKE,
element: superConstructor, type: type,
arguments: arguments, selector: callStructure));
super.visitSuperConstructorInvoke(
node, superConstructor, type, arguments, callStructure, arg);
}
@override
visitImplicitSuperConstructorInvoke(
FunctionExpression node,
ConstructorElement superConstructor,
InterfaceType type,
arg) {
visits.add(new Visit(VisitKind.VISIT_IMPLICIT_SUPER_CONSTRUCTOR_INVOKE,
element: superConstructor, type: type));
super.visitImplicitSuperConstructorInvoke(
node, superConstructor, type, arg);
}
@override
visitThisConstructorInvoke(
Send node,
ConstructorElement thisConstructor,
NodeList arguments,
CallStructure callStructure,
arg) {
visits.add(new Visit(VisitKind.VISIT_THIS_CONSTRUCTOR_INVOKE,
element: thisConstructor,
arguments: arguments, selector: callStructure));
super.visitThisConstructorInvoke(
node, thisConstructor, arguments, callStructure, arg);
}
@override
visitTopLevelFunctionDeclaration(
FunctionExpression node,
MethodElement function,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_TOP_LEVEL_FUNCTION_DECL,
element: function, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
errorUnresolvedFieldInitializer(
SendSet node,
Element element,
Node initializer,
arg) {
// TODO: implement errorUnresolvedFieldInitializer
}
@override
visitOptionalParameterDeclaration(
VariableDefinitions node,
Node definition,
ParameterElement parameter,
ConstantExpression defaultValue,
int index,
arg) {
visits.add(new Visit(VisitKind.VISIT_OPTIONAL_PARAMETER_DECL,
element: parameter,
constant: defaultValue != null ? defaultValue.getText() : null,
index: index));
}
@override
visitParameterDeclaration(
VariableDefinitions node,
Node definition,
ParameterElement parameter,
int index,
arg) {
visits.add(new Visit(VisitKind.VISIT_REQUIRED_PARAMETER_DECL,
element: parameter, index: index));
}
@override
visitInitializingFormalDeclaration(
VariableDefinitions node,
Node definition,
InitializingFormalElement initializingFormal,
int index,
arg) {
visits.add(new Visit(VisitKind.VISIT_REQUIRED_INITIALIZING_FORMAL_DECL,
element: initializingFormal, index: index));
}
@override
visitLocalVariableDeclaration(
VariableDefinitions node,
Node definition,
LocalVariableElement variable,
Node initializer,
arg) {
visits.add(new Visit(VisitKind.VISIT_LOCAL_VARIABLE_DECL,
element: variable, rhs: initializer));
if (initializer != null) {
apply(initializer, arg);
}
}
@override
visitLocalConstantDeclaration(
VariableDefinitions node,
Node definition,
LocalVariableElement variable,
ConstantExpression constant,
arg) {
visits.add(new Visit(VisitKind.VISIT_LOCAL_CONSTANT_DECL,
element: variable, constant: constant.getText()));
}
@override
visitNamedInitializingFormalDeclaration(
VariableDefinitions node,
Node definition,
InitializingFormalElement initializingFormal,
ConstantExpression defaultValue,
arg) {
visits.add(new Visit(VisitKind.VISIT_NAMED_INITIALIZING_FORMAL_DECL,
element: initializingFormal,
constant: defaultValue != null ? defaultValue.getText() : null));
}
@override
visitNamedParameterDeclaration(
VariableDefinitions node,
Node definition,
ParameterElement parameter,
ConstantExpression defaultValue,
arg) {
visits.add(new Visit(VisitKind.VISIT_NAMED_PARAMETER_DECL,
element: parameter,
constant: defaultValue != null ? defaultValue.getText() : null));
}
@override
visitOptionalInitializingFormalDeclaration(
VariableDefinitions node,
Node definition,
InitializingFormalElement initializingFormal,
ConstantExpression defaultValue,
int index,
arg) {
visits.add(new Visit(VisitKind.VISIT_OPTIONAL_INITIALIZING_FORMAL_DECL,
element: initializingFormal,
constant: defaultValue != null ? defaultValue.getText() : null,
index: index));
}
@override
visitInstanceFieldDeclaration(
VariableDefinitions node,
Node definition,
FieldElement field,
Node initializer,
arg) {
visits.add(new Visit(VisitKind.VISIT_INSTANCE_FIELD_DECL,
element: field, rhs: initializer));
if (initializer != null) {
apply(initializer, arg);
}
}
@override
visitStaticConstantDeclaration(
VariableDefinitions node,
Node definition,
FieldElement field,
ConstantExpression constant,
arg) {
visits.add(new Visit(VisitKind.VISIT_STATIC_CONSTANT_DECL,
element: field, constant: constant.getText()));
}
@override
visitStaticFieldDeclaration(
VariableDefinitions node,
Node definition,
FieldElement field,
Node initializer,
arg) {
visits.add(new Visit(VisitKind.VISIT_STATIC_FIELD_DECL,
element: field, rhs: initializer));
if (initializer != null) {
apply(initializer, arg);
}
}
@override
visitTopLevelConstantDeclaration(
VariableDefinitions node,
Node definition,
FieldElement field,
ConstantExpression constant,
arg) {
visits.add(new Visit(VisitKind.VISIT_TOP_LEVEL_CONSTANT_DECL,
element: field, constant: constant.getText()));
}
@override
visitTopLevelFieldDeclaration(
VariableDefinitions node,
Node definition,
FieldElement field,
Node initializer,
arg) {
visits.add(new Visit(VisitKind.VISIT_TOP_LEVEL_FIELD_DECL,
element: field, rhs: initializer));
if (initializer != null) {
apply(initializer, arg);
}
}
@override
visitAbstractGetterDeclaration(
FunctionExpression node,
MethodElement getter,
arg) {
visits.add(new Visit(VisitKind.VISIT_ABSTRACT_GETTER_DECL,
element: getter));
}
@override
visitAbstractSetterDeclaration(
FunctionExpression node,
MethodElement setter,
NodeList parameters,
arg) {
visits.add(new Visit(VisitKind.VISIT_ABSTRACT_SETTER_DECL,
element: setter, parameters: parameters));
applyParameters(parameters, arg);
}
@override
visitInstanceGetterDeclaration(
FunctionExpression node,
MethodElement getter,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_INSTANCE_GETTER_DECL,
element: getter, body: body));
apply(body, arg);
}
@override
visitInstanceSetterDeclaration(
FunctionExpression node,
MethodElement setter,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_INSTANCE_SETTER_DECL,
element: setter, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitTopLevelGetterDeclaration(
FunctionExpression node,
MethodElement getter,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_TOP_LEVEL_GETTER_DECL,
element: getter, body: body));
apply(body, arg);
}
@override
visitTopLevelSetterDeclaration(
FunctionExpression node,
MethodElement setter,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_TOP_LEVEL_SETTER_DECL,
element: setter, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitStaticGetterDeclaration(
FunctionExpression node,
MethodElement getter,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_STATIC_GETTER_DECL,
element: getter, body: body));
apply(body, arg);
}
@override
visitStaticSetterDeclaration(
FunctionExpression node,
MethodElement setter,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_STATIC_SETTER_DECL,
element: setter, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
}
// Copyright (c) 2015, 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.
part of dart2js.semantics_visitor_test;
class SemanticDeclarationTestVisitor extends SemanticTestVisitor {
SemanticDeclarationTestVisitor(TreeElements elements) : super(elements);
@override
errorUnresolvedSuperConstructorInvoke(
Send node,
Element element,
NodeList arguments,
Selector selector,
arg) {
// TODO: implement errorUnresolvedSuperConstructorInvoke
}
@override
errorUnresolvedThisConstructorInvoke(
Send node,
Element element,
NodeList arguments,
Selector selector,
arg) {
// TODO: implement errorUnresolvedThisConstructorInvoke
}
@override
visitAbstractMethodDeclaration(
FunctionExpression node,
MethodElement method,
NodeList parameters,
arg) {
visits.add(new Visit(VisitKind.VISIT_ABSTRACT_METHOD_DECL,
element: method, parameters: parameters));
applyParameters(parameters, arg);
}
@override
visitClosureDeclaration(
FunctionExpression node,
LocalFunctionElement function,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_CLOSURE_DECL,
element: function, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitFactoryConstructorDeclaration(
FunctionExpression node,
ConstructorElement constructor,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_FACTORY_CONSTRUCTOR_DECL,
element: constructor, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitFieldInitializer(
SendSet node,
FieldElement field,
Node initializer,
arg) {
visits.add(new Visit(VisitKind.VISIT_FIELD_INITIALIZER,
element: field, rhs: initializer));
apply(initializer, arg);
}
@override
visitGenerativeConstructorDeclaration(
FunctionExpression node,
ConstructorElement constructor,
NodeList parameters,
NodeList initializers,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_GENERATIVE_CONSTRUCTOR_DECL,
element: constructor, parameters: parameters, body: body));
applyParameters(parameters, arg);
applyInitializers(node, arg);
apply(body, arg);
}
@override
visitInstanceMethodDeclaration(
FunctionExpression node,
MethodElement method,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_INSTANCE_METHOD_DECL,
element: method, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitLocalFunctionDeclaration(
FunctionExpression node,
LocalFunctionElement function,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_LOCAL_FUNCTION_DECL,
element: function, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitRedirectingFactoryConstructorDeclaration(
FunctionExpression node,
ConstructorElement constructor,
NodeList parameters,
InterfaceType redirectionType,
ConstructorElement redirectionTarget,
arg) {
visits.add(new Visit(
VisitKind.VISIT_REDIRECTING_FACTORY_CONSTRUCTOR_DECL,
element: constructor,
parameters: parameters,
target: redirectionTarget,
type: redirectionType));
applyParameters(parameters, arg);
}
@override
visitRedirectingGenerativeConstructorDeclaration(
FunctionExpression node,
ConstructorElement constructor,
NodeList parameters,
NodeList initializers,
arg) {
visits.add(new Visit(
VisitKind.VISIT_REDIRECTING_GENERATIVE_CONSTRUCTOR_DECL,
element: constructor,
parameters: parameters,
initializers: initializers));
applyParameters(parameters, arg);
applyInitializers(node, arg);
}
@override
visitStaticFunctionDeclaration(
FunctionExpression node,
MethodElement function,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_STATIC_FUNCTION_DECL,
element: function, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitSuperConstructorInvoke(
Send node,
ConstructorElement superConstructor,
InterfaceType type,
NodeList arguments,
CallStructure callStructure,
arg) {
visits.add(new Visit(VisitKind.VISIT_SUPER_CONSTRUCTOR_INVOKE,
element: superConstructor, type: type,
arguments: arguments, selector: callStructure));
super.visitSuperConstructorInvoke(
node, superConstructor, type, arguments, callStructure, arg);
}
@override
visitImplicitSuperConstructorInvoke(
FunctionExpression node,
ConstructorElement superConstructor,
InterfaceType type,
arg) {
visits.add(new Visit(VisitKind.VISIT_IMPLICIT_SUPER_CONSTRUCTOR_INVOKE,
element: superConstructor, type: type));
super.visitImplicitSuperConstructorInvoke(
node, superConstructor, type, arg);
}
@override
visitThisConstructorInvoke(
Send node,
ConstructorElement thisConstructor,
NodeList arguments,
CallStructure callStructure,
arg) {
visits.add(new Visit(VisitKind.VISIT_THIS_CONSTRUCTOR_INVOKE,
element: thisConstructor,
arguments: arguments, selector: callStructure));
super.visitThisConstructorInvoke(
node, thisConstructor, arguments, callStructure, arg);
}
@override
visitTopLevelFunctionDeclaration(
FunctionExpression node,
MethodElement function,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_TOP_LEVEL_FUNCTION_DECL,
element: function, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
errorUnresolvedFieldInitializer(
SendSet node,
Element element,
Node initializer,
arg) {
// TODO: implement errorUnresolvedFieldInitializer
}
@override
visitOptionalParameterDeclaration(
VariableDefinitions node,
Node definition,
ParameterElement parameter,
ConstantExpression defaultValue,
int index,
arg) {
visits.add(new Visit(VisitKind.VISIT_OPTIONAL_PARAMETER_DECL,
element: parameter,
constant: defaultValue != null ? defaultValue.getText() : null,
index: index));
}
@override
visitParameterDeclaration(
VariableDefinitions node,
Node definition,
ParameterElement parameter,
int index,
arg) {
visits.add(new Visit(VisitKind.VISIT_REQUIRED_PARAMETER_DECL,
element: parameter, index: index));
}
@override
visitInitializingFormalDeclaration(
VariableDefinitions node,
Node definition,
InitializingFormalElement initializingFormal,
int index,
arg) {
visits.add(new Visit(VisitKind.VISIT_REQUIRED_INITIALIZING_FORMAL_DECL,
element: initializingFormal, index: index));
}
@override
visitLocalVariableDeclaration(
VariableDefinitions node,
Node definition,
LocalVariableElement variable,
Node initializer,
arg) {
visits.add(new Visit(VisitKind.VISIT_LOCAL_VARIABLE_DECL,
element: variable, rhs: initializer));
if (initializer != null) {
apply(initializer, arg);
}
}
@override
visitLocalConstantDeclaration(
VariableDefinitions node,
Node definition,
LocalVariableElement variable,
ConstantExpression constant,
arg) {
visits.add(new Visit(VisitKind.VISIT_LOCAL_CONSTANT_DECL,
element: variable, constant: constant.getText()));
}
@override
visitNamedInitializingFormalDeclaration(
VariableDefinitions node,
Node definition,
InitializingFormalElement initializingFormal,
ConstantExpression defaultValue,
arg) {
visits.add(new Visit(VisitKind.VISIT_NAMED_INITIALIZING_FORMAL_DECL,
element: initializingFormal,
constant: defaultValue != null ? defaultValue.getText() : null));
}
@override
visitNamedParameterDeclaration(
VariableDefinitions node,
Node definition,
ParameterElement parameter,
ConstantExpression defaultValue,
arg) {
visits.add(new Visit(VisitKind.VISIT_NAMED_PARAMETER_DECL,
element: parameter,
constant: defaultValue != null ? defaultValue.getText() : null));
}
@override
visitOptionalInitializingFormalDeclaration(
VariableDefinitions node,
Node definition,
InitializingFormalElement initializingFormal,
ConstantExpression defaultValue,
int index,
arg) {
visits.add(new Visit(VisitKind.VISIT_OPTIONAL_INITIALIZING_FORMAL_DECL,
element: initializingFormal,
constant: defaultValue != null ? defaultValue.getText() : null,
index: index));
}
@override
visitInstanceFieldDeclaration(
VariableDefinitions node,
Node definition,
FieldElement field,
Node initializer,
arg) {
visits.add(new Visit(VisitKind.VISIT_INSTANCE_FIELD_DECL,
element: field, rhs: initializer));
if (initializer != null) {
apply(initializer, arg);
}
}
@override
visitStaticConstantDeclaration(
VariableDefinitions node,
Node definition,
FieldElement field,
ConstantExpression constant,
arg) {
visits.add(new Visit(VisitKind.VISIT_STATIC_CONSTANT_DECL,
element: field, constant: constant.getText()));
}
@override
visitStaticFieldDeclaration(
VariableDefinitions node,
Node definition,
FieldElement field,
Node initializer,
arg) {
visits.add(new Visit(VisitKind.VISIT_STATIC_FIELD_DECL,
element: field, rhs: initializer));
if (initializer != null) {
apply(initializer, arg);
}
}
@override
visitTopLevelConstantDeclaration(
VariableDefinitions node,
Node definition,
FieldElement field,
ConstantExpression constant,
arg) {
visits.add(new Visit(VisitKind.VISIT_TOP_LEVEL_CONSTANT_DECL,
element: field, constant: constant.getText()));
}
@override
visitTopLevelFieldDeclaration(
VariableDefinitions node,
Node definition,
FieldElement field,
Node initializer,
arg) {
visits.add(new Visit(VisitKind.VISIT_TOP_LEVEL_FIELD_DECL,
element: field, rhs: initializer));
if (initializer != null) {
apply(initializer, arg);
}
}
@override
visitAbstractGetterDeclaration(
FunctionExpression node,
MethodElement getter,
arg) {
visits.add(new Visit(VisitKind.VISIT_ABSTRACT_GETTER_DECL,
element: getter));
}
@override
visitAbstractSetterDeclaration(
FunctionExpression node,
MethodElement setter,
NodeList parameters,
arg) {
visits.add(new Visit(VisitKind.VISIT_ABSTRACT_SETTER_DECL,
element: setter, parameters: parameters));
applyParameters(parameters, arg);
}
@override
visitInstanceGetterDeclaration(
FunctionExpression node,
MethodElement getter,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_INSTANCE_GETTER_DECL,
element: getter, body: body));
apply(body, arg);
}
@override
visitInstanceSetterDeclaration(
FunctionExpression node,
MethodElement setter,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_INSTANCE_SETTER_DECL,
element: setter, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitTopLevelGetterDeclaration(
FunctionExpression node,
MethodElement getter,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_TOP_LEVEL_GETTER_DECL,
element: getter, body: body));
apply(body, arg);
}
@override
visitTopLevelSetterDeclaration(
FunctionExpression node,
MethodElement setter,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_TOP_LEVEL_SETTER_DECL,
element: setter, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
@override
visitStaticGetterDeclaration(
FunctionExpression node,
MethodElement getter,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_STATIC_GETTER_DECL,
element: getter, body: body));
apply(body, arg);
}
@override
visitStaticSetterDeclaration(
FunctionExpression node,
MethodElement setter,
NodeList parameters,
Node body,
arg) {
visits.add(new Visit(VisitKind.VISIT_STATIC_SETTER_DECL,
element: setter, parameters: parameters, body: body));
applyParameters(parameters, arg);
apply(body, arg);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,72 +1,72 @@
// 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 subtype_test;
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'type_test_helper.dart';
import 'package:compiler/src/dart_types.dart';
import "package:compiler/src/elements/elements.dart"
show Element, ClassElement, TypedefElement;
void main() {
asyncTest(() => TypeEnvironment.create(r"""
class A<AT, AS> {}
typedef BS B<BT, BS>(BT t);
class C<CT, CS> extends A<CS, CT> {}
class X {}
class Y {}
class Z {}
""").then((env) {
List types = [];
DartType add(DartType type) {
types.add(type);
return type;
}
DartType dynamic_ = add(env['dynamic']);
DartType void_ = add(env['void']);
ClassElement A = env.getElement('A');
TypedefElement B = env.getElement('B');
ClassElement C = env.getElement('C');
DartType X = add(env['X']);
DartType Y = add(env['Y']);
DartType Z = add(env['Z']);
InterfaceType A_this = add(A.thisType);
InterfaceType A_raw = add(A.rawType);
TypeVariableType AT = add(A_this.typeArguments[0]);
TypeVariableType AS = add(A_this.typeArguments[1]);
InterfaceType A_X_Y = add(instantiate(A, [X, Y]));
InterfaceType A_Y_X = add(instantiate(A, [Y, X]));
TypedefType B_this = add(B.computeType(env.compiler));
TypedefType B_raw = add(B.rawType);
TypeVariableType BT = add(B_this.typeArguments[0]);
TypeVariableType BS = add(B_this.typeArguments[1]);
FunctionType B_this_alias = add(B.alias);
TypedefType B_X_Y = add(instantiate(B, [X, Y]));
FunctionType B_X_Y_alias = add(B_X_Y.unalias(env.compiler));
TypedefType B_Y_X = add(instantiate(B, [Y, X]));
FunctionType B_Y_X_alias = add(B_Y_X.unalias(env.compiler));
InterfaceType C_this = add(C.thisType);
InterfaceType C_raw = add(C.rawType);
TypeVariableType CT = add(C_this.typeArguments[0]);
TypeVariableType CS = add(C_this.typeArguments[1]);
Expect.listEquals(
[void_, dynamic_,
A_raw, A_this, A_X_Y, A_Y_X, AT, AS,
B_raw, B_this, B_X_Y, B_Y_X, BT, BS,
C_raw, C_this, CT, CS,
X, Y, Z,
B_this_alias, B_Y_X_alias, B_X_Y_alias,
],
Types.sorted(types));
}));
// 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 subtype_test;
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'type_test_helper.dart';
import 'package:compiler/src/dart_types.dart';
import "package:compiler/src/elements/elements.dart"
show Element, ClassElement, TypedefElement;
void main() {
asyncTest(() => TypeEnvironment.create(r"""
class A<AT, AS> {}
typedef BS B<BT, BS>(BT t);
class C<CT, CS> extends A<CS, CT> {}
class X {}
class Y {}
class Z {}
""").then((env) {
List types = [];
DartType add(DartType type) {
types.add(type);
return type;
}
DartType dynamic_ = add(env['dynamic']);
DartType void_ = add(env['void']);
ClassElement A = env.getElement('A');
TypedefElement B = env.getElement('B');
ClassElement C = env.getElement('C');
DartType X = add(env['X']);
DartType Y = add(env['Y']);
DartType Z = add(env['Z']);
InterfaceType A_this = add(A.thisType);
InterfaceType A_raw = add(A.rawType);
TypeVariableType AT = add(A_this.typeArguments[0]);
TypeVariableType AS = add(A_this.typeArguments[1]);
InterfaceType A_X_Y = add(instantiate(A, [X, Y]));
InterfaceType A_Y_X = add(instantiate(A, [Y, X]));
TypedefType B_this = add(B.computeType(env.compiler));
TypedefType B_raw = add(B.rawType);
TypeVariableType BT = add(B_this.typeArguments[0]);
TypeVariableType BS = add(B_this.typeArguments[1]);
FunctionType B_this_alias = add(B.alias);
TypedefType B_X_Y = add(instantiate(B, [X, Y]));
FunctionType B_X_Y_alias = add(B_X_Y.unalias(env.compiler));
TypedefType B_Y_X = add(instantiate(B, [Y, X]));
FunctionType B_Y_X_alias = add(B_Y_X.unalias(env.compiler));
InterfaceType C_this = add(C.thisType);
InterfaceType C_raw = add(C.rawType);
TypeVariableType CT = add(C_this.typeArguments[0]);
TypeVariableType CS = add(C_this.typeArguments[1]);
Expect.listEquals(
[void_, dynamic_,
A_raw, A_this, A_X_Y, A_Y_X, AT, AS,
B_raw, B_this, B_X_Y, B_Y_X, BT, BS,
C_raw, C_this, CT, CS,
X, Y, Z,
B_this_alias, B_Y_X_alias, B_X_Y_alias,
],
Types.sorted(types));
}));
}

View File

@ -1,29 +1,29 @@
// 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.
// Test that dart2js produces the expected static type warnings for type
// promotion language tests. This ensures that the analyzer and dart2js agrees
// on these tests.
import 'warnings_checker.dart';
/// Map from test files to a map of their expected status. If the status map is
/// `null` no warnings must be missing or unexpected, otherwise the status map
/// can contain a list of line numbers for keys 'missing' and 'unexpected' for
/// the warnings of each category.
const Map<String, dynamic> TESTS = const {
'language/type_promotion_assign_test.dart': null,
'language/type_promotion_closure_test.dart': null,
'language/type_promotion_functions_test.dart':
const {'missing': const [62, 63, 64]}, // Issue 14933.
'language/type_promotion_local_test.dart': null,
'language/type_promotion_logical_and_test.dart': null,
'language/type_promotion_more_specific_test.dart': null,
'language/type_promotion_multiple_test.dart': null,
'language/type_promotion_parameter_test.dart': null,
};
void main() {
checkWarnings(TESTS);
}
// 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.
// Test that dart2js produces the expected static type warnings for type
// promotion language tests. This ensures that the analyzer and dart2js agrees
// on these tests.
import 'warnings_checker.dart';
/// Map from test files to a map of their expected status. If the status map is
/// `null` no warnings must be missing or unexpected, otherwise the status map
/// can contain a list of line numbers for keys 'missing' and 'unexpected' for
/// the warnings of each category.
const Map<String, dynamic> TESTS = const {
'language/type_promotion_assign_test.dart': null,
'language/type_promotion_closure_test.dart': null,
'language/type_promotion_functions_test.dart':
const {'missing': const [62, 63, 64]}, // Issue 14933.
'language/type_promotion_local_test.dart': null,
'language/type_promotion_logical_and_test.dart': null,
'language/type_promotion_more_specific_test.dart': null,
'language/type_promotion_multiple_test.dart': null,
'language/type_promotion_parameter_test.dart': null,
};
void main() {
checkWarnings(TESTS);
}

View File

@ -1,83 +1,83 @@
// 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.
// Test that dart2js produces the expected static type warnings to ensures that
// the analyzer and dart2js agrees on the tests.
import 'dart:async';
import 'dart:io';
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'memory_compiler.dart';
import 'package:compiler/src/filenames.dart';
import 'package:compiler/src/io/source_file.dart';
import 'package:compiler/src/source_file_provider.dart';
import 'package:compiler/src/util/uri_extras.dart';
import 'dart:convert';
void checkWarnings(Map<String, dynamic> tests, [List<String> arguments]) {
bool isWindows = Platform.isWindows;
Uri script = currentDirectory.resolveUri(Platform.script);
bool warningsMismatch = false;
bool verbose = arguments != null && arguments.contains('-v');
asyncTest(() => Future.forEach(tests.keys, (String test) {
Uri uri = script.resolve('../../$test');
String source = UTF8.decode(readAll(uriPathToNative(uri.path)));
SourceFile file = new StringSourceFile(
uri, relativize(currentDirectory, uri, isWindows), source);
Map<int,String> expectedWarnings = {};
int lineNo = 0;
for (String line in source.split('\n')) {
if (line.contains('///') &&
(line.contains('static type warning') ||
line.contains('static warning'))) {
expectedWarnings[lineNo] = line;
}
lineNo++;
}
Set<int> unseenWarnings = new Set<int>.from(expectedWarnings.keys);
DiagnosticCollector collector = new DiagnosticCollector();
var compiler = compilerFor(const {},
diagnosticHandler: collector,
options: ['--analyze-only'],
showDiagnostics: verbose);
return compiler.run(uri).then((_) {
Map<String, List<int>> statusMap = tests[test];
// Line numbers with known unexpected warnings.
List<int> unexpectedStatus = [];
if (statusMap != null && statusMap.containsKey('unexpected')) {
unexpectedStatus = statusMap['unexpected'];
}
// Line numbers with known missing warnings.
List<int> missingStatus = [];
if (statusMap != null && statusMap.containsKey('missing')) {
missingStatus = statusMap['missing'];
}
for (DiagnosticMessage message in collector.warnings) {
Expect.equals(uri, message.uri);
int lineNo = file.getLine(message.begin);
if (expectedWarnings.containsKey(lineNo)) {
unseenWarnings.remove(lineNo);
} else if (!unexpectedStatus.contains(lineNo+1)) {
warningsMismatch = true;
print(file.getLocationMessage(
'Unexpected warning: ${message.message}',
message.begin, message.end));
}
}
if (!unseenWarnings.isEmpty) {
for (int lineNo in unseenWarnings) {
if (!missingStatus.contains(lineNo+1)) {
warningsMismatch = true;
String line = expectedWarnings[lineNo];
print('$uri [${lineNo+1}]: Missing static type warning.');
print(line);
}
}
}
});
}).then((_) {
Expect.isFalse(warningsMismatch);
}));
}
// 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.
// Test that dart2js produces the expected static type warnings to ensures that
// the analyzer and dart2js agrees on the tests.
import 'dart:async';
import 'dart:io';
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'memory_compiler.dart';
import 'package:compiler/src/filenames.dart';
import 'package:compiler/src/io/source_file.dart';
import 'package:compiler/src/source_file_provider.dart';
import 'package:compiler/src/util/uri_extras.dart';
import 'dart:convert';
void checkWarnings(Map<String, dynamic> tests, [List<String> arguments]) {
bool isWindows = Platform.isWindows;
Uri script = currentDirectory.resolveUri(Platform.script);
bool warningsMismatch = false;
bool verbose = arguments != null && arguments.contains('-v');
asyncTest(() => Future.forEach(tests.keys, (String test) {
Uri uri = script.resolve('../../$test');
String source = UTF8.decode(readAll(uriPathToNative(uri.path)));
SourceFile file = new StringSourceFile(
uri, relativize(currentDirectory, uri, isWindows), source);
Map<int,String> expectedWarnings = {};
int lineNo = 0;
for (String line in source.split('\n')) {
if (line.contains('///') &&
(line.contains('static type warning') ||
line.contains('static warning'))) {
expectedWarnings[lineNo] = line;
}
lineNo++;
}
Set<int> unseenWarnings = new Set<int>.from(expectedWarnings.keys);
DiagnosticCollector collector = new DiagnosticCollector();
var compiler = compilerFor(const {},
diagnosticHandler: collector,
options: ['--analyze-only'],
showDiagnostics: verbose);
return compiler.run(uri).then((_) {
Map<String, List<int>> statusMap = tests[test];
// Line numbers with known unexpected warnings.
List<int> unexpectedStatus = [];
if (statusMap != null && statusMap.containsKey('unexpected')) {
unexpectedStatus = statusMap['unexpected'];
}
// Line numbers with known missing warnings.
List<int> missingStatus = [];
if (statusMap != null && statusMap.containsKey('missing')) {
missingStatus = statusMap['missing'];
}
for (DiagnosticMessage message in collector.warnings) {
Expect.equals(uri, message.uri);
int lineNo = file.getLine(message.begin);
if (expectedWarnings.containsKey(lineNo)) {
unseenWarnings.remove(lineNo);
} else if (!unexpectedStatus.contains(lineNo+1)) {
warningsMismatch = true;
print(file.getLocationMessage(
'Unexpected warning: ${message.message}',
message.begin, message.end));
}
}
if (!unseenWarnings.isEmpty) {
for (int lineNo in unseenWarnings) {
if (!missingStatus.contains(lineNo+1)) {
warningsMismatch = true;
String line = expectedWarnings[lineNo];
print('$uri [${lineNo+1}]: Missing static type warning.');
print(line);
}
}
}
});
}).then((_) {
Expect.isFalse(warningsMismatch);
}));
}

View File

@ -60,7 +60,7 @@ void testMultiLine() {
Expect.equals("\n", """${''}
""");
Expect.equals("\r", """${''} """);
Expect.equals("\r\n", """${''}
Expect.equals("\r\n", """${''}
""");
Expect.equals("\n", """${'\n'}""");
Expect.equals("\r", """${'\r'}""");

View File

@ -56,7 +56,7 @@ void testMultiLine() {
Expect.equals("\n", """${''}
""");
Expect.equals("\r", """${''} """);
Expect.equals("\r\n", """${''}
Expect.equals("\r\n", """${''}
""");
Expect.equals("\n", """${'\n'}""");
Expect.equals("\r", """${'\r'}""");