Merge pull request #323 from dart-lang/language_tests

add language tests & run them in karma
This commit is contained in:
John Messerly 2015-09-16 16:43:33 -07:00
commit 4c43f3f8bb
1759 changed files with 111257 additions and 155 deletions

View file

@ -29,6 +29,8 @@ module.exports = function(config) {
'test/codegen/expect/unittest/unittest.js',
'test/codegen/expect/syncstar_syntax.js',
'test/codegen/expect/language/*.js',
'test/codegen/expect/language/sub/sub.js',
'test/codegen/expect/language/*.lib',
'test/browser/*.js',
'test-main.js',
],
@ -67,6 +69,9 @@ module.exports = function(config) {
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
browserNoActivityTimeout: 60000,
browserDisconnectTolerance: 5,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
@ -94,7 +99,8 @@ module.exports = function(config) {
flags: [ '--no-sandbox', harmony_flags ]
},
},
browsers: ['chrome_harmony', 'chrome_canary_harmony'],
// TODO(jmesserly): 'chrome_harmony',
browsers: ['chrome_canary_harmony'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits

View file

@ -9,143 +9,356 @@
_isolate_helper.startRootIsolate(function() {}, []);
let async_helper = dart_library.import('async_helper/async_helper');
function dartLanguageTest(name) {
test(name, (done) => {
async_helper.asyncTestInitialize(done);
console.debug('Running language test: ' + name);
dart_library.import('language/' + name).main();
if (!async_helper.asyncTestStarted) done();
});
}
// TODO(jmesserly): separate StrongModeError from other errors.
let expectedFailures = new Set([
'arithmetic2_test',
'assert_with_type_test_or_cast_test',
'assertion_test',
'async_star_await_pauses_test',
'async_star_cancel_while_paused_test',
'async_star_regression_fisk_test',
'async_switch_test',
'asyncstar_throw_in_catch_test',
'await_future_test',
'bit_operations_test_none_multi',
'bit_shift_test',
'bool_test',
'bound_closure_equality_test',
'call_closurization_test',
'call_function_apply_test',
'call_operator_test',
'call_property_test',
'call_test',
'call_this_test',
'call_through_null_getter_test',
'call_with_no_such_method_test',
'canonical_const2_test',
'canonical_const_test',
'cascade_precedence_test',
'cast_test_01_multi',
'cast_test_02_multi',
'cast_test_03_multi',
'cast_test_07_multi',
'cast_test_10_multi',
'cast_test_12_multi',
'cast_test_13_multi',
'cast_test_14_multi',
'cast_test_15_multi',
'cha_deopt1_test',
'cha_deopt2_test',
'cha_deopt3_test',
'classes_static_method_clash_test',
'closure_call_wrong_argument_count_negative_test',
'closure_in_constructor_test',
'closure_with_super_field_test',
'closures_initializer_test',
'code_after_try_is_executed_test_01_multi',
'compile_time_constant10_test_none_multi',
'compile_time_constant_a_test',
'compile_time_constant_b_test',
'compile_time_constant_d_test',
'compile_time_constant_i_test',
'compile_time_constant_k_test_none_multi',
'compile_time_constant_o_test_none_multi',
'const_constructor3_test_03_multi',
'const_escape_frog_test',
'const_evaluation_test_01_multi',
'const_map4_test',
'const_switch_test_02_multi',
'const_switch_test_04_multi',
'constructor11_test',
'constructor12_test',
'ct_const_test',
'cyclic_type2_test',
'cyclic_type_test_00_multi',
'cyclic_type_test_01_multi',
'cyclic_type_test_02_multi',
'cyclic_type_test_03_multi',
'cyclic_type_test_04_multi',
'cyclic_type_variable_test_none_multi',
'deferred_call_empty_before_load_test',
'deferred_closurize_load_library_test',
'deferred_constant_list_test',
'deferred_function_type_test',
'deferred_inlined_test',
'deferred_load_inval_code_test',
'deferred_mixin_test',
'deferred_no_such_method_test',
'deferred_not_loaded_check_test',
'deferred_only_constant_test',
'deferred_optimized_test',
'deferred_redirecting_factory_test',
'deferred_regression_22995_test',
'deferred_shadow_load_library_test',
'deferred_shared_and_unshared_classes_test',
'deferred_static_seperate_test',
'double_int_to_string_test',
'double_to_string_test',
'dynamic_test',
'enum_mirror_test',
'exception_test',
'execute_finally6_test',
'expect_test',
'extends_test_lib',
'external_test_10_multi',
'external_test_13_multi',
'external_test_20_multi',
'f_bounded_equality_test',
'f_bounded_quantification2_test',
'f_bounded_quantification3_test',
'factory_type_parameter_test',
'fast_method_extraction_test',
'field_increment_bailout_test',
'field_optimization3_test',
'field_test',
'final_syntax_test_08_multi',
'first_class_types_literals_test_01_multi',
'first_class_types_literals_test_02_multi',
'first_class_types_literals_test_none_multi',
'first_class_types_test',
'for_in2_test',
'for_variable_capture_test',
'function_propagation_test',
'function_subtype0_test',
'function_subtype1_test',
'function_subtype2_test',
'function_subtype3_test',
'function_subtype_bound_closure0_test',
'function_subtype_bound_closure1_test',
'function_subtype_bound_closure2_test',
'function_subtype_bound_closure3_test',
'function_subtype_bound_closure4_test',
'function_subtype_bound_closure5_test',
'function_subtype_bound_closure5a_test',
'function_subtype_bound_closure6_test',
'function_subtype_call0_test',
'function_subtype_call1_test',
'function_subtype_call2_test',
'function_subtype_cast0_test',
'function_subtype_cast1_test',
'function_subtype_cast2_test',
'function_subtype_cast3_test',
'function_subtype_factory0_test',
'function_subtype_inline0_test',
'function_subtype_local0_test',
'function_subtype_local1_test',
'function_subtype_local2_test',
'function_subtype_local3_test',
'function_subtype_local4_test',
'function_subtype_local5_test',
'function_subtype_named1_test',
'function_subtype_named2_test',
'function_subtype_not0_test',
'function_subtype_not1_test',
'function_subtype_not2_test',
'function_subtype_not3_test',
'function_subtype_optional1_test',
'function_subtype_optional2_test',
'function_subtype_top_level0_test',
'function_subtype_top_level1_test',
'function_subtype_typearg0_test',
'function_subtype_typearg2_test',
'function_subtype_typearg4_test',
'function_type_alias2_test',
'function_type_alias3_test',
'function_type_alias4_test',
'function_type_alias6_test_none_multi',
'function_type_alias_test',
'function_type_call_getter_test',
'gc_test',
'generic2_test',
'generic_deep_test',
'generic_field_mixin2_test',
'generic_field_mixin3_test',
'generic_field_mixin4_test',
'generic_field_mixin5_test',
'generic_field_mixin_test',
'generic_inheritance_test',
'generic_instanceof2_test',
'generic_instanceof3_test',
'generic_instanceof_test',
'generic_is_check_test',
'generic_native_test',
'generic_parameterized_extends_test',
'getter_closure_execution_order_test',
'getter_override2_test_00_multi',
'getters_setters_test',
'hash_code_mangling_test',
'identical_closure2_test',
'if_null_behavior_test_14_multi',
'infinite_switch_label_test',
'infinity_test',
'instance_creation_in_function_annotation_test',
'instanceof2_test',
'instanceof4_test_01_multi',
'instanceof4_test_none_multi',
'instanceof_optimized_test',
'int_test',
'integer_division_by_zero_test',
'interceptor_test',
'is_nan_test',
'issue10747_test',
'issue13179_test',
'issue21079_test',
'issue21957_test',
'issue_1751477_test',
'issue_22780_test_01_multi',
'issue_23914_test',
'js_properties_test',
'lazy_static3_test',
'least_upper_bound_expansive_test_none_multi',
'left_shift_test',
'list_is_test',
'list_literal3_test',
'many_generic_instanceof_test',
'map_literal10_test',
'map_literal7_test',
'memory_swap_test',
'method_invocation_test',
'mint_arithmetic_test',
'mixin_forwarding_constructor3_test',
'mixin_generic_test',
'mixin_implements_test',
'mixin_issue10216_2_test',
'mixin_mixin2_test',
'mixin_mixin3_test',
'mixin_mixin4_test',
'mixin_mixin5_test',
'mixin_mixin6_test',
'mixin_mixin7_test',
'mixin_mixin_bound2_test',
'mixin_mixin_bound_test',
'mixin_mixin_test',
'mixin_regress_13688_test',
'mixin_type_parameter1_test',
'mixin_type_parameter2_test',
'mixin_type_parameter3_test',
'modulo_test',
'named_argument_test',
'named_parameter_clash_test',
'namer2_test',
'nan_identical_test',
'nested_switch_label_test',
'no_such_method3_test',
'no_such_method_empty_selector_test',
'no_such_method_subtype_test',
'null_no_such_method_test',
'number_identifier_test_05_multi',
'number_identity2_test',
'numbers_test',
'operator4_test',
'operator_test',
'optimized_hoisting_checked_mode_assert_test',
'positive_bit_operations_test',
'prefix_test1',
'prefix_test2',
'redirecting_factory_reflection_test',
'regress_13462_0_test',
'regress_13462_1_test',
'regress_14105_test',
'regress_16640_test',
'regress_21795_test',
'regress_22443_test',
'regress_22666_test',
'regress_22719_test',
'regress_23650_test',
'regress_r24720_test',
'setter_no_getter_test_01_multi',
'smi_type_test',
'stack_overflow_stacktrace_test',
'stack_overflow_test',
'stack_trace_test',
'stacktrace_rethrow_error_test_none_multi',
'stacktrace_rethrow_error_test_withtraceparameter_multi',
'stacktrace_test',
'string_interpolate_null_test',
'string_interpolation_newline_test',
'super_field_2_test',
'super_field_test',
'super_operator_index3_test',
'super_operator_index4_test',
'switch_label2_test',
'switch_label_test',
'switch_try_catch_test',
'symbol_literal_test_none_multi',
'sync_generator1_test_none_multi',
'throwing_lazy_variable_test',
'top_level_non_prefixed_library_test',
'truncdiv_test',
'type_argument_substitution_test',
'type_promotion_functions_test_none_multi',
'type_variable_closure2_test',
'type_variable_field_initializer_closure_test',
'type_variable_field_initializer_test',
'type_variable_nested_test',
'type_variable_typedef_test',
'typedef_is_test',
function dartLanguageTests(tests) {
for (let name of tests) {
if (name instanceof Array) {
let multitestName = name[0];
let testCases = name.slice(1);
for (let testCase of testCases) {
if (typeof testCase == 'number') {
testCase = (testCase < 10 ? '0' : '') + testCase;
}
dartLanguageTest(`${multitestName}_${testCase}_multi`);
'bit_operations_test_01_multi',
'bit_operations_test_02_multi',
'bit_operations_test_03_multi',
'bit_operations_test_04_multi',
'bool_condition_check_test_01_multi',
'deferred_constraints_constants_test_none_multi',
'deferred_constraints_constants_test_reference_after_load_multi',
'deferred_constraints_type_annotation_test_new_generic1_multi',
'deferred_constraints_type_annotation_test_new_multi',
'deferred_constraints_type_annotation_test_none_multi',
'deferred_constraints_type_annotation_test_static_method_multi',
'deferred_constraints_type_annotation_test_type_annotation_non_deferred_multi',
'deferred_load_constants_test_none_multi',
'deferred_load_library_wrong_args_test_01_multi',
'deferred_load_library_wrong_args_test_none_multi',
'external_test_21_multi',
'external_test_24_multi',
'main_not_a_function_test_01_multi',
'multiline_newline_test_04_multi',
'multiline_newline_test_05_multi',
'multiline_newline_test_06_multi',
'multiline_newline_test_none_multi',
'no_main_test_01_multi',
]);
suite('language', () => {
let languageTestPattern = new RegExp('language/(.*_test.*)\\.js');
for (let testFile of Object.keys(window.__karma__.files)) {
let match = languageTestPattern.exec(testFile);
if (match != null) {
let name = match[1];
// These two tests are special because they use package:unittest.
// We run them below.
if (name == 'async_await_test' || name.startsWith('async_star_test')) {
continue;
}
} else {
dartLanguageTest(name);
// TODO(jmesserly): figure out why this test is hanging.
if (name == 'async_star_cancel_and_throw_in_finally_test') {
console.debug('Skipping known timeout: ' + name);
continue;
}
// TODO(jmesserly): better tracking of async test failures.
// For now we skip tests that expect failure.
if (expectedFailures.has(name)) {
console.debug('Skipping known failure: ' + name);
continue;
}
test(name, (done) => {
async_helper.asyncTestInitialize(done);
console.debug('Running language test: ' + name);
dart_library.import('language/' + name).main();
if (!async_helper.asyncTestStarted) done();
});
}
}
}
suite('scopes and names', () => {
dartLanguageTests([
'implicit_scope_test',
['built_in_identifier_test', 'none', 1],
'naming3_test'
]);
});
suite('strings', () => {
dartLanguageTests(['optimized_string_charcodeat_test']);
});
suite('method binding', () => {
dartLanguageTests([
['super_bound_closure_test', 'none'],
'method_binding_test'
]);
});
suite('dynamic type literal', () => {
dartLanguageTests([
['const_dynamic_type_literal_test', 'none', 1, 3]
]);
});
suite('cascade', () => {
dartLanguageTests(['cascade_in_expression_function_test']);
});
suite('null aware ops', () => {
dartLanguageTests([
['conditional_method_invocation_test', 'none', 1, 2, 3, 4],
['conditional_property_access_test', 'none', 1, 2, 3],
['conditional_property_assignment_test', 'none', 1, 2, 3, 7, 8, 9],
['conditional_property_increment_decrement_test',
'none', 1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15],
['if_null_assignment_behavior_test', 'none',
1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 31, 32],
['if_null_assignment_static_test', 'none',
1, 3, 5, 8, 10, 12, 15, 17, 19, 22, 24, 26, 29, 31, 33, 36, 38, 40],
'nullaware_opt_test',
['super_conditional_operator_test', 'none'],
['this_conditional_operator_test', 'none']
]);
});
suite('sync*', () => {
test('syncstar_syntax', () => {
dart_library.import('syncstar_syntax').main();
});
dartLanguageTests([
'syncstar_yield_test',
'syncstar_yieldstar_test'
]);
});
dart_library.import('language/async_await_test').main();
suite('async', () => {
dartLanguageTests([
'async_and_or_test',
'async_await_catch_regression_test',
'async_backwards_compatibility_1_test',
'async_backwards_compatibility_2_test',
'async_break_in_finally_test',
// TODO(jmesserly): https://github.com/dart-lang/dev_compiler/issues/263
// 'async_continue_label_test',
'async_control_structures_test',
'async_finally_rethrow_test',
'async_regression_23058_test',
'async_rethrow_test',
// TODO(jmesserly): https://github.com/dart-lang/dev_compiler/issues/294
// 'async_switch_test',
'async_test',
'async_this_bound_test',
'async_throw_in_catch_test'
// By design, rejected statically by strong mode:
// 'async_return_types_test',
// 'async_or_generator_return_type_stacktrace_test',
]);
});
dart_library.import('language/async_await_test_none_multi').main();
dart_library.import('language/async_star_test_none_multi').main();
suite('async*', () => {
dartLanguageTests([
// TODO(jmesserly): figure out why this test is hanging.
//'async_star_cancel_and_throw_in_finally_test',
'async_star_regression_23116_test',
'asyncstar_concat_test',
// TODO(jmesserly): https://github.com/dart-lang/dev_compiler/issues/294
// 'asyncstar_throw_in_catch_test',
'asyncstar_yield_test',
'asyncstar_yieldstar_test'
]);
});
suite('export', () => {
dartLanguageTests([
'duplicate_export_test',
'export_cyclic_test',
'export_double_same_main_test',
'export_main_override_test',
'export_main_test',
'export_test',
'local_export_test',
'reexport_core_test',
'top_level_entry_test'
]);
});
})();

View file

@ -0,0 +1,244 @@
dart_library.library('collection/algorithms', null, /* Imports */[
"dart_runtime/dart",
'dart/core',
'dart/math'
], /* Lazy imports */[
], function(exports, dart, core, math) {
'use strict';
let dartx = dart.dartx;
function _comparableBinarySearch(list, key) {
let min = 0;
let max = list[dartx.length];
while (dart.notNull(min) < dart.notNull(max)) {
let mid = dart.notNull(min) + (dart.notNull(max) - dart.notNull(min) >> 1);
let element = list[dartx.get](mid);
let comp = element[dartx.compareTo](key);
if (comp == 0)
return mid;
if (dart.notNull(comp) < 0) {
min = dart.notNull(mid) + 1;
} else {
max = mid;
}
}
return -1;
}
dart.fn(_comparableBinarySearch, core.int, [core.List$(core.Comparable), core.Comparable]);
function binarySearch(sortedList, key, opts) {
let compare = opts && 'compare' in opts ? opts.compare : null;
if (compare == null) {
return _comparableBinarySearch(dart.as(sortedList, core.List$(core.Comparable)), dart.as(key, core.Comparable));
}
let min = 0;
let max = sortedList[dartx.length];
while (dart.notNull(min) < dart.notNull(max)) {
let mid = dart.notNull(min) + (dart.notNull(max) - dart.notNull(min) >> 1);
let element = sortedList[dartx.get](mid);
let comp = dart.dcall(compare, element, key);
if (comp == 0)
return mid;
if (dart.notNull(comp) < 0) {
min = dart.notNull(mid) + 1;
} else {
max = mid;
}
}
return -1;
}
dart.fn(binarySearch, core.int, [core.List, dart.dynamic], {compare: dart.functionType(core.int, [dart.dynamic, dart.dynamic])});
function shuffle(list, start, end) {
if (start === void 0)
start = 0;
if (end === void 0)
end = null;
let random = math.Random.new();
if (end == null)
end = list[dartx.length];
let length = dart.notNull(end) - dart.notNull(start);
while (dart.notNull(length) > 1) {
let pos = random.nextInt(length);
length = dart.notNull(length) - 1;
let tmp1 = list[dartx.get](dart.notNull(start) + dart.notNull(pos));
list[dartx.set](dart.notNull(start) + dart.notNull(pos), list[dartx.get](dart.notNull(start) + dart.notNull(length)));
list[dartx.set](dart.notNull(start) + dart.notNull(length), tmp1);
}
}
dart.fn(shuffle, dart.void, [core.List], [core.int, core.int]);
function reverse(list, start, end) {
if (start === void 0)
start = 0;
if (end === void 0)
end = null;
if (end == null)
end = list[dartx.length];
_reverse(list, start, end);
}
dart.fn(reverse, dart.void, [core.List], [core.int, core.int]);
function _reverse(list, start, end) {
for (let i = start, j = dart.notNull(end) - 1; dart.notNull(i) < dart.notNull(j); i = dart.notNull(i) + 1, j = dart.notNull(j) - 1) {
let tmp = list[dartx.get](i);
list[dartx.set](i, list[dartx.get](j));
list[dartx.set](j, tmp);
}
}
dart.fn(_reverse, dart.void, [core.List, core.int, core.int]);
function insertionSort(list, opts) {
let compare = opts && 'compare' in opts ? opts.compare : null;
let start = opts && 'start' in opts ? opts.start : 0;
let end = opts && 'end' in opts ? opts.end : null;
if (end == null)
end = list[dartx.length];
if (compare == null)
compare = core.Comparable.compare;
_insertionSort(list, compare, start, end, dart.notNull(start) + 1);
}
dart.fn(insertionSort, dart.void, [core.List], {compare: dart.functionType(core.int, [dart.dynamic, dart.dynamic]), start: core.int, end: core.int});
function _insertionSort(list, compare, start, end, sortedUntil) {
for (let pos = sortedUntil; dart.notNull(pos) < dart.notNull(end); pos = dart.notNull(pos) + 1) {
let min = start;
let max = pos;
let element = list[dartx.get](pos);
while (dart.notNull(min) < dart.notNull(max)) {
let mid = dart.notNull(min) + (dart.notNull(max) - dart.notNull(min) >> 1);
let comparison = dart.dcall(compare, element, list[dartx.get](mid));
if (dart.notNull(comparison) < 0) {
max = mid;
} else {
min = dart.notNull(mid) + 1;
}
}
list[dartx.setRange](dart.notNull(min) + 1, dart.notNull(pos) + 1, list, min);
list[dartx.set](min, element);
}
}
dart.fn(_insertionSort, dart.void, [core.List, dart.functionType(core.int, [dart.dynamic, dart.dynamic]), core.int, core.int, core.int]);
let _MERGE_SORT_LIMIT = 32;
function mergeSort(list, opts) {
let start = opts && 'start' in opts ? opts.start : 0;
let end = opts && 'end' in opts ? opts.end : null;
let compare = opts && 'compare' in opts ? opts.compare : null;
if (end == null)
end = list[dartx.length];
if (compare == null)
compare = core.Comparable.compare;
let length = dart.notNull(end) - dart.notNull(start);
if (dart.notNull(length) < 2)
return;
if (dart.notNull(length) < dart.notNull(_MERGE_SORT_LIMIT)) {
_insertionSort(list, compare, start, end, dart.notNull(start) + 1);
return;
}
let middle = dart.notNull(start) + (dart.notNull(end) - dart.notNull(start) >> 1);
let firstLength = dart.notNull(middle) - dart.notNull(start);
let secondLength = dart.notNull(end) - dart.notNull(middle);
let scratchSpace = core.List.new(secondLength);
_mergeSort(list, compare, middle, end, scratchSpace, 0);
let firstTarget = dart.notNull(end) - dart.notNull(firstLength);
_mergeSort(list, compare, start, middle, list, firstTarget);
_merge(compare, list, firstTarget, end, scratchSpace, 0, secondLength, list, start);
}
dart.fn(mergeSort, dart.void, [core.List], {start: core.int, end: core.int, compare: dart.functionType(core.int, [dart.dynamic, dart.dynamic])});
function _movingInsertionSort(list, compare, start, end, target, targetOffset) {
let length = dart.notNull(end) - dart.notNull(start);
if (length == 0)
return;
target[dartx.set](targetOffset, list[dartx.get](start));
for (let i = 1; dart.notNull(i) < dart.notNull(length); i = dart.notNull(i) + 1) {
let element = list[dartx.get](dart.notNull(start) + dart.notNull(i));
let min = targetOffset;
let max = dart.notNull(targetOffset) + dart.notNull(i);
while (dart.notNull(min) < dart.notNull(max)) {
let mid = dart.notNull(min) + (dart.notNull(max) - dart.notNull(min) >> 1);
if (dart.notNull(dart.dcall(compare, element, target[dartx.get](mid))) < 0) {
max = mid;
} else {
min = dart.notNull(mid) + 1;
}
}
target[dartx.setRange](dart.notNull(min) + 1, dart.notNull(targetOffset) + dart.notNull(i) + 1, target, min);
target[dartx.set](min, element);
}
}
dart.fn(_movingInsertionSort, dart.void, [core.List, dart.functionType(core.int, [dart.dynamic, dart.dynamic]), core.int, core.int, core.List, core.int]);
function _mergeSort(list, compare, start, end, target, targetOffset) {
let length = dart.notNull(end) - dart.notNull(start);
if (dart.notNull(length) < dart.notNull(_MERGE_SORT_LIMIT)) {
_movingInsertionSort(list, compare, start, end, target, targetOffset);
return;
}
let middle = dart.notNull(start) + (dart.notNull(length) >> 1);
let firstLength = dart.notNull(middle) - dart.notNull(start);
let secondLength = dart.notNull(end) - dart.notNull(middle);
let targetMiddle = dart.notNull(targetOffset) + dart.notNull(firstLength);
_mergeSort(list, compare, middle, end, target, targetMiddle);
_mergeSort(list, compare, start, middle, list, middle);
_merge(compare, list, middle, dart.notNull(middle) + dart.notNull(firstLength), target, targetMiddle, dart.notNull(targetMiddle) + dart.notNull(secondLength), target, targetOffset);
}
dart.fn(_mergeSort, dart.void, [core.List, dart.functionType(core.int, [dart.dynamic, dart.dynamic]), core.int, core.int, core.List, core.int]);
function _merge(compare, firstList, firstStart, firstEnd, secondList, secondStart, secondEnd, target, targetOffset) {
dart.assert(dart.notNull(firstStart) < dart.notNull(firstEnd));
dart.assert(dart.notNull(secondStart) < dart.notNull(secondEnd));
let cursor1 = firstStart;
let cursor2 = secondStart;
let firstElement = firstList[dartx.get]((() => {
let x = cursor1;
cursor1 = dart.notNull(x) + 1;
return x;
})());
let secondElement = secondList[dartx.get]((() => {
let x = cursor2;
cursor2 = dart.notNull(x) + 1;
return x;
})());
while (true) {
if (dart.notNull(dart.dcall(compare, firstElement, secondElement)) <= 0) {
target[dartx.set]((() => {
let x = targetOffset;
targetOffset = dart.notNull(x) + 1;
return x;
})(), firstElement);
if (cursor1 == firstEnd)
break;
firstElement = firstList[dartx.get]((() => {
let x = cursor1;
cursor1 = dart.notNull(x) + 1;
return x;
})());
} else {
target[dartx.set]((() => {
let x = targetOffset;
targetOffset = dart.notNull(x) + 1;
return x;
})(), secondElement);
if (cursor2 != secondEnd) {
secondElement = secondList[dartx.get]((() => {
let x = cursor2;
cursor2 = dart.notNull(x) + 1;
return x;
})());
continue;
}
target[dartx.set]((() => {
let x = targetOffset;
targetOffset = dart.notNull(x) + 1;
return x;
})(), firstElement);
target[dartx.setRange](targetOffset, dart.notNull(targetOffset) + (dart.notNull(firstEnd) - dart.notNull(cursor1)), firstList, cursor1);
return;
}
}
target[dartx.set]((() => {
let x = targetOffset;
targetOffset = dart.notNull(x) + 1;
return x;
})(), secondElement);
target[dartx.setRange](targetOffset, dart.notNull(targetOffset) + (dart.notNull(secondEnd) - dart.notNull(cursor2)), secondList, cursor2);
}
dart.fn(_merge, dart.void, [dart.functionType(core.int, [dart.dynamic, dart.dynamic]), core.List, core.int, core.int, core.List, core.int, core.int, core.List, core.int]);
// Exports:
exports.binarySearch = binarySearch;
exports.shuffle = shuffle;
exports.reverse = reverse;
exports.insertionSort = insertionSort;
exports.mergeSort = mergeSort;
});

View file

@ -0,0 +1,21 @@
dart_library.library('collection/collection', null, /* Imports */[
"dart_runtime/dart",
'collection/algorithms',
'collection/equality',
'collection/iterable_zip',
'collection/priority_queue',
'collection/src/canonicalized_map',
'collection/src/queue_list',
'collection/wrappers'
], /* Lazy imports */[
], function(exports, dart, algorithms, equality, iterable_zip, priority_queue, canonicalized_map, queue_list, wrappers) {
'use strict';
let dartx = dart.dartx;
dart.export(exports, algorithms);
dart.export(exports, equality);
dart.export(exports, iterable_zip);
dart.export(exports, priority_queue);
dart.export(exports, canonicalized_map);
dart.export(exports, queue_list);
dart.export(exports, wrappers);
});

View file

@ -0,0 +1,57 @@
dart_library.library('collection/iterable_zip', null, /* Imports */[
"dart_runtime/dart",
'dart/collection',
'dart/core'
], /* Lazy imports */[
], function(exports, dart, collection, core) {
'use strict';
let dartx = dart.dartx;
let _iterables = Symbol('_iterables');
class IterableZip extends collection.IterableBase$(core.List) {
IterableZip(iterables) {
this[_iterables] = iterables;
super.IterableBase();
}
get iterator() {
let iterators = this[_iterables][dartx.map](dart.fn(x => dart.dload(x, 'iterator')))[dartx.toList]({growable: false});
return new _IteratorZip(iterators);
}
}
dart.setSignature(IterableZip, {
constructors: () => ({IterableZip: [IterableZip, [core.Iterable$(core.Iterable)]]})
});
dart.defineExtensionMembers(IterableZip, ['iterator']);
let _iterators = Symbol('_iterators');
let _current = Symbol('_current');
class _IteratorZip extends core.Object {
_IteratorZip(iterators) {
this[_iterators] = dart.as(iterators, core.List$(core.Iterator));
this[_current] = null;
}
moveNext() {
if (dart.notNull(this[_iterators][dartx.isEmpty]))
return false;
for (let i = 0; dart.notNull(i) < dart.notNull(this[_iterators][dartx.length]); i = dart.notNull(i) + 1) {
if (!dart.notNull(this[_iterators][dartx.get](i).moveNext())) {
this[_current] = null;
return false;
}
}
this[_current] = core.List.new(this[_iterators][dartx.length]);
for (let i = 0; dart.notNull(i) < dart.notNull(this[_iterators][dartx.length]); i = dart.notNull(i) + 1) {
this[_current][dartx.set](i, this[_iterators][dartx.get](i).current);
}
return true;
}
get current() {
return this[_current];
}
}
_IteratorZip[dart.implements] = () => [core.Iterator$(core.List)];
dart.setSignature(_IteratorZip, {
constructors: () => ({_IteratorZip: [_IteratorZip, [core.List]]}),
methods: () => ({moveNext: [core.bool, []]})
});
// Exports:
exports.IterableZip = IterableZip;
});

View file

@ -0,0 +1,250 @@
dart_library.library('collection/priority_queue', null, /* Imports */[
"dart_runtime/dart",
'dart/core',
'dart/collection'
], /* Lazy imports */[
], function(exports, dart, core, collection) {
'use strict';
let dartx = dart.dartx;
let PriorityQueue$ = dart.generic(function(E) {
class PriorityQueue extends core.Object {}
return PriorityQueue;
});
let PriorityQueue = PriorityQueue$();
let _queue = Symbol('_queue');
let _length = Symbol('_length');
let _add = Symbol('_add');
let _locate = Symbol('_locate');
let _removeLast = Symbol('_removeLast');
let _bubbleUp = Symbol('_bubbleUp');
let _bubbleDown = Symbol('_bubbleDown');
let _grow = Symbol('_grow');
let HeapPriorityQueue$ = dart.generic(function(E) {
class HeapPriorityQueue extends core.Object {
HeapPriorityQueue(comparison) {
if (comparison === void 0)
comparison = null;
this[_queue] = core.List$(E).new(HeapPriorityQueue$()._INITIAL_CAPACITY);
this.comparison = comparison != null ? comparison : core.Comparable.compare;
this[_length] = 0;
}
add(element) {
dart.as(element, E);
this[_add](element);
}
addAll(elements) {
dart.as(elements, core.Iterable$(E));
for (let element of elements) {
this[_add](element);
}
}
clear() {
this[_queue] = dart.const(dart.list([], E));
this[_length] = 0;
}
contains(object) {
dart.as(object, E);
return dart.notNull(this[_locate](object)) >= 0;
}
get first() {
if (this[_length] == 0)
dart.throw(new core.StateError("No such element"));
return this[_queue][dartx.get](0);
}
get isEmpty() {
return this[_length] == 0;
}
get isNotEmpty() {
return this[_length] != 0;
}
get length() {
return this[_length];
}
remove(element) {
dart.as(element, E);
let index = this[_locate](element);
if (dart.notNull(index) < 0)
return false;
let last = this[_removeLast]();
if (dart.notNull(index) < dart.notNull(this[_length])) {
let comp = dart.dcall(this.comparison, last, element);
if (dart.notNull(comp) <= 0) {
this[_bubbleUp](last, index);
} else {
this[_bubbleDown](last, index);
}
}
return true;
}
removeAll() {
let result = this[_queue];
let length = this[_length];
this[_queue] = dart.const(dart.list([], E));
this[_length] = 0;
return result[dartx.take](length);
}
removeFirst() {
if (this[_length] == 0)
dart.throw(new core.StateError("No such element"));
let result = this[_queue][dartx.get](0);
let last = this[_removeLast]();
if (dart.notNull(this[_length]) > 0) {
this[_bubbleDown](last, 0);
}
return result;
}
toList() {
let list = core.List$(E).new();
list[dartx.length] = this[_length];
list[dartx.setRange](0, this[_length], this[_queue]);
list[dartx.sort](dart.as(this.comparison, __CastType0));
return list;
}
toSet() {
let set = new (collection.SplayTreeSet$(E))(dart.as(this.comparison, dart.functionType(core.int, [E, E])));
for (let i = 0; dart.notNull(i) < dart.notNull(this[_length]); i = dart.notNull(i) + 1) {
set.add(this[_queue][dartx.get](i));
}
return set;
}
toString() {
return dart.toString(this[_queue][dartx.take](this[_length]));
}
[_add](element) {
dart.as(element, E);
if (this[_length] == this[_queue][dartx.length])
this[_grow]();
this[_bubbleUp](element, (() => {
let x = this[_length];
this[_length] = dart.notNull(x) + 1;
return x;
})());
}
[_locate](object) {
dart.as(object, E);
if (this[_length] == 0)
return -1;
let position = 1;
do {
let index = dart.notNull(position) - 1;
let element = this[_queue][dartx.get](index);
let comp = dart.dcall(this.comparison, element, object);
if (comp == 0)
return index;
if (dart.notNull(comp) < 0) {
let leftChildPosition = dart.notNull(position) * 2;
if (dart.notNull(leftChildPosition) <= dart.notNull(this[_length])) {
position = leftChildPosition;
continue;
}
}
do {
while (dart.notNull(position[dartx.isOdd])) {
position = dart.notNull(position) >> 1;
}
position = dart.notNull(position) + 1;
} while (dart.notNull(position) > dart.notNull(this[_length]));
} while (position != 1);
return -1;
}
[_removeLast]() {
let newLength = dart.notNull(this[_length]) - 1;
let last = this[_queue][dartx.get](newLength);
this[_queue][dartx.set](newLength, null);
this[_length] = newLength;
return last;
}
[_bubbleUp](element, index) {
dart.as(element, E);
while (dart.notNull(index) > 0) {
let parentIndex = ((dart.notNull(index) - 1) / 2)[dartx.truncate]();
let parent = this[_queue][dartx.get](parentIndex);
if (dart.notNull(dart.dcall(this.comparison, element, parent)) > 0)
break;
this[_queue][dartx.set](index, parent);
index = parentIndex;
}
this[_queue][dartx.set](index, element);
}
[_bubbleDown](element, index) {
dart.as(element, E);
let rightChildIndex = dart.notNull(index) * 2 + 2;
while (dart.notNull(rightChildIndex) < dart.notNull(this[_length])) {
let leftChildIndex = dart.notNull(rightChildIndex) - 1;
let leftChild = this[_queue][dartx.get](leftChildIndex);
let rightChild = this[_queue][dartx.get](rightChildIndex);
let comp = dart.dcall(this.comparison, leftChild, rightChild);
let minChildIndex = null;
let minChild = null;
if (dart.notNull(comp) < 0) {
minChild = leftChild;
minChildIndex = leftChildIndex;
} else {
minChild = rightChild;
minChildIndex = rightChildIndex;
}
comp = dart.dcall(this.comparison, element, minChild);
if (dart.notNull(comp) <= 0) {
this[_queue][dartx.set](index, element);
return;
}
this[_queue][dartx.set](index, minChild);
index = minChildIndex;
rightChildIndex = dart.notNull(index) * 2 + 2;
}
let leftChildIndex = dart.notNull(rightChildIndex) - 1;
if (dart.notNull(leftChildIndex) < dart.notNull(this[_length])) {
let child = this[_queue][dartx.get](leftChildIndex);
let comp = dart.dcall(this.comparison, element, child);
if (dart.notNull(comp) > 0) {
this[_queue][dartx.set](index, child);
index = leftChildIndex;
}
}
this[_queue][dartx.set](index, element);
}
[_grow]() {
let newCapacity = dart.notNull(this[_queue][dartx.length]) * 2 + 1;
if (dart.notNull(newCapacity) < dart.notNull(HeapPriorityQueue$()._INITIAL_CAPACITY))
newCapacity = HeapPriorityQueue$()._INITIAL_CAPACITY;
let newQueue = core.List$(E).new(newCapacity);
newQueue[dartx.setRange](0, this[_length], this[_queue]);
this[_queue] = newQueue;
}
}
HeapPriorityQueue[dart.implements] = () => [PriorityQueue$(E)];
dart.setSignature(HeapPriorityQueue, {
constructors: () => ({HeapPriorityQueue: [HeapPriorityQueue$(E), [], [dart.functionType(core.int, [E, E])]]}),
methods: () => ({
add: [dart.void, [E]],
addAll: [dart.void, [core.Iterable$(E)]],
clear: [dart.void, []],
contains: [core.bool, [E]],
remove: [core.bool, [E]],
removeAll: [core.Iterable$(E), []],
removeFirst: [E, []],
toList: [core.List$(E), []],
toSet: [core.Set$(E), []],
[_add]: [dart.void, [E]],
[_locate]: [core.int, [E]],
[_removeLast]: [E, []],
[_bubbleUp]: [dart.void, [E, core.int]],
[_bubbleDown]: [dart.void, [E, core.int]],
[_grow]: [dart.void, []]
})
});
return HeapPriorityQueue;
});
let HeapPriorityQueue = HeapPriorityQueue$();
HeapPriorityQueue._INITIAL_CAPACITY = 7;
let __CastType0$ = dart.generic(function(E) {
let __CastType0 = dart.typedef('__CastType0', () => dart.functionType(core.int, [E, E]));
return __CastType0;
});
let __CastType0 = __CastType0$();
// Exports:
exports.PriorityQueue$ = PriorityQueue$;
exports.PriorityQueue = PriorityQueue;
exports.HeapPriorityQueue$ = HeapPriorityQueue$;
exports.HeapPriorityQueue = HeapPriorityQueue;
});

View file

@ -0,0 +1,119 @@
dart_library.library('collection/src/canonicalized_map', null, /* Imports */[
"dart_runtime/dart",
'dart/core',
'collection/src/utils',
'dart/collection'
], /* Lazy imports */[
], function(exports, dart, core, utils, collection) {
'use strict';
let dartx = dart.dartx;
let _base = Symbol('_base');
let _canonicalize = Symbol('_canonicalize');
let _isValidKeyFn = Symbol('_isValidKeyFn');
let _isValidKey = Symbol('_isValidKey');
let CanonicalizedMap$ = dart.generic(function(C, K, V) {
class CanonicalizedMap extends core.Object {
CanonicalizedMap(canonicalize, opts) {
let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null;
this[_base] = core.Map$(C, utils.Pair$(K, V)).new();
this[_canonicalize] = canonicalize;
this[_isValidKeyFn] = isValidKey;
}
from(other, canonicalize, opts) {
let isValidKey = opts && 'isValidKey' in opts ? opts.isValidKey : null;
this[_base] = core.Map$(C, utils.Pair$(K, V)).new();
this[_canonicalize] = canonicalize;
this[_isValidKeyFn] = isValidKey;
this.addAll(other);
}
get(key) {
if (!dart.notNull(this[_isValidKey](key)))
return null;
let pair = this[_base].get(dart.dcall(this[_canonicalize], key));
return pair == null ? null : pair.last;
}
set(key, value) {
dart.as(key, K);
dart.as(value, V);
this[_base].set(dart.as(dart.dcall(this[_canonicalize], key), C), new (utils.Pair$(K, V))(key, value));
return value;
}
addAll(other) {
dart.as(other, core.Map$(K, V));
other.forEach(dart.fn((key, value) => this.set(dart.as(key, K), dart.as(value, V))));
}
clear() {
this[_base].clear();
}
containsKey(key) {
if (!dart.notNull(this[_isValidKey](key)))
return false;
return this[_base].containsKey(dart.dcall(this[_canonicalize], key));
}
containsValue(value) {
return this[_base].values[dartx.any](dart.fn(pair => dart.equals(dart.dload(pair, 'last'), value), core.bool, [dart.dynamic]));
}
forEach(f) {
dart.as(f, dart.functionType(dart.void, [K, V]));
this[_base].forEach(dart.fn((key, pair) => f(dart.as(dart.dload(pair, 'first'), K), dart.as(dart.dload(pair, 'last'), V)), dart.void, [dart.dynamic, dart.dynamic]));
}
get isEmpty() {
return this[_base].isEmpty;
}
get isNotEmpty() {
return this[_base].isNotEmpty;
}
get keys() {
return dart.as(this[_base].values[dartx.map](dart.fn(pair => dart.dload(pair, 'first'))), core.Iterable$(K));
}
get length() {
return this[_base].length;
}
putIfAbsent(key, ifAbsent) {
dart.as(key, K);
dart.as(ifAbsent, dart.functionType(V, []));
return this[_base].putIfAbsent(dart.as(dart.dcall(this[_canonicalize], key), C), dart.fn(() => new (utils.Pair$(K, V))(key, ifAbsent()), utils.Pair$(K, V), [])).last;
}
remove(key) {
if (!dart.notNull(this[_isValidKey](key)))
return null;
let pair = this[_base].remove(dart.dcall(this[_canonicalize], key));
return pair == null ? null : pair.last;
}
get values() {
return dart.as(this[_base].values[dartx.map](dart.fn(pair => dart.dload(pair, 'last'))), core.Iterable$(V));
}
toString() {
return collection.Maps.mapToString(this);
}
[_isValidKey](key) {
return (key == null || dart.is(key, K)) && (this[_isValidKeyFn] == null || dart.notNull(dart.as(dart.dcall(this[_isValidKeyFn], key), core.bool)));
}
}
CanonicalizedMap[dart.implements] = () => [core.Map$(K, V)];
dart.defineNamedConstructor(CanonicalizedMap, 'from');
dart.setSignature(CanonicalizedMap, {
constructors: () => ({
CanonicalizedMap: [CanonicalizedMap$(C, K, V), [dart.functionType(C, [K])], {isValidKey: dart.functionType(core.bool, [core.Object])}],
from: [CanonicalizedMap$(C, K, V), [core.Map$(K, V), dart.functionType(C, [K])], {isValidKey: dart.functionType(core.bool, [core.Object])}]
}),
methods: () => ({
get: [V, [core.Object]],
set: [dart.void, [K, V]],
addAll: [dart.void, [core.Map$(K, V)]],
clear: [dart.void, []],
containsKey: [core.bool, [core.Object]],
containsValue: [core.bool, [core.Object]],
forEach: [dart.void, [dart.functionType(dart.void, [K, V])]],
putIfAbsent: [V, [K, dart.functionType(V, [])]],
remove: [V, [core.Object]],
[_isValidKey]: [core.bool, [core.Object]]
})
});
return CanonicalizedMap;
});
let CanonicalizedMap = CanonicalizedMap$();
// Exports:
exports.CanonicalizedMap$ = CanonicalizedMap$;
exports.CanonicalizedMap = CanonicalizedMap;
});

View file

@ -0,0 +1,242 @@
dart_library.library('collection/src/queue_list', null, /* Imports */[
"dart_runtime/dart",
'dart/core',
'dart/collection'
], /* Lazy imports */[
], function(exports, dart, core, collection) {
'use strict';
let dartx = dart.dartx;
let _head = Symbol('_head');
let _tail = Symbol('_tail');
let _table = Symbol('_table');
let _add = Symbol('_add');
let _preGrow = Symbol('_preGrow');
let _grow = Symbol('_grow');
let _writeToList = Symbol('_writeToList');
let QueueList$ = dart.generic(function(E) {
class QueueList extends dart.mixin(core.Object, collection.ListMixin$(E)) {
QueueList(initialCapacity) {
if (initialCapacity === void 0)
initialCapacity = null;
this[_head] = 0;
this[_tail] = 0;
this[_table] = null;
if (initialCapacity == null || dart.notNull(initialCapacity) < dart.notNull(QueueList$()._INITIAL_CAPACITY)) {
initialCapacity = QueueList$()._INITIAL_CAPACITY;
} else if (!dart.notNull(QueueList$()._isPowerOf2(initialCapacity))) {
initialCapacity = QueueList$()._nextPowerOf2(initialCapacity);
}
dart.assert(QueueList$()._isPowerOf2(initialCapacity));
this[_table] = core.List$(E).new(initialCapacity);
}
static from(source) {
if (dart.is(source, core.List)) {
let length = source[dartx.length];
let queue = new (QueueList$(E))(dart.notNull(length) + 1);
dart.assert(dart.notNull(queue[_table][dartx.length]) > dart.notNull(length));
let sourceList = dart.as(source, core.List);
queue[_table][dartx.setRange](0, length, dart.as(sourceList, core.Iterable$(E)), 0);
queue[_tail] = length;
return queue;
} else {
let _ = new (QueueList$(E))();
_.addAll(source);
return _;
}
}
add(element) {
dart.as(element, E);
this[_add](element);
}
addAll(elements) {
dart.as(elements, core.Iterable$(E));
if (dart.is(elements, core.List)) {
let list = dart.as(elements, core.List);
let addCount = list[dartx.length];
let length = this.length;
if (dart.notNull(length) + dart.notNull(addCount) >= dart.notNull(this[_table][dartx.length])) {
this[_preGrow](dart.notNull(length) + dart.notNull(addCount));
this[_table][dartx.setRange](length, dart.notNull(length) + dart.notNull(addCount), dart.as(list, core.Iterable$(E)), 0);
this[_tail] = dart.notNull(this[_tail]) + dart.notNull(addCount);
} else {
let endSpace = dart.notNull(this[_table][dartx.length]) - dart.notNull(this[_tail]);
if (dart.notNull(addCount) < dart.notNull(endSpace)) {
this[_table][dartx.setRange](this[_tail], dart.notNull(this[_tail]) + dart.notNull(addCount), dart.as(list, core.Iterable$(E)), 0);
this[_tail] = dart.notNull(this[_tail]) + dart.notNull(addCount);
} else {
let preSpace = dart.notNull(addCount) - dart.notNull(endSpace);
this[_table][dartx.setRange](this[_tail], dart.notNull(this[_tail]) + dart.notNull(endSpace), dart.as(list, core.Iterable$(E)), 0);
this[_table][dartx.setRange](0, preSpace, dart.as(list, core.Iterable$(E)), endSpace);
this[_tail] = preSpace;
}
}
} else {
for (let element of elements)
this[_add](element);
}
}
toString() {
return collection.IterableBase.iterableToFullString(this, "{", "}");
}
addLast(element) {
dart.as(element, E);
this[_add](element);
}
addFirst(element) {
dart.as(element, E);
this[_head] = dart.notNull(this[_head]) - 1 & dart.notNull(this[_table][dartx.length]) - 1;
this[_table][dartx.set](this[_head], element);
if (this[_head] == this[_tail])
this[_grow]();
}
removeFirst() {
if (this[_head] == this[_tail])
dart.throw(new core.StateError("No element"));
let result = this[_table][dartx.get](this[_head]);
this[_table][dartx.set](this[_head], null);
this[_head] = dart.notNull(this[_head]) + 1 & dart.notNull(this[_table][dartx.length]) - 1;
return result;
}
removeLast() {
if (this[_head] == this[_tail])
dart.throw(new core.StateError("No element"));
this[_tail] = dart.notNull(this[_tail]) - 1 & dart.notNull(this[_table][dartx.length]) - 1;
let result = this[_table][dartx.get](this[_tail]);
this[_table][dartx.set](this[_tail], null);
return result;
}
get length() {
return dart.notNull(this[_tail]) - dart.notNull(this[_head]) & dart.notNull(this[_table][dartx.length]) - 1;
}
set length(value) {
if (dart.notNull(value) < 0)
dart.throw(new core.RangeError(`Length ${value} may not be negative.`));
let delta = dart.notNull(value) - dart.notNull(this.length);
if (dart.notNull(delta) >= 0) {
if (dart.notNull(this[_table][dartx.length]) <= dart.notNull(value)) {
this[_preGrow](value);
}
this[_tail] = dart.notNull(this[_tail]) + dart.notNull(delta) & dart.notNull(this[_table][dartx.length]) - 1;
return;
}
let newTail = dart.notNull(this[_tail]) + dart.notNull(delta);
if (dart.notNull(newTail) >= 0) {
this[_table][dartx.fillRange](newTail, this[_tail], null);
} else {
newTail = dart.notNull(newTail) + dart.notNull(this[_table][dartx.length]);
this[_table][dartx.fillRange](0, this[_tail], null);
this[_table][dartx.fillRange](newTail, this[_table][dartx.length], null);
}
this[_tail] = newTail;
}
get(index) {
if (dart.notNull(index) < 0 || dart.notNull(index) >= dart.notNull(this.length)) {
dart.throw(new core.RangeError(`Index ${index} must be in the range [0..${this.length}).`));
}
return this[_table][dartx.get](dart.notNull(this[_head]) + dart.notNull(index) & dart.notNull(this[_table][dartx.length]) - 1);
}
set(index, value) {
dart.as(value, E);
if (dart.notNull(index) < 0 || dart.notNull(index) >= dart.notNull(this.length)) {
dart.throw(new core.RangeError(`Index ${index} must be in the range [0..${this.length}).`));
}
this[_table][dartx.set](dart.notNull(this[_head]) + dart.notNull(index) & dart.notNull(this[_table][dartx.length]) - 1, value);
return value;
}
static _isPowerOf2(number) {
return (dart.notNull(number) & dart.notNull(number) - 1) == 0;
}
static _nextPowerOf2(number) {
dart.assert(dart.notNull(number) > 0);
number = (dart.notNull(number) << 1) - 1;
for (;;) {
let nextNumber = dart.notNull(number) & dart.notNull(number) - 1;
if (nextNumber == 0)
return number;
number = nextNumber;
}
}
[_add](element) {
dart.as(element, E);
this[_table][dartx.set](this[_tail], element);
this[_tail] = dart.notNull(this[_tail]) + 1 & dart.notNull(this[_table][dartx.length]) - 1;
if (this[_head] == this[_tail])
this[_grow]();
}
[_grow]() {
let newTable = core.List$(E).new(dart.notNull(this[_table][dartx.length]) * 2);
let split = dart.notNull(this[_table][dartx.length]) - dart.notNull(this[_head]);
newTable[dartx.setRange](0, split, this[_table], this[_head]);
newTable[dartx.setRange](split, dart.notNull(split) + dart.notNull(this[_head]), this[_table], 0);
this[_head] = 0;
this[_tail] = this[_table][dartx.length];
this[_table] = newTable;
}
[_writeToList](target) {
dart.as(target, core.List$(E));
dart.assert(dart.notNull(target[dartx.length]) >= dart.notNull(this.length));
if (dart.notNull(this[_head]) <= dart.notNull(this[_tail])) {
let length = dart.notNull(this[_tail]) - dart.notNull(this[_head]);
target[dartx.setRange](0, length, this[_table], this[_head]);
return length;
} else {
let firstPartSize = dart.notNull(this[_table][dartx.length]) - dart.notNull(this[_head]);
target[dartx.setRange](0, firstPartSize, this[_table], this[_head]);
target[dartx.setRange](firstPartSize, dart.notNull(firstPartSize) + dart.notNull(this[_tail]), this[_table], 0);
return dart.notNull(this[_tail]) + dart.notNull(firstPartSize);
}
}
[_preGrow](newElementCount) {
dart.assert(dart.notNull(newElementCount) >= dart.notNull(this.length));
newElementCount = dart.notNull(newElementCount) + (dart.notNull(newElementCount) >> 1);
let newCapacity = QueueList$()._nextPowerOf2(newElementCount);
let newTable = core.List$(E).new(newCapacity);
this[_tail] = this[_writeToList](newTable);
this[_table] = newTable;
this[_head] = 0;
}
}
QueueList[dart.implements] = () => [collection.Queue$(E)];
dart.setSignature(QueueList, {
constructors: () => ({
QueueList: [QueueList$(E), [], [core.int]],
from: [QueueList$(E), [core.Iterable$(E)]]
}),
methods: () => ({
add: [dart.void, [E]],
addAll: [dart.void, [core.Iterable$(E)]],
addLast: [dart.void, [E]],
addFirst: [dart.void, [E]],
removeFirst: [E, []],
removeLast: [E, []],
get: [E, [core.int]],
set: [dart.void, [core.int, E]],
[_add]: [dart.void, [E]],
[_grow]: [dart.void, []],
[_writeToList]: [core.int, [core.List$(E)]],
[_preGrow]: [dart.void, [core.int]]
}),
statics: () => ({
_isPowerOf2: [core.bool, [core.int]],
_nextPowerOf2: [core.int, [core.int]]
}),
names: ['_isPowerOf2', '_nextPowerOf2']
});
dart.defineExtensionMembers(QueueList, [
'add',
'addAll',
'toString',
'removeLast',
'get',
'set',
'length',
'length'
]);
return QueueList;
});
let QueueList = QueueList$();
QueueList._INITIAL_CAPACITY = 8;
// Exports:
exports.QueueList$ = QueueList$;
exports.QueueList = QueueList;
});

View file

@ -0,0 +1 @@
severe: [InvalidMethodOverride] Invalid override. The type of UnmodifiableMapMixin.remove ((K) → V) is not a subtype of Map<K, V>.remove ((Object) → V). (package:collection/src/unmodifiable_wrappers.dart, line 230, col 3)

View file

@ -0,0 +1,24 @@
dart_library.library('collection/src/utils', null, /* Imports */[
"dart_runtime/dart",
'dart/core'
], /* Lazy imports */[
], function(exports, dart, core) {
'use strict';
let dartx = dart.dartx;
let Pair$ = dart.generic(function(E, F) {
class Pair extends core.Object {
Pair(first, last) {
this.first = first;
this.last = last;
}
}
dart.setSignature(Pair, {
constructors: () => ({Pair: [Pair$(E, F), [E, F]]})
});
return Pair;
});
let Pair = Pair$();
// Exports:
exports.Pair$ = Pair$;
exports.Pair = Pair;
});

View file

@ -0,0 +1,2 @@
severe: [InvalidMethodOverride] Invalid override. The type of DelegatingSet.lookup ((E) → E) is not a subtype of Set<E>.lookup ((Object) → E). (package:collection/wrappers.dart, line 237, col 3)
severe: [InvalidMethodOverride] Invalid override. The type of MapValueSet.lookup ((V) → V) is not a subtype of Set<V>.lookup ((Object) → V). (package:collection/wrappers.dart, line 521, col 3)

View file

@ -0,0 +1,25 @@
// 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.
// Regression test for dart2js that used to be confused when inlining
// method that always aborts in a switch case.
import "package:expect/expect.dart";
foo() { throw 42; }
main() {
var exception;
try {
switch (42) {
case 42:
foo();
foo();
break;
}
} catch (e) {
exception = e;
}
Expect.equals(42, exception);
}

View file

@ -0,0 +1,38 @@
// 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.
// Regression test for dart2js that used to duplicate some `Object`
// methods to handle `noSuchMethod`.
import "package:expect/expect.dart";
import "compiler_annotations.dart";
abstract /// 01: static type warning
class Foo {
noSuchMethod(im) => 42;
}
@DontInline()
returnFoo() {
(() => 42)();
return new Foo();
}
class Bar {
operator==(other) => false;
}
var a = [false, true, new Object(), new Bar()];
main() {
if (a[0]) {
// This `==` call will make the compiler create a selector with an
// exact `TypeMask` of `Foo`. Since `Foo` is abstract, such a call
// cannot happen, but we still used to generate a `==` method on
// the `Object` class to handle `noSuchMethod`.
print(returnFoo() == 42);
} else {
Expect.isFalse(a[2] == 42);
}
}

View file

@ -0,0 +1,29 @@
// 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.
// Dart test program for constructors and initializers.
// Exercises issue 2282, factory constructors in abstract classes should
// not emit a static type warning
class B extends A1 {
B() {}
method() {}
}
abstract class A1 {
A1() {}
method(); // Abstract.
factory A1.make() { return new B(); }
}
class A2 {
// Intentionally abstract method.
method(); /// 00: static type warning
A2.make() {}
}
main() {
new A1.make();
new A2.make(); /// 00: continued
}

View file

@ -0,0 +1,28 @@
// 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";
// Test to ensure that an abstract getter is not mistaken for a field.
class Foo {
// Intentionally abstract:
get i; /// 01: static type warning
}
class Bar {
}
noMethod(e) => e is NoSuchMethodError;
checkIt(f) {
Expect.throws(() { f.i = 'hi'; }, noMethod); /// 01: continued
Expect.throws(() { print(f.i); }, noMethod); /// 01: continued
Expect.throws(() { print(f.i()); }, noMethod); /// 01: continued
}
main() {
checkIt(new Foo());
checkIt(new Bar());
}

View file

@ -0,0 +1,41 @@
// 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 "package:expect/expect.dart";
// Checks that abstract instance methods are correctly resolved.
int get length => throw "error: top-level getter called";
set height(x) { throw "error: top-level setter called"; }
width() { throw "error: top-level function called"; }
abstract class A {
int get length; // Abstract instance getter.
set height(x); // Abstract instance setter.
int width(); // Abstract instance method.
// Must resolve to non-abstract length getter in subclass.
get useLength => length;
// Must resolve to non-abstract height setter in subclass.
setHeight(x) => height = x;
// Must resolve to non-abstract width() method in subclass.
useWidth() => width();
}
class A1 extends A {
int length; // Implies a length getter.
int height; // Implies a height setter.
int width() => 345;
A1(this.length);
}
main() {
var a = new A1(123);
Expect.equals(123, a.useLength);
a.setHeight(234);
Expect.equals(234, a.height);
Expect.equals(345, a.useWidth());
print([a.useLength, a.height, a.useWidth()]);
}

View file

@ -0,0 +1,26 @@
// 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 "package:expect/expect.dart";
class A {
noSuchMethod(_) {
Expect.fail('Should not reach here');
}
}
class B extends A {
operator ==(other);
}
class C extends B {
}
var a = [new C()];
main() {
C c = a[0];
a.add(c);
Expect.isTrue(c == a[1]);
}

View file

@ -0,0 +1,45 @@
// 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";
// Test various conditions around instantiating an abstract class.
// From The Dart Programming Langauge Specification, 11.11.1 "New":
// If q is a constructor of an abstract class then an
// AbstractClassInstantiation- Error is thrown.
abstract class Interface {
void foo(); /// 03: static type warning
}
abstract class AbstractClass {
toString() => 'AbstractClass';
}
class ConcreteSubclass extends AbstractClass {
toString() => 'ConcreteSubclass';
}
class NonAbstractClass implements Interface {
toString() => 'NonAbstractClass';
}
Interface interface() => new Interface(); /// 01: static type warning
AbstractClass abstractClass() => new AbstractClass(); /// 02: static type warning
bool isAbstractClassInstantiationError(e) {
return e is AbstractClassInstantiationError;
}
void main() {
Expect.throws(interface, isAbstractClassInstantiationError, /// 01: continued
"expected AbstractClassInstantiationError"); /// 01: continued
Expect.throws(abstractClass, isAbstractClassInstantiationError, /// 02: continued
"expected AbstractClassInstantiationError"); /// 02: continued
Expect.stringEquals('ConcreteSubclass', '${new ConcreteSubclass()}');
Expect.stringEquals('NonAbstractClass', '${new NonAbstractClass()}');
}

View file

@ -0,0 +1,20 @@
// 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";
main() {
var b = new B();
Expect.equals(42, b.foo());
}
class A {
foo(); /// 00: static type warning
static bar(); /// 01: compile-time error
}
class B extends A {
foo() => 42;
bar() => 87;
}

View file

@ -0,0 +1,22 @@
// Copyright (c) 2011, 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.
// Dart version of two-argument Ackermann-Peter function.
import "package:expect/expect.dart";
class AckermannTest {
static ack(m, n) {
return m == 0 ?
n + 1 : ((n == 0) ?
ack(m - 1, 1) : ack(m - 1, ack(m, n - 1)));
}
static testMain() {
Expect.equals(253, ack(3, 5));
}
}
main() {
AckermannTest.testMain();
}

View file

@ -0,0 +1,98 @@
// 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";
class Conster {
const Conster(this.value);
final value;
toString() {
return value.toString();
}
}
main() {
testEmpty();
testInterpolation();
testMultiline();
}
testEmpty() {
Expect.equals("", (const Conster("" "" "")).toString());
Expect.equals("", (const Conster("" '' "")).toString());
Expect.equals("", (const Conster("" "" r"")).toString());
Expect.equals("a", (const Conster("a" "")).toString());
Expect.equals("a", (const Conster("a" '')).toString());
Expect.equals("a", (const Conster("a" r'')).toString());
Expect.equals("b", (const Conster('b' "")).toString());
Expect.equals("b", (const Conster('b' '')).toString());
Expect.equals("b", (const Conster('b' r'')).toString());
Expect.equals("c", (const Conster(r'c' "")).toString());
Expect.equals("c", (const Conster(r'c' '')).toString());
Expect.equals("c", (const Conster(r'c' r'')).toString());
Expect.equals("a", (const Conster("" "a")).toString());
Expect.equals("a", (const Conster("" 'a')).toString());
Expect.equals("a", (const Conster("" r'a')).toString());
Expect.equals("b", (const Conster('' "b")).toString());
Expect.equals("b", (const Conster('' 'b')).toString());
Expect.equals("b", (const Conster('' r'b')).toString());
Expect.equals("c", (const Conster(r'' "c")).toString());
Expect.equals("c", (const Conster(r'' 'c')).toString());
Expect.equals("c", (const Conster(r'' r'c')).toString());
}
const s = "a";
testInterpolation() {
Expect.equals(r"ab", (const Conster("$s" "b")).toString());
Expect.equals(r"ab", (const Conster('$s' "b")).toString());
Expect.equals(r"$sb", (const Conster(r'$s' "b")).toString());
Expect.equals(r"-a-b", (const Conster("-$s-" "b")).toString());
Expect.equals(r"-a-b", (const Conster('-$s-' "b")).toString());
Expect.equals(r"-$s-b", (const Conster(r'-$s-' "b")).toString());
Expect.equals(r"ba", (const Conster('b' "$s")).toString());
Expect.equals(r"ba", (const Conster('b' '$s')).toString());
Expect.equals(r"b$s", (const Conster('b' r'$s')).toString());
Expect.equals(r"b-a-", (const Conster('b' "-$s-")).toString());
Expect.equals(r"b-a-", (const Conster('b' '-$s-')).toString());
Expect.equals(r"b-$s-", (const Conster('b' r'-$s-')).toString());
}
testMultiline() {
Expect.equals("abe",
(const Conster("a"
"b"
"e")).toString());
Expect.equals("a b e",
(const Conster("a "
"b "
"e")).toString());
Expect.equals("a b e",
(const Conster("a"
" b"
" e")).toString());
Expect.equals("abe", (const Conster("""
a""" "b" "e")).toString());
Expect.equals("a b e", (const Conster("""
a""" " b" " e")).toString());
Expect.equals("abe", (const Conster("""
a""" """
b""" """
e""")).toString());
}

View file

@ -0,0 +1,86 @@
// 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";
main() {
testEmpty();
testInterpolation();
testMultiline();
}
testEmpty() {
Expect.equals("", "" "" "");
Expect.equals("", "" '' "");
Expect.equals("", "" "" r"");
Expect.equals("a", "a" "");
Expect.equals("a", "a" '');
Expect.equals("a", "a" r'');
Expect.equals("b", 'b' "");
Expect.equals("b", 'b' '');
Expect.equals("b", 'b' r'');
Expect.equals("c", r'c' "");
Expect.equals("c", r'c' '');
Expect.equals("c", r'c' r'');
Expect.equals("a", "" "a");
Expect.equals("a", "" 'a');
Expect.equals("a", "" r'a');
Expect.equals("b", '' "b");
Expect.equals("b", '' 'b');
Expect.equals("b", '' r'b');
Expect.equals("c", r'' "c");
Expect.equals("c", r'' 'c');
Expect.equals("c", r'' r'c');
}
testInterpolation() {
var s = "a";
Expect.equals(r"ab", "$s" "b");
Expect.equals(r"ab", '$s' "b");
Expect.equals(r"$sb", r'$s' "b");
Expect.equals(r"-a-b", "-$s-" "b");
Expect.equals(r"-a-b", '-$s-' "b");
Expect.equals(r"-$s-b", r'-$s-' "b");
Expect.equals(r"ba", 'b' "$s");
Expect.equals(r"ba", 'b' '$s');
Expect.equals(r"b$s", 'b' r'$s');
Expect.equals(r"b-a-", 'b' "-$s-");
Expect.equals(r"b-a-", 'b' '-$s-');
Expect.equals(r"b-$s-", 'b' r'-$s-');
}
testMultiline() {
Expect.equals("abe",
"a"
"b"
"e");
Expect.equals("a b e",
"a "
"b "
"e");
Expect.equals("a b e",
"a"
" b"
" e");
Expect.equals("abe", """
a""" "b" "e");
Expect.equals("a b e", """
a""" " b" " e");
Expect.equals("abe", """
a""" """
b""" """
e""");
}

View file

@ -0,0 +1,46 @@
// Copyright (c) 2011, 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";
class A {
int a;
double d1;
double d2;
double d3;
double d4;
double d5;
double d6;
double d7;
double d8;
double d9;
double d10;
double d11;
double d12;
double d13;
double d14;
static var s;
static foo() {
return s;
}
A(this.a) { }
value() {
return a + foo();
}
}
class AllocateLargeObject {
static testMain() {
var a = new A(1);
A.s = 4;
Expect.equals(5, a.value());
}
}
main() {
AllocateLargeObject.testMain();
}

View file

@ -0,0 +1,21 @@
// Copyright (c) 2011, 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";
class MyAllocate {
const MyAllocate([int value = 0]) : value_ = value;
int getValue() { return value_; }
final int value_;
}
class AllocateTest {
static testMain() {
Expect.equals(900, (new MyAllocate(900)).getValue());
}
}
main() {
AllocateTest.testMain();
}

View file

@ -0,0 +1,36 @@
// 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.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr
// Test allocation sinking with polymorphic inlining.
import "package:expect/expect.dart";
class A {
foo(x) => ++x.f;
}
class B {
foo(x) => --x.f;
}
class C {
int f = 0;
}
test(obj) {
var c = new C();
return obj.foo(c);
}
main() {
var a = new A();
var b = new B();
Expect.equals(1, test(a));
Expect.equals(-1, test(b));
for (var i = 0; i < 20; i++) test(a);
Expect.equals(1, test(a));
Expect.equals(-1, test(b));
}

View file

@ -0,0 +1,20 @@
// 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.
// Regression test for dart2js that used to miscompile boolean add operations
// if one of the operands was an int and the other was not (issue 22427).
import "package:expect/expect.dart";
class NotAnInt {
NotAnInt operator&(b) => this;
}
@AssumeDynamic() @NoInline()
id(x) => x;
main () {
var a = id(new NotAnInt());
Expect.equals(a, a & 5 & 2);
}

View file

@ -0,0 +1,6 @@
// Copyright (c) 2011, 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 application_negative_test.dart;
part 'failing_main.dart';

View file

@ -0,0 +1,6 @@
// Copyright (c) 2011, 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 ApplicationTest.dart;
part 'empty_main.dart';

View file

@ -0,0 +1,16 @@
// 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.
// Dart test program for testing that the argument definition test has been
// removed.
import "package:expect/expect.dart";
int test(a, {b, c}) {
if (?b) return b; /// 01: compile-time error
return a + b + c;
}
main() {
Expect.equals(6, test(1, b: 2, c:3));
}

View file

@ -0,0 +1,73 @@
// 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.
// Dart test program to test arithmetic operations.
import "package:expect/expect.dart";
class A {
static foo() => 499;
}
bool throwsNoSuchMethod(f) {
try {
f();
return false;
} on NoSuchMethodError catch (e) {
return true;
}
return false;
}
bool throwsBecauseOfBadArgument(f) {
try {
f();
return false;
} on NoSuchMethodError catch (e) {
return true;
} on ArgumentError catch (e) {
return true;
} on TypeError catch (e) {
// In type checked mode.
return true;
}
return false;
}
numberOpBadSecondArgument(f) {
Expect.isTrue(throwsBecauseOfBadArgument(() => f(true)));
Expect.isTrue(throwsBecauseOfBadArgument(() => f(new A())));
Expect.isTrue(throwsBecauseOfBadArgument(() => f("foo")));
Expect.isTrue(throwsBecauseOfBadArgument(() => f("5")));
Expect.isTrue(throwsBecauseOfBadArgument(() => f(() => 499)));
Expect.isTrue(throwsBecauseOfBadArgument(() => f(null)));
Expect.isTrue(throwsBecauseOfBadArgument(() => f(false)));
Expect.isTrue(throwsBecauseOfBadArgument(() => f([])));
Expect.isTrue(throwsBecauseOfBadArgument(() => f({})));
Expect.isTrue(throwsBecauseOfBadArgument(() => f(A.foo)));
}
badOperations(b) {
Expect.isTrue(throwsNoSuchMethod(() => b - 3));
Expect.isTrue(throwsNoSuchMethod(() => b * 3));
Expect.isTrue(throwsNoSuchMethod(() => b ~/ 3));
Expect.isTrue(throwsNoSuchMethod(() => b / 3));
Expect.isTrue(throwsNoSuchMethod(() => b % 3));
Expect.isTrue(throwsNoSuchMethod(() => b + 3));
Expect.isTrue(throwsNoSuchMethod(() => b[3]));
Expect.isTrue(throwsNoSuchMethod(() => ~b));
Expect.isTrue(throwsNoSuchMethod(() => -b));
}
main() {
numberOpBadSecondArgument((x) => 3 + x);
numberOpBadSecondArgument((x) => 3 - x);
numberOpBadSecondArgument((x) => 3 * x);
numberOpBadSecondArgument((x) => 3 / x);
numberOpBadSecondArgument((x) => 3 ~/ x);
numberOpBadSecondArgument((x) => 3 % x);
badOperations(true);
badOperations(false);
badOperations(() => 499);
badOperations(A.foo);
}

View file

@ -0,0 +1,39 @@
// 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 canonicalization of simple arithmetic equivalences.
// VMOptions=--optimization-counter-threshold=20 --no-use-osr
import "package:expect/expect.dart";
main() {
for (var i = 0; i < 50; i++) {
Expect.isTrue(mul1double(i) is double);
Expect.equals(i.toDouble(), mul1double(i));
Expect.equals(0.0, mul0double(i));
Expect.equals(i.toDouble(), add0double(i));
Expect.equals(i, mul1int(i));
Expect.equals(i, add0int(i));
Expect.equals(0, mul0int(i));
Expect.equals(0, and0(i));
Expect.equals(i, and1(i));
Expect.equals(i, or0(i));
Expect.equals(i, xor0(i));
}
Expect.isTrue(mul0double(double.NAN).isNaN);
Expect.isFalse(add0double(-0.0).isNegative);
}
mul1double(x) => 1.0 * x;
mul0double(x) => 0.0 * x;
add0double(x) => 0.0 + x;
mul1int(x) => 1 * x;
mul0int(x) => 0 * x;
add0int(x) => 0 + x;
and0(x) => 0 & x;
or0(x) => 0 | x;
xor0(x) => 0 ^ x;
and1(x) => (-1) & x;

View file

@ -0,0 +1,15 @@
// 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.
// Dart test program to test arithmetic operations.
// VMOptions=--optimization_counter_threshold=5
import "package:expect/expect.dart";
main() {
for (var i = 0; i < 10; i++) {
Expect.equals(0x40000000, (i - i) - -1073741824);
Expect.equals(0x4000000000000000, (i - i) - -4611686018427387904);
}
}

View file

@ -0,0 +1,495 @@
// 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.
// Dart test program to test arithmetic operations.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr
library arithmetic_test;
import "package:expect/expect.dart";
import 'dart:math';
class ArithmeticTest {
static bool exceptionCaughtParseInt(String s) {
try {
int.parse(s);
return false;
} on FormatException catch (e) {
return true;
}
}
static bool exceptionCaughtParseDouble(String s) {
try {
double.parse(s);
return false;
} on FormatException catch (e) {
return true;
}
}
static bool toIntThrowsUnsupportedError(String str) {
// No exception allowed for parse double.
double d = double.parse(str);
try {
var a = d.toInt();
return false;
} on UnsupportedError catch (e) {
return true;
}
}
static runOne() {
var a = 22;
var b = 4;
// Smi & smi.
Expect.equals(26, a + b);
Expect.equals(18, a - b);
Expect.equals(88, a * b);
Expect.equals(5, a ~/ b);
Expect.equals(5.5, a / b);
Expect.equals(2.0, 10 / 5);
Expect.equals(2, a % b);
Expect.equals(2, a.remainder(b));
// Smi corner cases.
for (int i = 0; i < 80; i++) {
a = -(1 << i);
b = -1;
Expect.equals(1 << i, a ~/ b);
}
a = 22;
b = 4.0;
// Smi & double.
Expect.equals(26.0, a + b);
Expect.equals(18.0, a - b);
Expect.equals(88.0, a * b);
Expect.equals(5, a ~/ b);
Expect.equals(5.5, a / b);
Expect.equals(2.0, a % b);
Expect.equals(2.0, a.remainder(b));
a = 22.0;
b = 4;
// Double & smi.
Expect.equals(26.0, a + b);
Expect.equals(18.0, a - b);
Expect.equals(88.0, a * b);
Expect.equals(5, a ~/ b);
Expect.equals(5.5, a / b);
Expect.equals(2.0, a % b);
Expect.equals(2.0, a.remainder(b));
a = 22.0;
b = 4.0;
// Double & double.
Expect.equals(26.0, a + b);
Expect.equals(18.0, a - b);
Expect.equals(88.0, a * b);
Expect.equals(5, a ~/ b);
Expect.equals(5.5, a / b);
Expect.equals(2.0, a % b);
Expect.equals(2.0, a.remainder(b));
// Special int operations.
Expect.equals(2, (2).floor());
Expect.equals(2, (2).ceil());
Expect.equals(2, (2).round());
Expect.equals(2, (2).truncate());
Expect.equals(-2, (-2).floor());
Expect.equals(-2, (-2).ceil());
Expect.equals(-2, (-2).round());
Expect.equals(-2, (-2).truncate());
// Note that this number fits into 53 bits of a double.
int big = 123456789012345;
Expect.equals(big, big.floor());
Expect.equals(big, big.ceil());
Expect.equals(big, big.round());
Expect.equals(big, big.truncate());
big = -big;
Expect.equals(big, big.floor());
Expect.equals(big, big.ceil());
Expect.equals(big, big.round());
Expect.equals(big, big.truncate());
// Test if double is contagious. The assignment will check the type.
{ double d = 1 + 1.0; }
{ double d = 1.0 + 1; }
{ double d = 1 * 1.0; }
{ double d = 0 * 1.0; }
{ double d = 1.0 * 0; }
{ double d = 1 / 1.0; }
{ double d = 1.0 / 0; }
{ double d = 1 - 1.0; }
{ double d = 1.0 - 1; }
{ double d = big * 1.0; }
{ double d = 1.0 * big; }
// Reset big to positive value.
big = 123456789012345;
// -- isNegative --.
// Smi.
Expect.equals(false, (0).isNegative);
Expect.equals(false, (1).isNegative);
Expect.equals(true, (-1).isNegative);
// Big.
Expect.equals(false, big.isNegative);
Expect.equals(true, (-big).isNegative);
// Double.
// TODO(srdjan): enable the following test once isNegative works.
// Expect.equals(true, (-0.0).isNegative);
Expect.equals(false, (0.0).isNegative);
Expect.equals(false, (2.0).isNegative);
Expect.equals(true, (-2.0).isNegative);
double negateDouble(double x) {
return -x;
}
Expect.isTrue(negateDouble(0.0).isNegative);
Expect.isFalse(negateDouble(-0.0).isNegative);
Expect.isTrue(negateDouble(3.5e3).isNegative);
Expect.isFalse(negateDouble(-3.5e3).isNegative);
// Constants.
final nan = 0.0/0.0;
final infinity = 1.0/0.0;
// -- isInfinite --.
// Smi.
Expect.equals(false, (0).isInfinite);
Expect.equals(false, (1).isInfinite);
Expect.equals(false, (-1).isInfinite);
// Big.
Expect.equals(false, big.isInfinite);
Expect.equals(false, (-big).isInfinite);
// Double.
Expect.equals(false, (0.0).isInfinite);
Expect.equals(true, infinity.isInfinite);
Expect.equals(true, (-infinity).isInfinite);
Expect.equals(false, (12.0).isInfinite);
Expect.equals(false, (-12.0).isInfinite);
Expect.equals(false, nan.isInfinite);
// -- isNaN --.
// Smi.
Expect.equals(false, (0).isNaN);
Expect.equals(false, (1).isNaN);
Expect.equals(false, (-1).isNaN);
// Big.
Expect.equals(false, big.isNaN);
Expect.equals(false, (-big).isNaN);
// Double.
Expect.equals(true, nan.isNaN);
Expect.equals(false, (12.0).isNaN);
Expect.equals(false, infinity.isNaN);
// -- abs --.
// Smi.
Expect.equals(0, (0).abs());
Expect.equals(2, (2).abs());
Expect.equals(2, (-2).abs());
// Big.
Expect.equals(big, big.abs());
Expect.equals(big, (-big).abs());
// Double.
Expect.equals(false, (0.0).abs().isNegative);
Expect.equals(false, (-0.0).abs().isNegative);
Expect.equals(2.0, (2.0).abs());
Expect.equals(2.0, (-2.0).abs());
// -- ceil --.
// Smi.
Expect.equals(0, (0).ceil());
Expect.equals(1, (1).ceil());
Expect.equals(-1, (-1).ceil());
// Big.
Expect.equals(big, big.ceil());
Expect.equals(-big, (-big).ceil());
// Double.
Expect.equals(0, (0.0).ceil());
Expect.equals(false, (0.0).ceil().isNegative);
Expect.equals(1, (0.1).ceil());
Expect.equals(1, double.MIN_POSITIVE.ceil());
Expect.equals(1, (0.49999999999999994).ceil());
Expect.equals(0, (-0.0).ceil());
Expect.equals(0, (-0.3).ceil());
Expect.isTrue((-0.0).ceil() is int);
Expect.isTrue((-0.3).ceil() is int);
Expect.equals(0, (-0.49999999999999994).ceil());
Expect.equals(3, (2.1).ceil());
Expect.equals(-2, (-2.1).ceil());
// -- floor --.
// Smi.
Expect.equals(0, (0).floor());
Expect.equals(1, (1).floor());
Expect.equals(-1, (-1).floor());
// Big.
Expect.equals(big, big.floor());
Expect.equals(-big, (-big).floor());
// Double.
Expect.equals(0, (0.0).floor());
Expect.equals(0, (0.1).floor());
Expect.equals(0, (0.49999999999999994).floor());
Expect.equals(0, double.MIN_POSITIVE.floor());
Expect.isTrue((0.0).floor() is int);
Expect.isTrue((0.1).floor() is int);
Expect.equals(0, (-0.0).floor());
Expect.isTrue((-0.0).floor() is int);
Expect.equals(-1, (-0.1).floor());
Expect.equals(2, (2.1).floor());
Expect.equals(-3, (-2.1).floor());
Expect.equals(-1.0, (-0.49999999999999994).floor());
Expect.equals(-3.0, (-2.1).floor());
// -- truncate --.
// Smi.
Expect.equals(0, (0).truncate());
Expect.equals(1, (1).truncate());
Expect.equals(-1, (-1).truncate());
// Big.
Expect.equals(big, big.truncate());
Expect.equals(-big, (-big).truncate());
// Double.
Expect.equals(0, (0.0).truncate());
Expect.equals(0, (0.1).truncate());
Expect.isTrue((0.0).truncate() is int);
Expect.isTrue((0.1).truncate() is int);
Expect.equals(0, (-0.0).truncate());
Expect.equals(0, (-0.3).truncate());
Expect.isTrue((-0.0).truncate() is int);
Expect.isTrue((-0.3).truncate() is int);
Expect.equals(2, (2.1).truncate());
Expect.equals(-2, (-2.1).truncate());
int b1 = (1234567890123.0).truncate();
int b2 = (1234567890124.0).truncate();
Expect.equals(b2, b1 + 1.0);
// -- round --.
// Smi.
Expect.equals(0, (0).round());
Expect.equals(1, (1).round());
Expect.equals(-1, (-1).round());
// Big.
Expect.equals(big, big.round());
Expect.equals(-big, (-big).round());
// Double.
Expect.equals(3, (2.6).round());
Expect.equals(-3, (-2.6).round());
Expect.equals(0, (0.0).round());
Expect.equals(0, (0.1).round());
Expect.equals(3, (2.5).round());
Expect.equals(-3, (-2.5).round());
Expect.isFalse((0.0).round().isNegative);
Expect.isFalse((0.1).round().isNegative);
Expect.equals(0, (-0.0).round());
Expect.equals(0, (-0.3).round());
Expect.equals(2, (2.1).round());
Expect.equals(-2, (-2.1).round());
Expect.equals(1, (0.5).round());
Expect.equals(-1, (-0.5).round());
Expect.isTrue((-0.0).round() is int);
Expect.isTrue((-0.3).round() is int);
Expect.isTrue((-0.5).round() is int);
Expect.equals(2, (1.5).round());
Expect.equals(-2, (-1.5).round());
Expect.equals(1, (0.99).round());
// -- toInt --.
// Smi.
Expect.equals(0, (0).toInt());
Expect.equals(1, (1).toInt());
Expect.equals(-1, (-1).toInt());
// Type checks.
{ int i = (0).toInt(); }
{ int i = (1).toInt(); }
{ int i = (-1).toInt(); }
// Big.
Expect.equals(big, big.toInt());
Expect.equals(-big, (-big).toInt());
{ int i = big.toInt(); }
{ int i = (-big).toInt(); }
// Double.
Expect.equals(1234567890123, (1234567890123.0).toInt());
Expect.equals(-1234567890123, (-1234567890123.0).toInt());
{ int i = (1234567890123.0).toInt(); }
{ int i = (-1234567890123.0).toInt(); }
// 32bit Smi border cases.
Expect.equals(-1073741824, (-1073741824.0).toInt());
Expect.equals(-1073741825, (-1073741825.0).toInt());
Expect.equals(1073741823, (1073741823.0).toInt());
Expect.equals(1073741824, (1073741824.0).toInt());
{ int i = (-1073741824.0).toInt(); }
{ int i = (-1073741825.0).toInt(); }
{ int i = (1073741823.0).toInt(); }
{ int i = (1073741824.0).toInt(); }
// -- toDouble --.
// Smi.
Expect.equals(0.0, (0).toDouble());
Expect.equals(1.0, (1).toDouble());
Expect.equals(-1.0, (-1).toDouble());
// Type checks.
{ double d = (0).toDouble(); }
{ double d = (1).toDouble(); }
{ double d = (-1).toDouble(); }
// Big.
Expect.equals(big, big.toInt());
Expect.equals(-big, (-big).toInt());
{ int i = big.toInt(); }
{ int i = (-big).toInt(); }
// Math functions.
Expect.equals(2.0, sqrt(4.0));
Expect.approxEquals(1.0, sin(3.14159265 / 2.0));
Expect.approxEquals(-1.0, cos(3.14159265));
Expect.equals(12, int.parse("12"));
Expect.equals(-12, int.parse("-12"));
Expect.equals(12345678901234567890,
int.parse("12345678901234567890"));
Expect.equals(-12345678901234567890,
int.parse("-12345678901234567890"));
// Type checks.
{ int i = int.parse("12"); }
{ int i = int.parse("-12"); }
{ int i = int.parse("12345678901234567890"); }
{ int i = int.parse("-12345678901234567890"); }
Expect.equals(1.2, double.parse("1.2"));
Expect.equals(-1.2, double.parse("-1.2"));
// Type checks.
{ double d = double.parse("1.2"); }
{ double d = double.parse("-1.2"); }
{ double d = double.parse("0"); }
// Random
{
Random rand = new Random();
double d = rand.nextDouble();
}
Expect.equals(false, exceptionCaughtParseInt("22"));
Expect.equals(true, exceptionCaughtParseInt("alpha"));
Expect.equals(true, exceptionCaughtParseInt("-alpha"));
Expect.equals(false, exceptionCaughtParseDouble("22.2"));
Expect.equals(true, exceptionCaughtParseDouble("alpha"));
Expect.equals(true, exceptionCaughtParseDouble("-alpha"));
Expect.equals(false, double.parse("1.2").isNaN);
Expect.equals(false, double.parse("1.2").isInfinite);
Expect.equals(true, double.parse("NaN").isNaN);
Expect.equals(true, double.parse("Infinity").isInfinite);
Expect.equals(true, double.parse("-Infinity").isInfinite);
Expect.equals(false, double.parse("NaN").isNegative);
Expect.equals(false, double.parse("Infinity").isNegative);
Expect.equals(true, double.parse("-Infinity").isNegative);
Expect.equals("NaN", double.parse("NaN").toString());
Expect.equals("Infinity", double.parse("Infinity").toString());
Expect.equals("-Infinity", double.parse("-Infinity").toString());
Expect.equals(false, toIntThrowsUnsupportedError("1.2"));
Expect.equals(true, toIntThrowsUnsupportedError("Infinity"));
Expect.equals(true, toIntThrowsUnsupportedError("-Infinity"));
Expect.equals(true, toIntThrowsUnsupportedError("NaN"));
// Min/max
Expect.equals(1, min(1, 12));
Expect.equals(12, max(1, 12));
Expect.equals(1.0, min(1.0, 12.0));
Expect.equals(12.0, max(1.0, 12.0));
Expect.equals(false, 1.0 < min(1.0, 12.0));
Expect.equals(true, 1.0 < max(1.0, 12.0));
// Hashcode
Expect.equals(false, (3.4).hashCode == (1.2).hashCode);
Expect.equals(true, (1.2).hashCode == (1.2).hashCode);
Expect.equals(false, (3).hashCode == (1).hashCode);
Expect.equals(true, (10).hashCode == (10).hashCode);
}
static int div(a, b) => a ~/ b;
static void testSmiDivDeopt() {
var a = -0x40000000;
var b = -1;
for (var i = 0; i < 10; i++) Expect.equals(0x40000000, div(a, b));
}
static int divMod(a, b) => a ~/ b + a % b;
static void testSmiDivModDeopt() {
var a = -0x40000000;
var b = -1;
for (var i = 0; i < 10; i++) Expect.equals(0x40000000, divMod(a, b));
}
static double sinCosSub(double a) => sin(a) - cos(a);
static double sinCosAddCos(double a) => sin(a) * cos(a) + cos(a);
static void testSinCos() {
var e = sin(1.234) - cos(1.234);
var f = sin(1.234) * cos(1.234) + cos(1.234);
for (var i = 0; i < 20; i++) {
Expect.approxEquals(e, sinCosSub(1.234));
Expect.approxEquals(f, sinCosAddCos(1.234));
}
Expect.approxEquals(1.0, sinCosSub(3.14159265));
Expect.approxEquals(1.0, sinCosSub(3.14159265 / 2.0));
}
// Test fix for issue 16592.
static void testSinCosNoUse() {
for (var i = 0; i < 20; i++) {
sin(i);
cos(i);
}
}
static mySqrt(var x) => sqrt(x);
static testSqrtDeopt() {
for (var i = 0; i < 10; i++) mySqrt(4.0);
Expect.equals(2.0, mySqrt(4.0));
Expect.throws(() => mySqrt("abc"));
}
static self_equality(x) {
return x == x;
}
static testDoubleEquality() {
Expect.isFalse(self_equality(double.NAN));
for (int i = 0; i < 20; i++) {
self_equality(3.0);
}
Expect.isFalse(self_equality(double.NAN));
}
static testMain() {
for (int i = 0; i < 20; i++) {
runOne();
testSmiDivDeopt();
testSmiDivModDeopt();
testSqrtDeopt();
testDoubleEquality();
testSinCos();
testSinCosNoUse();
}
}
}
main() {
ArithmeticTest.testMain();
}

View file

@ -0,0 +1,31 @@
// 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.
// Dart test program to test arithmetic operations.
// VMOptions=--optimization-counter-threshold=10 --checked
// This test crashes if we recompute type of AssertAssignableInstr based on its
// output types. By doing that we would eliminate not only the unnecessary
// AssertAssignableInstr but also the trailing class check.
main() {
// Foul up IC data in integer's unary minus.
var y = -0x80000000;
testInt64List();
}
testInt64List() {
var array = new List(10);
testInt64ListImpl(array);
}
testInt64ListImpl(array) {
for (int i = 0; i < 10; ++i) {
}
int sum = 0;
for (int i = 0; i < 10; ++i) {
array[i] = -0x80000000000000 + i;
}
}

View file

@ -0,0 +1,28 @@
// 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.
// Issue 3741: generic type tests and casts fail in assertion statements
// when run in production mode.
//
// The cause was incomplete generic type skipping, so each of the assert
// statements below would fail.
//
// VMOptions=
// VMOptions=--enable_asserts
main() {
var names = new List<int>();
// Generic type test.
assert(names is List<int>);
// Negated generic type test.
assert(names is !List<String>);
// Generic type cast.
assert((names as List<num>).length == 0);
// Generic type test inside expression.
assert((names is List<int>));
}

View file

@ -0,0 +1,77 @@
// Copyright (c) 2011, 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.
// VMOptions=--enable_type_checks
//
// Dart test program testing assert statements.
import "package:expect/expect.dart";
class AssertionTest {
static testTrue() {
int i = 0;
try {
assert(true);
} on AssertionError catch (error) {
i = 1;
}
return i;
}
static testFalse() {
int i = 0;
try {
assert(false);
} on AssertionError catch (error) {
i = 1;
}
return i;
}
static unknown(var a) {
return (a) ? true : false;
}
static testUnknown() {
var x = unknown(false);
int i = 0;
try {
assert(x);
} on AssertionError catch (error) {
i = 1;
}
return i;
}
static testClosure() {
int i = 0;
try {
assert(() => false);
} on AssertionError catch (error) {
i = 1;
}
return i;
}
static testClosure2() {
int i = 0;
try {
var x = () => false;
assert(x);
} on AssertionError catch (error) {
i = 1;
}
return i;
}
static testMain() {
Expect.equals(0, testTrue());
Expect.equals(1, testFalse());
Expect.equals(1, testClosure());
Expect.equals(1, testClosure2());
}
}
main() {
AssertionTest.testMain();
}

View file

@ -0,0 +1,14 @@
// Copyright (c) 2011, 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.
class A {
A() {}
imethod() { return 0; }
}
main() {
var a = new A();
// Illegal, can't change a member method
a.imethod = () { return 1; };
}

View file

@ -0,0 +1,96 @@
// Copyright (c) 2011, 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.
// Dart test program for testing assign operators.
// VMOptions=--optimization-counter-threshold=10
import "package:expect/expect.dart";
class AssignOpTest {
AssignOpTest() {}
static testMain() {
var b = 0;
b += 1;
Expect.equals(1, b);
b *= 5;
Expect.equals(5, b);
b -= 1;
Expect.equals(4, b);
b ~/= 2;
Expect.equals(2, b);
f = 0;
f += 1;
Expect.equals(1, f);
f *= 5;
Expect.equals(5, f);
f -= 1;
Expect.equals(4, f);
f ~/= 2;
Expect.equals(2, f);
f /= 4;
Expect.equals(.5, f);
AssignOpTest.f = 0;
AssignOpTest.f += 1;
Expect.equals(1, AssignOpTest.f);
AssignOpTest.f *= 5;
Expect.equals(5, AssignOpTest.f);
AssignOpTest.f -= 1;
Expect.equals(4, AssignOpTest.f);
AssignOpTest.f ~/= 2;
Expect.equals(2, AssignOpTest.f);
AssignOpTest.f /= 4;
Expect.equals(.5, f);
var o = new AssignOpTest();
o.instf = 0;
o.instf += 1;
Expect.equals(1, o.instf);
o.instf *= 5;
Expect.equals(5, o.instf);
o.instf -= 1;
Expect.equals(4, o.instf);
o.instf ~/= 2;
Expect.equals(2, o.instf);
o.instf /= 4;
Expect.equals(.5, o.instf);
var x = 0xFF;
x >>= 3;
Expect.equals(0x1F, x);
x <<= 3;
Expect.equals(0xF8, x);
x |= 0xF00;
Expect.equals(0xFF8, x);
x &=0xF0;
Expect.equals(0xF0, x);
x ^=0x11;
Expect.equals(0xE1, x);
var y = 100;
y += 1 << 3;
Expect.equals(108, y);
y *= 2 + 1;
Expect.equals(324, y);
y -= 3 - 2;
Expect.equals(323, y);
y += 3 * 4;
Expect.equals(335, y);
var a = [1, 2, 3];
var ix = 0;
a[ix] |= 12;
Expect.equals(13, a[ix]);
}
static var f;
var instf;
}
main() {
for (int i = 0; i < 20; i++) {
AssignOpTest.testMain();
}
}

View file

@ -0,0 +1,32 @@
// 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.
// This test insures that statically initialized variables, fields, and parameters
// report static type warnings.
int a = "String"; /// 01: static type warning, dynamic type error
class A {
static const int c = "String"; /// 02: static type warning, checked mode compile-time error
final int d = "String"; /// 03: static type warning, dynamic type error
int e = "String"; /// 04: static type warning, dynamic type error
A() {
int f = "String"; /// 05: static type warning, dynamic type error
}
method([
int /// 06: static type warning
g = "String"]) {
return g;
}
}
int main() {
var w = a; /// 01: continued
var x;
x = A.c; /// 02: continued
var v = new A();
x = v.d; /// 03: continued
x = v.e; /// 04: continued
x = v.method(1); /// 06: continued
}

View file

@ -0,0 +1,29 @@
// 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.
// Verify that an attempt to assign to a class, enum, typedef, or type
// parameter produces a static warning and runtime error.
import "package:expect/expect.dart";
noMethod(e) => e is NoSuchMethodError;
class C<T> {
f() {
Expect.throws(() => T = null, noMethod); /// 01: static type warning
}
}
class D {}
enum E { e0 }
typedef void F();
main() {
new C<D>().f();
Expect.throws(() => D = null, noMethod); /// 02: static type warning
Expect.throws(() => E = null, noMethod); /// 03: static type warning
Expect.throws(() => F = null, noMethod); /// 04: static type warning
}

View file

@ -0,0 +1,13 @@
// 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";
method() { return 0; }
main() {
// Illegal, can't change a top level method
Expect.throws(() { method = () { return 1; }; }, /// 01: static type warning
(e) => e is NoSuchMethodError); /// 01: continued
}

View file

@ -0,0 +1,44 @@
// 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 to detect syntactically illegal left-hand-side (assignable)
// expressions.
class C {
static var static_field = 0;
}
var tl_static_var = 0;
main() {
tl_static_var = 0;
(tl_static_var) = 0; /// 01: compile-time error
(tl_static_var)++; /// 02: compile-time error
++(tl_static_var); /// 03: compile-time error
C.static_field = 0;
(C.static_field) = 0; /// 11: compile-time error
(C.static_field)++; /// 12: compile-time error
++(C.static_field); /// 13: compile-time error
tl_static_var = [1, 2, 3];
tl_static_var[0] = 0;
(tl_static_var)[0] = 0;
(tl_static_var[0]) = 0; /// 21: compile-time error
(tl_static_var[0])++; /// 22: compile-time error
++(tl_static_var[0]); /// 23: compile-time error
C.static_field = [1, 2, 3];
(C.static_field[0]) = 0; /// 31: compile-time error
(C.static_field[0])++; /// 32: compile-time error
++(C.static_field[0]); /// 33: compile-time error
var a = 0;
(a) = 0; /// 41: compile-time error
(a)++; /// 42: compile-time error
++(a); /// 43: compile-time error
// Neat palindrome expression. x is assignable, ((x)) is not.
var funcnuf = (x) => ((x))=((x)) <= (x); /// 50: compile-time error
}

View file

@ -0,0 +1,302 @@
// 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.
// Test async/await syntax.
import 'dart:async' show Stream;
var yield = 0;
var await = 0;
get st => new Stream.fromIterable([]);
a01a() async => null; /// a01a: ok
a01b() async* => null; /// a01b: compile-time error
a01c() sync* => null; /// a01c: compile-time error
a01d() async => yield 5; /// a01d: compile-time error
a02a() async {} /// a02a: ok
a03a() async* {} /// a03a: ok
a03b() async * {} /// a03b: ok
a04a() sync* {} /// a04a: ok
a04b() sync {} /// a04b: compile-time error
a04c() sync * {} /// a04c: ok
a05a() async { await 0; } /// a05a: ok
a05b() async { /// a05b: ok
await(a) {}; /// a05b: continued
await(0); /// a05b: continued
} /// a05b: continued
a05c() { /// a05c: ok
await(a) {}; /// a05c: continued
await(0); /// a05c: continued
} /// a05c: continued
a05d() async { /// a05d: compile-time error
await(a) {} /// a05d: continued
await(0); /// a05d: continued
} /// a05d: continued
a05e() { /// a05e: ok
await(a) {} /// a05e: continued
await(0); /// a05e: continued
} /// a05e: continued
a05f() async { /// a05f: compile-time error
var await = (a) {}; /// a05f: continued
await(0); /// a05f: continued
} /// a05f: continued
a05g() async { /// a05g: continued
yield 5; /// a05g: compile-time error
} /// a05g: continued
a05h() async { /// a05h: continued
yield* st; /// a05h: compile-time error
} /// a05h: continued
a06a() async { await for (var o in st) {} } /// a06a: ok
a06b() sync* { await for (var o in st) {} } /// a06b: compile-time error
a07a() sync* { yield 0; } /// a07a: ok
a07b() sync { yield 0; } /// a07b: compile-time error
a08a() sync* { yield* []; } /// a08a: ok
a08b() sync { yield 0; } /// a08b: compile-time error
a09a() async* { yield 0; } /// a09a: ok
a10a() async* { yield* []; } /// a10a: static type warning
get sync sync {} /// a11a: compile-time error
get sync sync* {} /// a11b: ok
get async async {} /// a11c: ok
get async async* {} /// a11d: ok
get sync {} /// a12a: ok
get sync* {} /// a12b: compile-time error
get async {} /// a12c: ok
get async* {} /// a12d: compile-time error
get a12e sync* => null; /// a12e: compile-time error
get a12f async* => null; /// a12f: compile-time error
get a12g async => null; /// a12g: ok
int sync; /// a13a: ok
int sync*; /// a13b: compile-time error
int async; /// a13c: ok
int async*; /// a13d: compile-time error
var sync; /// a14a: ok
var sync*; /// a14b: compile-time error
var async; /// a14c: ok
var async*; /// a14d: compile-time error
sync() {} /// a15a: ok
sync*() {} /// a15b: compile-time error
async() {} /// a15c: ok
async*() {} /// a15d: compile-time error
abstract class B {
b00a() async; /// b00a: compile-time error
b00b() async*; /// b00b: compile-time error
b00c() sync*; /// b00c: compile-time error
b00d() sync; /// b00d: compile-time error
}
class C extends B {
C();
factory C.e1() async { return null; } /// e1: compile-time error
factory C.e2() async* { return null; } /// e2: compile-time error
factory C.e3() sync* { return null; } /// e3: compile-time error
factory C.e4() async = C; /// e4: compile-time error
factory C.e5() async* = C; /// e5: compile-time error
factory C.e6() sync* = C; /// e6: compile-time error
C.e7() async {} /// e7: compile-time error
C.e8() async* {} /// e8: compile-time error
C.e9() sync* {} /// e9: compile-time error
b00a() {} /// b00a: continued
b00b() {} /// b00b: continued
b00c() {} /// b00c: continued
b00d() {} /// b00d: continued
b01a() async => null; /// b01a: ok
b01b() async* => null; /// b01b: compile-time error
b01c() sync* => null; /// b01c: compile-time error
b02a() async {} /// b02a: ok
b03a() async* {} /// b03a: ok
b04a() sync* {} /// b04a: ok
b04b() sync {} /// b04b: compile-time error
b05a() async { await 0; } /// b05a: ok
b06a() async { await for (var o in st) {} } /// b06a: ok
b06b() async { await for ( ; ; ) {} } /// b06b: compile-time error
b07a() sync* { yield 0; } /// b07a: ok
b08a() sync* { yield* []; } /// b08a: ok
b09a() async* { yield 0; } /// b09a: ok
b10a() async* { yield* []; } /// b10a: static type warning
b10b() async { yield 0; } /// b10b: compile-time error
get sync sync {} /// b11a: compile-time error
get sync sync* {} /// b11b: ok
get async async {} /// b11c: ok
get async async* {} /// b11d: ok
get sync {} /// b12a: ok
get sync* {} /// b12b: compile-time error
get async {} /// b12c: ok
get async* {} /// b12d: compile-time error
get b12e sync* => null; /// b12e: compile-time error
get b12f async* => null; /// b12f: compile-time error
get b12g async => null; /// b12g: ok
int sync; /// b13a: ok
int sync*; /// b13b: compile-time error
int async; /// b13c: ok
int async*; /// b13d: compile-time error
var sync; /// b14a: ok
var sync*; /// b14b: compile-time error
var async; /// b14c: ok
var async*; /// b14d: compile-time error
sync() {} /// b15a: ok
sync*() {} /// b15b: compile-time error
async() {} /// b15c: ok
async*() {} /// b15d: compile-time error
}
method1() {
c01a() async => null; c01a(); /// c01a: ok
c01b() async* => null; c01b(); /// c01b: compile-time error
c01c() sync* => null; c01c(); /// c01c: compile-time error
c02a() async {} c02a(); /// c02a: ok
c03a() async* {} c03a(); /// c03a: ok
c04a() sync* {} c04a(); /// c04a: ok
c04b() sync {} c04b(); /// c04b: compile-time error
c05a() async { await 0; } c05a(); /// c05a: ok
c06a() async { await for (var o in st) {} } c06a(); /// c06a: ok
c07a() sync* { yield 0; } c07a(); /// c07a: ok
c08a() sync* { yield* []; } c08a(); /// c08a: ok
c09a() async* { yield 0; } c09a(); /// c09a: ok
c10a() async* { yield* []; } c10a(); /// c10a: static type warning
c11a() async { yield -5; } c11a(); /// c11a: compile-time error
c11b() async { yield* st; } c11b(); /// c11b: compile-time error
}
method2() {
var d01a = () async => null; d01a(); /// d01a: ok
var d01b = () async* => null; d01b(); /// d01b: compile-time error
var d01c = () sync* => null; d01c(); /// d01c: compile-time error
var d02a = () async {}; d02a(); /// d02a: ok
var d03a = () async* {}; d03a(); /// d03a: ok
var d04a = () sync* {}; d04a(); /// d04a: ok
var d04b = () sync {}; d04b(); /// d04b: compile-time error
var d05a = () async { await 0; }; d05a(); /// d05a: ok
var d06a = () async { await for (var o in st) {} }; d06a(); /// d06a: ok
var d07a = () sync* { yield 0; }; d07a(); /// d07a: ok
var d08a = () sync* { yield* []; }; d08a(); /// d08a: ok
var d08b = () sync* { yield*0+1; }; d08b(); /// d08b: static type warning
var d08c = () { yield*0+1; }; d08c(); /// d08c: ok
var d09a = () async* { yield 0; }; d09a(); /// d09a: ok
var d10a = () async* { yield* []; }; d10a(); /// d10a: static type warning
}
void main() {
var a;
var c = new C();
c = new C.e1(); /// e1: continued
c = new C.e2(); /// e2: continued
c = new C.e3(); /// e3: continued
c = new C.e4(); /// e4: continued
c = new C.e5(); /// e5: continued
c = new C.e6(); /// e6: continued
c = new C.e7(); /// e7: continued
c = new C.e8(); /// e8: continued
c = new C.e9(); /// e9: continued
a01a(); /// a01a: continued
a01b(); /// a01b: continued
a01c(); /// a01c: continued
a01d(); /// a01d: continued
a02a(); /// a02a: continued
a03a(); /// a03a: continued
a03b(); /// a03b: continued
a04a(); /// a04a: continued
a04b(); /// a04b: continued
a04c(); /// a04c: continued
a05a(); /// a05a: continued
a05b(); /// a05b: continued
a05c(); /// a05c: continued
a05d(); /// a05d: continued
a05e(); /// a05e: continued
a05f(); /// a05f: continued
a05g(); /// a05g: continued
a05h(); /// a05h: continued
a06a(); /// a06a: continued
a06b(); /// a06b: continued
a07a(); /// a07a: continued
a07b(); /// a07b: continued
a08a(); /// a08a: continued
a08b(); /// a08b: continued
a09a(); /// a09a: continued
a10a(); /// a10a: continued
a = sync; /// a11a: continued
a = sync; /// a11b: continued
a = async; /// a11c: continued
a = async; /// a11d: continued
a = sync; /// a12a: continued
a = sync; /// a12b: continued
a = async; /// a12c: continued
a = async; /// a12d: continued
a = a12e; /// a12e: continued
a = a12f; /// a12f: continued
a = a12g; /// a12g: continued
a = sync; /// a13a: continued
a = sync; /// a13b: continued
a = async; /// a13c: continued
a = async; /// a13d: continued
a = sync; /// a14a: continued
a = sync; /// a14b: continued
a = async; /// a14c: continued
a = async; /// a14d: continued
sync(); /// a15a: continued
sync(); /// a15b: continued
async(); /// a15c: continued
async(); /// a15d: continued
c.b00a(); /// b00a: continued
c.b00b(); /// b00b: continued
c.b00c(); /// b00c: continued
c.b00d(); /// b00d: continued
c.b01a(); /// b01a: continued
c.b01b(); /// b01b: continued
c.b01c(); /// b01c: continued
c.b02a(); /// b02a: continued
c.b03a(); /// b03a: continued
c.b04a(); /// b04a: continued
c.b04b(); /// b04b: continued
c.b05a(); /// b05a: continued
c.b06a(); /// b06a: continued
c.b06b(); /// b06b: continued
c.b07a(); /// b07a: continued
c.b08a(); /// b08a: continued
c.b09a(); /// b09a: continued
c.b10a(); /// b10a: continued
c.b10b(); /// b10b: continued
a = c.sync; /// b11a: continued
a = c.sync; /// b11b: continued
a = c.async; /// b11c: continued
a = c.async; /// b11d: continued
a = c.sync; /// b12a: continued
a = c.sync; /// b12b: continued
a = c.async; /// b12c: continued
a = c.async; /// b12d: continued
a = c.b12e; /// b12e: continued
a = c.b12f; /// b12f: continued
a = c.b12g; /// b12g: continued
a = c.sync; /// b13a: continued
a = c.sync; /// b13b: continued
a = c.async; /// b13c: continued
a = c.async; /// b13d: continued
a = c.sync; /// b14a: continued
a = c.sync; /// b14b: continued
a = c.async; /// b14c: continued
a = c.async; /// b14d: continued
c.sync(); /// b15a: continued
c.sync(); /// b15b: continued
c.async(); /// b15c: continued
c.async(); /// b15d: continued
method1();
method2();
}

View file

@ -0,0 +1,34 @@
// 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.
import "dart:async";
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
main() {
var sc;
var i = 0;
void send() {
if (i == 5) {
sc.close();
} else {
sc.add(i++);
}
}
sc = new StreamController(onListen: send, onResume: send);
f(s) async {
var r = 0;
await for (var i in s) {
r += await new Future.delayed(new Duration(milliseconds: 10), () => i);
}
return r;
}
asyncStart();
f(sc.stream).then((v) {
Expect.equals(10, v);
asyncEnd();
});
}

View file

@ -0,0 +1,66 @@
// 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.
// This is a regression test for issue 22853.
import "dart:async";
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
main() {
var list = [];
var sync = new Sync();
f() async* {
list.add("*1");
yield 1;
await sync.wait();
sync.release();
list.add("*2");
yield 2;
list.add("*3");
};
var stream = f();
var sub = stream.listen(list.add);
asyncStart();
return sync.wait().whenComplete(() {
Expect.listEquals(list, ["*1", 1]);
sub.pause();
return sync.wait();
}).whenComplete(() {
Expect.listEquals(list, ["*1", 1, "*2"]);
sub.cancel();
new Future.delayed(new Duration(milliseconds: 200), () {
// Should not have yielded 2 or added *3 while paused.
Expect.listEquals(list, ["*1", 1, "*2"]);
asyncEnd();
});
});
}
/**
* Allows two asynchronous executions to synchronize.
*
* Calling [wait] and waiting for the returned future to complete will
* wait for the other executions to call [wait] again. At that point,
* the waiting execution is allowed to continue (the returned future completes),
* and the more recent call to [wait] is now the waiting execution.
*/
class Sync {
Completer _completer = null;
// Release whoever is currently waiting and start waiting yourself.
Future wait([v]) {
if (_completer != null) _completer.complete(v);
_completer = new Completer();
return _completer.future;
}
// Release whoever is currently waiting.
void release([v]) {
if (_completer != null) {
_completer.complete(v);
_completer = null;
}
}
}

View file

@ -0,0 +1,20 @@
// 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.
// This is a regression test for issue 2238
import "dart:async";
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
main() {
f() async* {
label1: label2: yield 0;
}
asyncStart();
f().toList().then((list) {
Expect.listEquals([0], list);
asyncEnd();
});
}

View file

@ -0,0 +1,44 @@
// 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.
// This test may crash dart2js.
import "dart:async";
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
main() {
var res = [];
fisk() async* {
res.add("+fisk");
try {
for (int i = 0; i < 2; i++) {
yield await new Future.microtask(() => i);
}
} finally {
res.add("-fisk");
}
}
fugl(int count) async {
res.add("fisk $count");
try {
await for(int i in fisk().take(count)) res.add(i);
} finally {
res.add("done");
}
}
asyncStart();
fugl(3).whenComplete(() => fugl(2))
.whenComplete(() => fugl(1))
.whenComplete(() {
Expect.listEquals(
["fisk 3", "+fisk", 0, 1, "-fisk", "done",
"fisk 2", "+fisk", 0, 1, "-fisk", "done",
"fisk 1", "+fisk", 0, "-fisk", "done"],
res);
asyncEnd();
});
}

View file

@ -0,0 +1,26 @@
// 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.
import "dart:async";
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
Stream makeStream(int n) async* {
for (int i = 0; i < n; i++) yield i;
}
main() {
f(Stream s) async {
var r = 0;
await for(var v in s.take(5)) r += v;
return r;
}
asyncStart();
f(makeStream(10)).then((v) {
Expect.equals(10, v);
asyncEnd();
});
}

View file

@ -0,0 +1,27 @@
// 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.
import "dart:async";
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
expectList(stream, list) {
return stream.toList().then((v) {
Expect.listEquals(v, list);
});
}
Stream makeStream(int n) async* {
for (int i = 0; i < n; i++) yield i;
}
main() {
fivePartialSums(Stream s) async* {
var r = 0;
await for(var v in s.take(5)) yield r += v;
}
asyncStart();
expectList(fivePartialSums(makeStream(10)), [0, 1, 3, 6, 10])
.then(asyncSuccess);
}

View file

@ -0,0 +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.
import 'dart:async';
import 'package:expect/expect.dart';
get await => 4;
// For functions that are declared with the async modifier we treat await as
// keyword.
test0() async {
var x = await 7;
Expect.equals(7, x);
var await = 1; /// await1: compile-time error
}
test1() async {
var x = await 9;
Expect.equals(9, x);
var y = await; /// await2: compile-time error
}
// For functions that are not declared with the async modifier we allow await to
// be used as an identifier.
test2() {
var y = await;
Expect.equals(4, y);
var x = await 1; /// await3: compile-time error
}
test3() {
var await = 3;
Expect.equals(3, await);
var x = await 1; /// await4: compile-time error
}
main() {
test0();
test1();
test2();
test3();
}

View file

@ -0,0 +1,98 @@
// 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.
// VMOptions=--optimization-counter-threshold=5
import 'package:expect/expect.dart';
import "package:async_helper/async_helper.dart";
import 'dart:async';
// It does not matter where a future is generated.
bar(p) async => p;
baz(p) => new Future(() => p);
test0_1() async {
throw 1;
}
test0() async {
try {
await test0_1();
} catch (e) {
Expect.equals(1, e);
}
}
test1_1() async {
throw 1;
}
test1_2() async {
try {
await test1_1();
} catch (e) {
throw e+1;
}
}
test1() async {
try {
await test1_2();
} catch (e) {
Expect.equals(2, e);
}
}
test2() async {
var x;
var test2_1 = () async {
try {
throw 'a';
} catch (e) {
throw e + 'b';
}
};
try {
try {
await test2_1();
} catch (e) {
var y = await bar(e + 'c');
throw y;
}
} catch (e) {
x = e + 'd';
return '?';
} finally {
return x;
}
return '!';
}
test() async {
var result;
for (int i = 0; i < 10; i++) {
await test0();
await test1();
result = await test2();
Expect.equals('abcd', result);
}
await 1;
}
foo() {
throw "Error";
}
awaitFoo() async {
await foo();
}
main() {
asyncStart();
test().then((_) => awaitFoo().then(
(_) => Expect.fail("Should have thrown"),
onError: (error) => Expect.equals("Error", error)))
.whenComplete(asyncEnd);
}

View file

@ -0,0 +1,92 @@
// 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:async";
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
bool canceled;
test1() async {
canceled = false;
try {
StreamController controller = infiniteStreamController();
outer: while(true) {
await for (var x in controller.stream) {
for (int j = 0; j < 10; j++) {
if (j == 5) break outer;
}
}
}
} finally {
Expect.isTrue(canceled);
}
}
test2() async {
canceled = false;
try {
StreamController controller = infiniteStreamController();
bool first = true;
outer: while(true) {
if (first) {
first = false;
} else {
break;
}
await for (var x in controller.stream) {
for (int j = 0; j < 10; j++) {
if (j == 5) continue outer;
}
}
}
} finally {
Expect.isTrue(canceled);
}
}
test() async {
await test1();
await test2();
}
main() {
asyncStart();
test().then((_) {
asyncEnd();
});
}
// Create a stream that produces numbers [1, 2, ... ]
StreamController infiniteStreamController() {
StreamController controller;
Timer timer;
int counter = 0;
void tick() {
if (controller.isPaused) {
return;
}
if (canceled) {
return;
}
counter++;
controller.add(counter); // Ask stream to send counter values as event.
Timer.run(tick);
}
void startTimer() {
Timer.run(tick);
}
controller = new StreamController(
onListen: startTimer,
onResume: startTimer,
onCancel: () {
canceled = true;
});
return controller;
}

View file

@ -0,0 +1,156 @@
// 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:async";
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
class Trace {
String trace = "";
record(x) {
trace += x.toString();
}
toString() => trace;
}
Stream makeMeAStream() {
return timedCounter(5);
}
Trace t1 = new Trace();
consumeOne() async {
// Equivalent to await for (x in makeMeAStream()) { ... }
var s = makeMeAStream();
var it = new StreamIterator(s);
while (await it.moveNext()) {
var x = it.current;
t1.record(x);
}
t1.record("X");
}
Trace t2 = new Trace();
consumeTwo() async {
await for (var x in makeMeAStream()) {
t2.record(x);
}
t2.record("Y");
}
Trace t3 = new Trace();
consumeNested() async {
await for (var x in makeMeAStream()) {
t3.record(x);
await for (var y in makeMeAStream()) {
t3.record(y);
}
t3.record("|");
}
t3.record("Z");
}
Trace t4 = new Trace();
consumeSomeOfInfinite() async {
int i = 0;
await for (var x in infiniteStream()) {
i++;
if (i > 10) break;
t4.record(x);
}
t4.record("U");
}
main() {
var f1 = consumeOne();
t1.record("T1:");
var f2 = consumeTwo();
t2.record("T2:");
var f3 = consumeNested();
t3.record("T3:");
var f4 = consumeSomeOfInfinite();
t4.record("T4:");
asyncStart();
Future.wait([f1, f2, f3, f4]).then((_) {
Expect.equals("T1:12345X", t1.toString());
Expect.equals("T2:12345Y", t2.toString());
Expect.equals("T3:112345|212345|312345|412345|512345|Z", t3.toString());
Expect.equals("T4:12345678910U", t4.toString());
asyncEnd();
});
}
// Create a stream that produces numbers [1, 2, ... maxCount]
Stream timedCounter(int maxCount) {
StreamController controller;
Timer timer;
int counter = 0;
void tick(_) {
counter++;
controller.add(counter); // Ask stream to send counter values as event.
if (counter >= maxCount) {
timer.cancel();
controller.close(); // Ask stream to shut down and tell listeners.
}
}
void startTimer() {
timer = new Timer.periodic(const Duration(milliseconds: 10), tick);
}
void stopTimer() {
if (timer != null) {
timer.cancel();
timer = null;
}
}
controller = new StreamController(
onListen: startTimer,
onPause: stopTimer,
onResume: startTimer,
onCancel: stopTimer);
return controller.stream;
}
// Create a stream that produces numbers [1, 2, ... ]
Stream infiniteStream() {
StreamController controller;
Timer timer;
int counter = 0;
void tick(_) {
counter++;
controller.add(counter); // Ask stream to send counter values as event.
}
void startTimer() {
timer = new Timer.periodic(const Duration(milliseconds: 10), tick);
}
void stopTimer() {
if (timer != null) {
timer.cancel();
timer = null;
}
}
controller = new StreamController(
onListen: startTimer,
onPause: stopTimer,
onResume: startTimer,
onCancel: stopTimer);
return controller.stream;
}

View file

@ -0,0 +1,40 @@
// 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.
import "dart:async";
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
sumStream(s) async {
int accum = 0;
await for (var v in s) {
accum += v;
}
return accum;
}
test() async {
var countStreamController;
int i = 0;
void tick() {
if (i < 10) {
countStreamController.add(i);
i++;
scheduleMicrotask(tick);
} else {
countStreamController.close();
}
}
countStreamController = new StreamController(
onListen: () {
scheduleMicrotask(tick);
});
Expect.equals(45, await sumStream(countStreamController.stream));
}
void main() {
asyncStart();
test().then((_) => asyncEnd());
}

View file

@ -0,0 +1,236 @@
// 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.
// VMOptions=--optimization-counter-threshold=5
import 'package:expect/expect.dart';
import "package:async_helper/async_helper.dart";
import 'dart:async';
// It does not matter where a future is generated.
bar(p) async => p;
baz(p) => new Future(() => p);
foo() async {
var b = 0;
for(int i = 0; i < 10; i++) {
b += (await bar(1)) + (await baz(2));
}
return b;
}
faa() async => (await bar('faa')).length;
quaz(p) async {
var x = 0;
try {
for (var j = 0; j < 10; j++) {
x += await baz(j);
}
return x;
} finally {
Expect.equals(x, 45);
return p;
}
}
quazz() async {
var x = 0;
try {
try {
x = await bar(1);
throw x;
} catch (e1) {
var y = await baz(e1 + 1);
throw y;
}
} catch (e2) {
return e2;
}
}
nesting() async {
try {
try {
var x = 1;
var y = () async {
try {
var z = (await bar(3)) + x;
throw z;
} catch (e1) {
return e1;
}
};
var a = await y();
throw a;
} catch (e2) {
throw e2 + 1;
}
} catch (e3) {
return e3;
}
}
awaitAsUnary(a,b) async {
return await a + await b;
}
awaitIf(p) async {
if (p < (await bar(5))) {
return "p<5";
} else {
return "p>=5";
}
}
awaitNestedIf(p,q) async {
if (p == (await bar(5))) {
if (q < (await bar(7))) {
return "q<7";
} else {
return "q>=7";
}
} else {
return "p!=5";
}
return "!";
}
awaitElseIf(p) async {
if (p > (await bar(5))) {
return "p>5";
} else if (p < (await bar(5))) {
return "p<5";
} else {
return "p==5";
}
return "!";
}
awaitReturn() async {
return await bar(17);
}
awaitSwitch() async {
switch(await bar(3)) {
case 1:
return 1;
break;
case 3:
return 3;
break;
default:
return -1;
}
}
awaitNestedWhile(int i, int j) async {
int savedJ = j;
var decI = () async {
return i--;
};
var decJ = () async {
return j--;
};
var k = 0;
while ((await decI()) > 0) {
j = savedJ;
while(0 < (await decJ())) {
k++;
}
}
return k;
}
awaitNestedDoWhile(int i, int j) async {
int savedJ = j;
var decI = () async {
return i--;
};
var decJ = () async {
return j--;
};
var k = 0;
do {
do {
k++;
} while (0 < (await decI()));
} while((await decJ()) > 0);
return k;
}
awaitFor() async {
var asyncInc = (p) async => p+1;
var k = 0;
for (int j = (await bar(0)), i = (await bar(1));
j < (await bar(5));
j = (await asyncInc(j)), i = (await asyncInc(i))) {
k += i;
k += j;
}
return k;
}
awaitForIn() async {
var list = ['a', 'b', 'c'];
var k = '';
for (var c in (await bar(list))) {
k += c;
}
return k;
}
test() async {
var result;
for (int i = 0; i < 10; i++) {
result = await foo();
Expect.equals(30, result);
result = await faa();
Expect.equals(3, result);
result = await quaz(17);
Expect.equals(17, result);
result = await quazz();
Expect.equals(2, result);
result = await nesting();
Expect.equals(5, result);
result = await awaitIf(3);
Expect.equals("p<5", result);
result = await awaitIf(5);
Expect.equals("p>=5", result);
result = await awaitNestedIf(5,3);
Expect.equals("q<7", result);
result = await awaitNestedIf(5,8);
Expect.equals("q>=7", result);
result = await awaitNestedIf(3,8);
Expect.equals("p!=5", result);
result = await awaitReturn();
Expect.equals(17, result);
result = await awaitSwitch();
Expect.equals(3, result);
result = await awaitElseIf(6);
Expect.equals("p>5", result);
result = await awaitElseIf(4);
Expect.equals("p<5", result);
result = await awaitElseIf(5);
Expect.equals("p==5", result);
result = await awaitNestedWhile(5,3);
Expect.equals(15, result);
result = await awaitNestedWhile(4,6);
Expect.equals(24, result);
result = await awaitAsUnary(bar(1), bar(2));
Expect.equals(3, result);
result = await awaitFor();
Expect.equals(25, result);
result = await awaitForIn();
Expect.equals('abc', result);
}
}
main() {
asyncStart();
test().then((_) {
asyncEnd();
});
}

View file

@ -0,0 +1,21 @@
// 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.
// VMOptions=--optimization-counter-threshold=5
import 'package:expect/expect.dart';
var X = 0;
foo() async {
Expect.equals(X, 10); // foo runs after main returns.
return await 5;
}
main() {
var f = foo();
f.then((res) => print("f completed with $res"));
X = 10;
}

View file

@ -0,0 +1,22 @@
// 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.
// Test that an async function does not start immediately.
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
var x = 0;
foo() async {
x++;
await 1;
x++;
}
void main() {
asyncStart();
foo().then((_) => Expect.equals(2, x)).whenComplete(asyncEnd);
Expect.equals(0, x);
}

View file

@ -0,0 +1,59 @@
// 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.
import "dart:async";
import "package:expect/expect.dart";
import "package:async_helper/async_helper.dart";
post0(a) async {
return await a++;
}
post1(a) async {
return await a++ + await a++;
}
pref0(a) async {
return await ++a;
}
pref1(a) async {
return await ++a + await ++a;
}
sum(a) async {
var s = 0;
for (int i = 0; i < a.length; /* nothing */) {
s += a[await i++];
}
return s;
}
// Adapted from repro case for issue 22875.
sum2(n) async {
int i, s = 0;
for (i = 1; i <= n; await i++) {
// The loop-local variable j was necessary for the crash in 22785.
var j = await i;
s += j;
}
return s;
}
test() async {
Expect.equals(10, await post0(10));
Expect.equals(21, await post1(10));
Expect.equals(11, await pref0(10));
Expect.equals(23, await pref1(10));
Expect.equals(10, await sum([1, 2, 3, 4]));
Expect.equals(10, await sum2(4));
}
main() {
asyncStart();
test().then((_) {
asyncEnd();
});
}

View file

@ -0,0 +1,36 @@
// 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:async';
import 'package:expect/expect.dart';
later(vodka) => new Future.value(vodka);
manana(tequila) async => tequila;
// Regression test for issue 21536.
testNestedFunctions() async {
var a = await later('Asterix').then((tonic) {
return later(tonic);
});
var o = await manana('Obelix').then(manana);
Expect.equals("$a and $o", "Asterix and Obelix");
}
addLater({a, b}) => new Future.value(a + b);
// Regression test for issue 21480.
testNamedArguments() async {
var sum = await addLater(a:5, b:10);
Expect.equals(sum, 15);
sum = await addLater(b:11, a:-11);
Expect.equals(sum, 0);
}
main() async {
testNestedFunctions();
testNamedArguments();
}

View file

@ -0,0 +1,132 @@
// 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.
// VMOptions=---optimization-counter-threshold=10
import 'package:expect/expect.dart';
import 'dart:async';
int globalVariable = 1;
int topLevelFoo(int param) => 1;
int get topLevelGetter => globalVariable;
void set topLevelSetter(val) {
globalVariable = val;
}
class C {
static int staticField = 1;
static int get staticGetter => staticField;
static void set staticSetter(val) {
staticField = val;
}
static int staticFoo(int param) => param;
int field = 1;
int get getter => field;
void set setter(val) {
field = val;
}
int foo(int param) => param;
}
dummy() => 1;
staticMembers() async {
var a = C.staticField + await dummy();
Expect.equals(a, 2);
var f = (C.staticField = 1) + await dummy();
Expect.equals(f, 2);
var b = C.staticGetter + await dummy();
Expect.equals(b, 2);
var c = (C.staticSetter = 1) + await dummy();
Expect.equals(c, 2);
var d = C.staticFoo(2) + await dummy();
Expect.equals(d, 3);
var e = C.staticField +
C.staticGetter +
(C.staticSetter = 1) +
C.staticFoo(1) +
await dummy();
Expect.equals(e, 5);
}
topLevelMembers() async {
var a = globalVariable + await dummy();
Expect.equals(a, 2);
var b = topLevelGetter + await dummy();
Expect.equals(b, 2);
var c = (topLevelSetter = 1) + await dummy();
Expect.equals(c, 2);
var d = topLevelFoo(1) + await dummy();
Expect.equals(d, 2);
var e = globalVariable +
topLevelGetter +
(topLevelSetter = 1) +
topLevelFoo(1) +
await dummy();
Expect.equals(e, 5);
}
instanceMembers() async {
var inst = new C();
var a = inst.field + await dummy();
Expect.equals(a, 2);
var b = inst.getter + await dummy();
Expect.equals(b, 2);
var c = (inst.setter = 1) + await dummy();
Expect.equals(c, 2);
var d = inst.foo(1) + await dummy();
Expect.equals(d, 2);
var e = inst.field +
inst.getter +
(inst.setter = 1) +
inst.foo(1) +
await dummy();
Expect.equals(e, 5);
}
await() => 4;
nonAsyncFunction() => await();
others() async {
var a = "${globalVariable} ${await dummy()} " + await "someString";
Expect.equals(a, "1 1 someString");
try {
var c = new C();
var d = c.nooooo() + await dummy();
} catch (e) {}
var cnt = 2;
var b = [1,2,3];
b[cnt] = await dummy();
Expect.equals(b[cnt], 1);
var e = b[0] + await dummy();
Expect.equals(e, 2);
Expect.equals(nonAsyncFunction(), 4);
}
conditionals() async {
var a = false;
var b = true;
var c = (a || b) || await dummy();
Expect.isTrue(c);
var d = (a || b) ? a : await dummy();
Expect.isFalse(d);
var e = (a is int) ? await dummy() : 2;
Expect.equals(e, 2);
try {
var f = (a is int) ? await dummy() : 2;
} catch(e) {}
}
main() {
for (int i = 0; i < 10; i++) {
staticMembers();
topLevelMembers();
instanceMembers();
conditionals();
others();
}
}

View file

@ -0,0 +1,26 @@
// 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.
class A {
// Constructor may not be static.
static A(); /// 00: compile-time error
// Factory may not be static.
static factory A() { return null; } /// 01: compile-time error
// Named constructor may not conflict with names of methods and fields.
var m;
A.m() { m = 0; } /// 04: compile-time error
set q(var value) { m = q; } // No name conflict with q=.
// The runtime error occurs because main calls new A() instead of new A.q().
A.q(); /// 05: runtime error
A.foo() : m = 0; /// 06: compile-time error
int foo(int a, int b) => a + b * m;
}
main() {
new A();
}

View file

@ -0,0 +1,15 @@
// Copyright (c) 2011, 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.
// Variable initializer must not reference the initialized variable.
class BadInitializer1NegativeTest {
static testMain() {
final List elems = const [
const [1, 2.0, true, false, 0xffffffffff, elems], "a", "b"];
}
}
main() {
BadInitializer1NegativeTest.testMain();
}

View file

@ -0,0 +1,23 @@
// Copyright (c) 2011, 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.
// Variable initializer must not reference the initialized variable.
import "package:expect/expect.dart";
class BadInitializer2NegativeTest {
static testMain() {
var foo = (int n) {
if (n == 0) {
return 0;
} else {
return 1 + foo(n - 1); // <-- self-reference to closure foo.
}
};
Expect.equals(4, foo(4));
}
}
main() {
BadInitializer2NegativeTest.testMain();
}

View file

@ -0,0 +1,11 @@
// Copyright (c) 2011, 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.
class BadNamedConstructorNegativeTest {
A.foo() {}
}
main() {
BadNamedConstructorNegativeTest.testMain();
}

View file

@ -0,0 +1,35 @@
// 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.
// Dart test program for testing bad named parameters.
import "package:expect/expect.dart";
class BadNamedParameters2Test {
int foo(int a) {
// Although no optional named parameters are declared, we must check that
// no named arguments are passed in, either here or in the resolving stub.
return a;
}
static testMain() {
BadNamedParameters2Test np = new BadNamedParameters2Test();
// Verify that NoSuchMethod is called after an error is detected.
bool caught;
try {
caught = false;
// No formal parameter named b.
np.foo(b:25); /// 01: static type warning
} on NoSuchMethodError catch (e) {
caught = true;
}
Expect.equals(true, caught); /// 01: continued
}
}
main() {
BadNamedParameters2Test.testMain();
}

View file

@ -0,0 +1,69 @@
// 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.
// Dart test program for testing bad named parameters.
import "package:expect/expect.dart";
class BadNamedParametersTest {
int f42(int a, {int b: 20, int c: 30}) {
return 100*(100*a + b) + c;
}
int f52(int a, {int b: 20, int c, int d: 40}) {
return 100*(100*(100*a + b) + (c == null ? 0 : c)) + d;
}
static testMain() {
BadNamedParametersTest np = new BadNamedParametersTest();
// Verify that NoSuchMethod is called after an error is detected.
bool caught;
try {
caught = false;
// Parameter b passed twice.
np.f42(10, 25, b:25); /// 01: static type warning
} on NoSuchMethodError catch (e) {
caught = true;
}
Expect.equals(true, caught); /// 01: continued
try {
caught = false;
// Parameter x does not exist.
np.f42(10, 25, x:99); /// 02: static type warning
} on NoSuchMethodError catch (e) {
caught = true;
}
Expect.equals(true, caught); /// 02: continued
try {
caught = false;
// Parameter b1 does not exist.
np.f52(10, b:25, b1:99, c:35); /// 03: static type warning
} on NoSuchMethodError catch (e) {
caught = true;
}
Expect.equals(true, caught); /// 03: continued
try {
caught = false;
// Too many parameters.
np.f42(10, 20, 30, 40); /// 04: static type warning
} on NoSuchMethodError catch (e) {
caught = true;
}
Expect.equals(true, caught); /// 04: continued
try {
caught = false;
// Too few parameters.
np.f42(b:25); /// 05: static type warning
} on NoSuchMethodError catch (e) {
caught = true;
}
Expect.equals(true, caught); /// 05: continued
}
}
main() {
BadNamedParametersTest.testMain();
}

View file

@ -0,0 +1,30 @@
// 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.
class Fisk {
get fisk => null;
static /// 01: static type warning
set fisk(x) {}
static /// 02: static type warning
get hest => null;
set hest(x) {}
foo() {}
var field;
method() {}
nullary() {}
}
class Hest extends Fisk {
static foo() {} /// 03: compile-time error
field() {} /// 04: compile-time error
var method; /// 05: compile-time error
nullary(x) {} /// 06: static type warning
}
main() {
new Fisk();
new Hest();
}

View file

@ -0,0 +1,9 @@
// 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.
main() {
// Raw String may not contain newline (may not be multi-line).
print(r'
');
}

View file

@ -0,0 +1,26 @@
// 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";
var a;
main() {
// Write a loop to force a bailout method on [A.foo].
for (int i = 0; i < 10; i++) {
if (a != null) new A().foo([]);
Expect.equals(42, new A().foo(new A()));
}
}
class A {
// In dart2js, the optimized version of foo tries to optimize the
// uses of a.length (which is used two times here: for the index,
// and for the bounds check), and that optmization used to crash
// the compiler.
foo(a) => a[a.length];
int get length => 42;
operator[] (index) => 42;
}

View file

@ -0,0 +1,41 @@
// 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";
// Test that the return type of a method is being registered for both
// its bailout and optimized version in dart2js.
var a;
bar() {
if (a[0] == 0) {
// Force bailout version.
bar();
// Avoid inlining.
throw 0;
}
for (int i = 0; i < 10; i++) {
a[0] = 42;
}
// This return should say that bar can return an array or unknown.
return a;
}
foo() {
if (a[0] == 0) {
// Avoid inlining.
throw 0;
}
var b = bar();
// This check used to fail because dart2js was assuming [b] was an
// array.
Expect.equals(1, b.length);
}
main() {
a = new Map();
bar();
foo();
}

View file

@ -0,0 +1,32 @@
// 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";
// Test that dart2s computes the right bailout environment in presence
// of nested loops.
class A {
operator[] (index) => 42;
}
var a = new A();
var b = new List(4);
int count = 0;
main() {
// Make the method recursive to make sure it gets an optimized
// version.
if (b[0] != null) main();
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
for (int k = 0; k < 2; k++) {
Expect.equals(42, a[i + j + k]);
count++;
}
}
}
Expect.equals(8, count);
}

View file

@ -0,0 +1,57 @@
// 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 "package:expect/expect.dart";
// Test to make sure the bailout environment in dart2js is correct.
var global;
class A {
var array;
initArray() {
return global[0] == null ? [null] : new Map();
}
bar() {
array = initArray();
do {
var element = array[0]; // bailout here
if (element is Map) continue;
if (element == null) break;
} while (true);
return global[0]; // bailout here
}
baz() {
do {
var element = bar();
if (element == null) return global[0]; // bailout here
if (element is Map) continue;
if (element is num) break;
} while (true);
return global[0]; // bailout here
}
}
void main() {
global = [1];
for (int i = 0; i < 2; i++) {
Expect.equals(1, new A().baz());
Expect.equals(1, new A().bar());
}
global = new Map();
for (int i = 0; i < 2; i++) {
Expect.equals(null, new A().baz());
Expect.equals(null, new A().bar());
}
global[0] = 42;
for (int i = 0; i < 2; i++) {
Expect.equals(42, new A().baz());
Expect.equals(42, new A().bar());
}
}

View file

@ -0,0 +1,40 @@
// 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 "package:expect/expect.dart";
// Test for dart2js to make sure the computed bailout environment is
// correct.
var global;
class A {
var array;
foo() {
do {
var element = global;
if (element is Map) continue;
if (element is num) break;
} while (true);
return array[0]; // bailout here.
}
}
void main() {
var a = new A();
a.array = [42];
global = 42;
for (int i = 0; i < 2; i++) {
Expect.equals(42, a.foo());
}
a.array = new Map();
a.array[0] = 42;
for (int i = 0; i < 2; i++) {
Expect.equals(42, a.foo());
}
global = null;
}

View file

@ -0,0 +1,48 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
// Test to make sure the do/while loop exit condition is generated.
var global;
class A {
var array;
initArray() {
if (global[0] == null) {
return [2];
} else {
var map = new Map();
map[0] = 2;
return map;
}
}
bar() {
array = initArray();
var element;
do {
element = array[0]; // bailout here
if (element is Map) continue;
if (element == null) break;
} while (element != 2);
return global[0]; // bailout here
}
}
void main() {
global = [2];
for (int i = 0; i < 2; i++) {
Expect.equals(2, new A().bar());
}
global = new Map();
global[0] = 2;
for (int i = 0; i < 2; i++) {
Expect.equals(2, new A().bar());
}
}

View file

@ -0,0 +1,27 @@
// 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.
// Regression test for dart2js that used to generate bad code for the
// non-bailout version of [main].
var a = [false, [1, 2, 3]];
var b;
main() {
// Defeat type inferencing for [b].
b = new Object();
b = 42;
b = [];
// Make the function recursive to force a bailout version.
if (a[0]) main();
// We used to ask [b] to be of the same type as [a], but not
// checking that the length and element type are the same.
var arrayPhi = a[0] ? a : b;
if (arrayPhi.length != 0) {
throw 'Test failed';
}
}

View file

@ -0,0 +1,48 @@
// 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";
// Test that a call to a bailout method in dart2js resolves to the
// right method.
var reachedAfoo = new C();
class A {
foo() {
// Using '++' makes sure there is a type guard.
reachedAfoo++;
}
}
class B extends A {
foo() {
reachedAfoo++;
// Call the Expect method after the type guard.
Expect.fail('Should never reach B.foo');
}
bar() {
super.foo();
}
}
class C {
int value = 0;
operator +(val) {
value += val;
return this;
}
}
main() {
// Using a loop makes sure the 'foo' methods will have an optimized
// version.
while (reachedAfoo.value != 0) {
new A().foo();
new B().foo();
}
new B().bar();
Expect.equals(1, reachedAfoo.value);
}

View file

@ -0,0 +1,16 @@
// 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";
class Bound {
run() {
return 42;
}
}
void main() {
var runner = new Bound().run;
Expect.equals(42, runner());
}

View file

@ -0,0 +1,195 @@
// Copyright (c) 2011, 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.
// Dart test for testing bitwise operations.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr
import "package:expect/expect.dart";
void main() {
for (int i = 0; i < 4; i++) {
test();
}
}
void test() {
Expect.equals(3, (3 & 7));
Expect.equals(7, (3 | 7));
Expect.equals(4, (3 ^ 7));
Expect.equals(25, (100 >> 2));
Expect.equals(400, (100 << 2));
Expect.equals(-25, (-100 >> 2));
Expect.equals(-101, ~100);
Expect.equals(0x10000000000000000, 1 << 64);
Expect.equals(-0x10000000000000000, -1 << 64);
Expect.equals(0x40000000, 0x04000000 << 4);
Expect.equals(0x4000000000000000, 0x0400000000000000 << 4);
Expect.equals(0, ~-1);
Expect.equals(-1, ~0);
Expect.equals(0, 1 >> 160);
Expect.equals(-1, -1 >> 160);
Expect.equals(0x100000000000000001,
0x100000000000000001 & 0x100000100F00000001);
Expect.equals(0x1, 0x1 & 0x100000100F00000001);
Expect.equals(0x1, 0x100000100F00000001 & 0x1);
Expect.equals(0x100000100F00000001,
0x100000000000000001 | 0x100000100F00000001);
Expect.equals(0x100000100F00000011, 0x11 | 0x100000100F00000001);
Expect.equals(0x100000100F00000011, 0x100000100F00000001 | 0x11);
Expect.equals(0x0F000F00000000000000,
0x0F00F00000000000001 ^ 0xFF00000000000000001);
Expect.equals(0x31, 0xF00F00000000000001 ^ 0xF00F00000000000030);
Expect.equals(0xF00F00000000000031, 0xF00F00000000000001 ^ 0x30);
Expect.equals(0xF00F00000000000031, 0x30 ^ 0xF00F00000000000001);
Expect.equals(0xF0000000000000000F, 0xF0000000000000000F7 >> 4);
Expect.equals(15, 0xF00000000 >> 32);
Expect.equals(1030792151040, 16492674416655 >> 4);
Expect.equals(0xF0000000000000000F0, 0xF0000000000000000F << 4);
Expect.equals(0xF00000000, 15 << 32);
testNegativeValueShifts();
testPositiveValueShifts();
testNoMaskingOfShiftCount();
testNegativeCountShifts();
for (int i = 0; i < 20; i++) {
testCornerCasesRightShifts();
testRightShift64Bit();
testLeftShift64Bit();
testLeftShift64BitWithOverflow1();
testLeftShift64BitWithOverflow2();
testLeftShift64BitWithOverflow3();
}
// Test precedence.
testPrecedence(4,5,3,1);
testPrecedence(3,4,5,9);
testPrecedence(0x5c71, 0x6b92, 0x7654, 0x7d28);
}
void testCornerCasesRightShifts() {
var v32 = 0xFF000000;
var v64 = 0xFF00000000000000;
Expect.equals(0x3, v32 >> 0x1E);
Expect.equals(0x1, v32 >> 0x1F);
Expect.equals(0x0, v32 >> 0x20);
Expect.equals(0x3, v64 >> 0x3E);
Expect.equals(0x1, v64 >> 0x3F);
Expect.equals(0x0, v64 >> 0x40);
}
void testRightShift64Bit() {
var t = 0x1ffffffff;
Expect.equals(0xffffffff, t >> 1);
}
void testLeftShift64Bit() {
var t = 0xffffffff;
Expect.equals(0xffffffff, t << 0);
Expect.equals(0x1fffffffe, t << 1);
Expect.equals(0x7fffffff80000000, t << 31);
Expect.equals(0x10000000000000000, 2*(t+1) << 31); /// 01: static type warning
Expect.equals(0x20000000000000000, 4*(t+1) << 31); /// 02: static type warning
Expect.equals(0x8000000000000000, (t+1) << 31);
}
void testLeftShift64BitWithOverflow1() {
var t = 0xffffffff;
Expect.equals(0x10000000000000000, 2*(t+1) << 31); /// 03: static type warning
}
void testLeftShift64BitWithOverflow2() {
var t = 0xffffffff;
Expect.equals(0x20000000000000000, 4*(t+1) << 31); /// 04: static type warning
}
void testLeftShift64BitWithOverflow3() {
var t = 0xffffffff;
Expect.equals(0x8000000000000000, (t+1) << 31);
}
void testNegativeCountShifts() {
bool throwOnLeft(a, b) {
try {
var x = a << b;
return false;
} catch (e) {
return true;
}
}
bool throwOnRight(a, b) {
try {
var x = a >> b;
return false;
} catch (e) {
return true;
}
}
Expect.isTrue(throwOnLeft(12, -3));
Expect.isTrue(throwOnRight(12, -3));
for (int i = 0; i < 20; i++) {
Expect.isFalse(throwOnLeft(12, 3));
Expect.isFalse(throwOnRight(12, 3));
}
}
void testNegativeValueShifts() {
for (int value = 0; value > -100; value--) {
for (int i = 0; i < 300; i++) {
int b = (value << i) >> i;
Expect.equals(value, b);
}
}
}
void testPositiveValueShifts() {
for (int value = 0; value < 100; value++) {
for (int i = 0; i < 300; i++) {
int b = (value << i) >> i;
Expect.equals(value, b);
}
}
}
void testNoMaskingOfShiftCount() {
// Shifts which would behave differently if shift count was masked into a
// range.
Expect.equals(0, 0 >> 256);
Expect.equals(0, 1 >> 256);
Expect.equals(0, 2 >> 256);
Expect.equals(0, shiftRight(0, 256));
Expect.equals(0, shiftRight(1, 256));
Expect.equals(0, shiftRight(2, 256));
for (int shift = 1; shift <= 256; shift++) {
Expect.equals(0, shiftRight(1, shift));
Expect.equals(-1, shiftRight(-1, shift));
Expect.equals(true, shiftLeft(1, shift) > shiftLeft(1, shift - 1));
}
}
int shiftLeft(int a, int b) { return a << b; }
int shiftRight(int a, int b) { return a >> b; }
void testPrecedence(int a, int b, int c, int d) {
// & binds stronger than ^, which binds stronger than |.
int result = a & b ^ c | d & b ^ c;
Expect.equals(((a & b) ^ c) | ((d & b) ^ c), result); // &^|
Expect.notEquals((a & (b ^ c)) | (d & (b ^ c)), result); // ^&|
Expect.notEquals((a & b) ^ (c | (d & b)) ^ c, result); // &|^
Expect.notEquals((a & b) ^ ((c | d) & b) ^ c, result); // |&^
Expect.notEquals(a & (b ^ (c | d)) & (b ^ c), result); // |^&
Expect.notEquals(a & ((b ^ c) | d) & (b ^ c), result); // ^|&
// Binds stronger than relational operators.
Expect.equals((a & b) < (c & d), a & b < c & d);
// Binds weaker than shift operators.
Expect.equals((a & (b << c)) ^ d, a & b << c ^ d);
Expect.notEquals((a & b) << (c ^ d), a & b << c ^ d);
}

View file

@ -0,0 +1,48 @@
// 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";
constants() {
Expect.equals(0, 499 >> 33);
Expect.equals(0, (499 << 33) & 0xFFFFFFFF);
}
foo(i) {
if (i != 0) {
y--;
foo(i - 1);
y++;
}
}
var y;
// id returns [x] in a way that should be difficult to predict statically.
id(x) {
y = x;
foo(10);
return y;
}
interceptors() {
Expect.equals(0, id(499) >> 33);
Expect.equals(0, (id(499) << 33) & 0xFFFFFFFF);
}
speculative() {
var a = id(499);
for (int i = 0; i < 1; i++) {
Expect.equals(0, a >> 33);
Expect.equals(0, (a << 33) & 0xFFFFFFFF);
}
}
// JavaScript shifts by the amount modulo 32. That is x << y is equivalent to
// x << (y & 0x1F). Dart does not.
main() {
constants();
interceptors();
speculative();
}

View file

@ -0,0 +1,80 @@
// 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.
// Dart test checking that static/instance field shadowing do not conflict.
// Test that certain interfaces/classes are blacklisted from being
// implemented or extended.
// bool.
class MyBool implements bool {} /// 01: compile-time error
abstract class MyBoolInterface implements bool default F { /// 02: compile-time error
MyBoolInterface(); /// 02: continued
} /// 02: continued
// num.
class MyNum implements num {} /// 03: compile-time error
abstract class MyNumInterface implements num default F { /// 04: compile-time error
MyNumInterface(); /// 04: continued
} /// 04: continued
// int.
class MyInt implements int {} /// 05: compile-time error
abstract class MyIntInterface implements int default F { /// 06: compile-time error
MyIntInterface(); /// 06: continued
} /// 06: continued
// double.
class MyDouble implements double {} /// 07: compile-time error
abstract class MyDoubleInterface implements double default F { /// 08: compile-time error
MyDoubleInterface(); /// 08: continued
} /// 08: continued
// String.
class MyString implements String {} /// 09: compile-time error
abstract class MyStringInterface implements String default F { /// 10: compile-time error
MyStringInterface(); /// 10: continued
} /// 10: continued
// Function.
class MyFunction implements Function {}
class MyOtherFunction extends Function {}
abstract class MyFunctionInterface implements Function default F { /// 12: compile-time error
MyFunctionInterface(); /// 12: continued
} /// 12: continued
// dynamic.
class MyDynamic implements dynamic {} /// 13: compile-time error
abstract class MyDynamicInterface implements dynamic default F { /// 14: compile-time error
MyDynamicInterface(); /// 14: continued
} /// 14: continued
class F {
factory MyBoolInterface() { return null; } /// 02: continued
factory MyNumInterface() { return null; } /// 04: continued
factory MyIntInterface() { return null; } /// 06: continued
factory MyDoubleInterface() { return null; } /// 08: continued
factory MyStringInterface() { return null; } /// 10: continued
factory MyFunctionInterface() { return null; } /// 12: continued
factory MyDynamicInterface() { return null; } /// 14: continued
}
main() {
new MyBool(); /// 01: continued
new MyBoolInterface(); /// 02: continued
new MyNum(); /// 03: continued
new MyNumInterface(); /// 04: continued
new MyInt(); /// 05: continued
new MyIntInterface(); /// 06: continued
new MyDouble(); /// 07: continued
new MyDoubleInterface(); /// 08: continued
new MyString(); /// 09: continued
new MyStringInterface(); /// 10: continued
new MyFunction();
new MyOtherFunction();
new MyFunctionInterface(); /// 12: continued
new MyDynamic(); /// 13: continued
new MyDynamicInterface(); /// 14: continued
}

View file

@ -0,0 +1,16 @@
// 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.
main() {
C o = const C(1);
}
class Base {
final String name;
const Base(this.name);
}
class C extends Base {
const C(var x): super(); // call super constructor with wrong argument count.
}

View file

@ -0,0 +1,54 @@
// 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 "package:expect/expect.dart";
bool typeChecksEnabled() {
try {
var i = 42;
String s = i;
} on TypeError catch (e) {
return true;
}
return false;
}
bool assertionsEnabled() {
try {
assert(false);
return false;
} on AssertionError catch (e) {
return true;
}
return false;
}
final bool typeChecksOn = typeChecksEnabled();
final bool assertionsOn = assertionsEnabled();
ifExpr(e) { if (e) return true; else return false; }
bool ifNull() => ifExpr(null);
bool ifString() => ifExpr("true");
main() {
print("type checks: $typeChecksOn");
print("assertions: $assertionsOn");
if (typeChecksOn) {
Expect.throws(ifNull, (e) => e is AssertionError);
}
if (assertionsOn && !typeChecksOn) {
Expect.throws(ifNull, (e) => e is AssertionError);
}
if (!typeChecksOn && !assertionsOn) {
Expect.identical(false, ifNull());
}
if (!typeChecksOn) {
Expect.identical(false, ifString());
}
if (typeChecksOn) {
Expect.throws(ifString, (e) => e is TypeError);
}
}

View file

@ -0,0 +1,24 @@
// 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.
// Check that passing `null` for a boolean typed parameter will still cause
// a boolean conversion error when used in a condition in checked mode.
import 'package:expect/expect.dart';
@NoInline()
String check({bool a, bool b}) {
String a_string = a ? 'a' : '';
String b_string = b ? 'b' : '';
return '$a_string$b_string';
}
class Class {
final String field;
Class({bool a: false, bool b: true}) : this.field = check(a: a, b: b);
}
main() {
Expect.equals('', new Class(a: null, b: null).field); /// 01: dynamic type error
}

View file

@ -0,0 +1,218 @@
// Copyright (c) 2011, 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";
class BoolTest {
static void testEquality() {
Expect.equals(true, true);
Expect.equals(false, false);
Expect.isTrue(identical(true, true));
Expect.isFalse(identical(true, false));
Expect.isTrue(identical(false, false));
Expect.isFalse(identical(false, true));
Expect.isFalse(!identical(true, true));
Expect.isTrue(!identical(true, false));
Expect.isFalse(!identical(false, false));
Expect.isTrue(!identical(false, true));
Expect.isTrue(true == true);
Expect.isFalse(true == false);
Expect.isTrue(false == false);
Expect.isFalse(false == true);
Expect.isFalse(true != true);
Expect.isTrue(true != false);
Expect.isFalse(false != false);
Expect.isTrue(false != true);
Expect.isTrue(identical(true, (true == true)));
Expect.isTrue(identical(false, (true == false)));
Expect.isTrue(identical(true, (false == false)));
Expect.isTrue(identical(false, (false == true)));
Expect.isFalse(!identical(true, (true == true)));
Expect.isFalse(!identical(false, (true == false)));
Expect.isFalse(!identical(true, (false == false)));
Expect.isFalse(!identical(false, (false == true)));
Expect.isFalse(identical(false, (true == true)));
Expect.isFalse(identical(true, (true == false)));
Expect.isFalse(identical(false, (false == false)));
Expect.isFalse(identical(true, (false == true)));
Expect.isTrue(!identical(false, (true == true)));
Expect.isTrue(!identical(true, (true == false)));
Expect.isTrue(!identical(false, (false == false)));
Expect.isTrue(!identical(true, (false == true)));
// Expect.equals could rely on a broken boolean equality.
if (true == false) {
throw "Expect.equals broken";
}
if (false == true) {
throw "Expect.equals broken";
}
if (identical(true, false)) {
throw "Expect.equals broken";
}
if (identical(false, true)) {
throw "Expect.equals broken";
}
if (true == true) {
} else {
throw "Expect.equals broken";
}
if (false == false) {
} else {
throw "Expect.equals broken";
}
if (identical(true, true)) {
} else {
throw "Expect.equals broken";
}
if (identical(false, false)) {
} else {
throw "Expect.equals broken";
}
if (true != false) {
} else {
throw "Expect.equals broken";
}
if (false != true) {
} else {
throw "Expect.equals broken";
}
if (!identical(true, false)) {
} else {
throw "Expect.equals broken";
}
if (!identical(false, true)) {
} else {
throw "Expect.equals broken";
}
if (true != true) {
throw "Expect.equals broken";
}
if (false != false) {
throw "Expect.equals broken";
}
if (!identical(true, true)) {
throw "Expect.equals broken";
}
if (!identical(false, false)) {
throw "Expect.equals broken";
}
}
static void testToString() {
Expect.equals("true", true.toString());
Expect.equals("false", false.toString());
}
static void testNegate(isTrue, isFalse) {
Expect.equals(true, !false);
Expect.equals(false, !true);
Expect.equals(true, !isFalse);
Expect.equals(false, !isTrue);
}
static void testLogicalOp() {
testOr(a, b, onTypeError) {
try {
return a || b;
} on TypeError catch (t) {
return onTypeError;
}
}
testAnd(a, b, onTypeError) {
try {
return a && b;
} on TypeError catch (t) {
return onTypeError;
}
}
var isTrue = true;
var isFalse = false;
Expect.equals(true, testAnd(isTrue, isTrue, false));
Expect.equals(false, testAnd(isTrue, 0, false));
Expect.equals(false, testAnd(isTrue, 1, false));
Expect.equals(false, testAnd(isTrue, "true", false));
Expect.equals(false, testAnd(0, isTrue, false));
Expect.equals(false, testAnd(1, isTrue, false));
Expect.equals(true, testOr(isTrue, isTrue, false));
Expect.equals(true, testOr(isFalse, isTrue, false));
Expect.equals(true, testOr(isTrue, isFalse, false));
Expect.equals(true, testOr(isTrue, 0, true));
Expect.equals(true, testOr(isTrue, 1, true));
Expect.equals(false, testOr(isFalse, 0, false));
Expect.equals(false, testOr(isFalse, 1, false));
Expect.equals(true, testOr(0, isTrue, true));
Expect.equals(true, testOr(1, isTrue, true));
Expect.equals(false, testOr(0, isFalse, false));
Expect.equals(false, testOr(1, isFalse, false));
// Test side effects.
int trueCount = 0, falseCount = 0;
trueFunc() {
trueCount++;
return true;
}
falseFunc() {
falseCount++;
return false;
}
Expect.equals(0, trueCount);
Expect.equals(0, falseCount);
trueFunc() && trueFunc();
Expect.equals(2, trueCount);
Expect.equals(0, falseCount);
trueCount = falseCount = 0;
falseFunc() && trueFunc();
Expect.equals(0, trueCount);
Expect.equals(1, falseCount);
trueCount = falseCount = 0;
trueFunc() && falseFunc();
Expect.equals(1, trueCount);
Expect.equals(1, falseCount);
trueCount = falseCount = 0;
falseFunc() && falseFunc();
Expect.equals(0, trueCount);
Expect.equals(1, falseCount);
trueCount = falseCount = 0;
trueFunc() || trueFunc();
Expect.equals(1, trueCount);
Expect.equals(0, falseCount);
trueCount = falseCount = 0;
falseFunc() || trueFunc();
Expect.equals(1, trueCount);
Expect.equals(1, falseCount);
trueCount = falseCount = 0;
trueFunc() || falseFunc();
Expect.equals(1, trueCount);
Expect.equals(0, falseCount);
trueCount = falseCount = 0;
falseFunc() || falseFunc();
Expect.equals(0, trueCount);
Expect.equals(2, falseCount);
}
static void testMain() {
testEquality();
testNegate(true, false);
testToString();
testLogicalOp();
}
}
main() {
BoolTest.testMain();
}

View file

@ -0,0 +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.
class BootstrapTest {
static testMain() {
var obj = new Object();
return obj;
}
}
main() {
BootstrapTest.testMain();
}

View file

@ -0,0 +1,76 @@
// 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 "package:expect/expect.dart";
class A {
const A();
foo() => 42;
}
class B {
foo() => 42;
}
main() {
// Use an array to defeat type inferencing.
var array = [new A(), new A(), new B(), new B()];
var set = new Set.from(array.map((a) => a.foo));
Expect.equals(array.length, set.length);
set.addAll(array.map((a) => a.foo));
Expect.equals(array.length, set.length);
for (int i = 0; i < array.length; i += 2) {
Expect.isTrue(set.contains(array[i].foo));
Expect.equals(array[i], array[i]);
Expect.equals(array[i].foo, array[i].foo);
Expect.equals(array[i].foo.hashCode, array[i].foo.hashCode);
for (int j = 0; j < array.length; j++) {
if (i == j) continue;
Expect.notEquals(array[i].foo, array[j].foo);
}
}
// Try with dart2js intercepted types.
array = ['foo', 'bar', [], [], const []];
set = new Set.from(array.map((a) => a.indexOf));
Expect.equals(array.length, set.length);
set.addAll(array.map((a) => a.indexOf));
Expect.equals(array.length, set.length);
for (int i = 0; i < array.length; i += 2) {
Expect.isTrue(set.contains(array[i].indexOf));
Expect.equals(array[i], array[i]);
Expect.equals(array[i].indexOf, array[i].indexOf);
Expect.equals(array[i].indexOf.hashCode, array[i].indexOf.hashCode);
for (int j = 0; j < array.length; j++) {
if (i == j) continue;
Expect.notEquals(array[i].indexOf, array[j].indexOf);
}
}
array = [const A(), const A()];
set = new Set.from(array.map((a) => a.foo));
Expect.equals(1, set.length);
set.addAll(array.map((a) => a.foo));
Expect.equals(1, set.length);
Expect.isTrue(set.contains(array[0].foo));
Expect.equals(array[0].foo, array[0].foo);
Expect.equals(array[0].foo.hashCode, array[0].foo.hashCode);
Expect.equals(array[0].foo, array[1].foo);
Expect.equals(array[0].foo.hashCode, array[1].foo.hashCode);
array = [const [], const []];
set = new Set.from(array.map((a) => a.indexOf));
Expect.equals(1, set.length);
set.addAll(array.map((a) => a.indexOf));
Expect.equals(1, set.length);
Expect.isTrue(set.contains(array[0].indexOf));
Expect.equals(array[0].indexOf, array[0].indexOf);
Expect.equals(array[0].indexOf.hashCode, array[0].indexOf.hashCode);
Expect.equals(array[0].indexOf, array[1].indexOf);
Expect.equals(array[0].indexOf.hashCode, array[1].indexOf.hashCode);
}

View file

@ -0,0 +1,27 @@
// 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 to make sure dart2js does not try to use the same
// BoundClosureClass between an intercepted method and a
// non-intercepted method.
import "package:expect/expect.dart";
class A {
// Make dart2js try to share a bound closure for [foo] with a bound
// closure for [List.add], by having same number of arguments.
foo(a) => a;
}
main() {
var array = [[], new A()];
var method = array[0].add;
method(42);
method = array[1].foo;
Expect.equals(42, method(42));
Expect.equals(1, array[0].length);
Expect.isTrue(array[0].contains(42));
}

View file

@ -0,0 +1,66 @@
// 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 branch fusion correctly sets branch environment for comparisons
// that require unboxing and does not fuse branches that can deoptimize.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr
import "package:expect/expect.dart";
var sideEffect = true;
barDouble(a, b) {
sideEffect = false;
final result = (a == b);
sideEffect = !sideEffect;
return result;
}
fooDouble(a, b) => barDouble(a, b) ? 1 : 0;
barMint(a, b) {
sideEffect = false;
final result = (a == b);
sideEffect = !sideEffect;
return result;
}
fooMint(a, b) => barMint(a, b) ? 1 : 0;
class A {
operator == (other) => identical(this, other);
}
class B extends A {
}
class C extends A {
}
barPoly(a, b) {
sideEffect = false;
final result = a == b;
sideEffect = !sideEffect;
return result;
}
fooPoly(a, b) => barPoly(a, b) ? 1 : 0;
main () {
final a = 1.0;
final b = 1 << 62;
final x = new A(), y = new B(), z = new C();
for (var i = 0; i < 20; i++) {
Expect.equals(1, fooDouble(a, a));
Expect.isTrue(sideEffect);
Expect.equals(0, fooMint(b, 0));
Expect.isTrue(sideEffect);
Expect.equals(1, fooPoly(x, x));
Expect.equals(0, fooPoly(y, x));
}
Expect.equals(1, fooDouble(z, z));
Expect.isTrue(sideEffect);
Expect.equals(1, fooMint(z, z));
Expect.isTrue(sideEffect);
Expect.equals(1, fooPoly(z, z));
Expect.isTrue(sideEffect);
}

View file

@ -0,0 +1,158 @@
// Copyright (c) 2011, 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.
// Dart test for branches. Make sure that shortcuts work, even if they have
// to jump over several expressions.
import "package:expect/expect.dart";
class BranchesTest {
static bool f() {
Expect.equals("Never reached", 0);
return true;
}
static void testMain() {
int checkPointCounter = 1;
int checkPoint1 = 0;
int checkPoint2 = 0;
int checkPoint3 = 0;
int checkPoint4 = 0;
int checkPoint5 = 0;
int checkPoint6 = 0;
int i = 0;
for (int i = 0; i < 2; i++) {
if (i == 0) {
checkPoint1 += checkPointCounter++;
if (true || // Test branch-if-true.
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f() ||
f()) {
checkPoint2 += checkPointCounter++;
}
} else { // Test branch (jumping over the else branch).
checkPoint3 += checkPointCounter++;
if (false) {
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
checkPoint4 = checkPointCounter++; // Never reached.
}
}
checkPoint5 += checkPointCounter++;
}
checkPoint6 += checkPointCounter++;
Expect.equals(1, checkPoint1);
Expect.equals(2, checkPoint2);
Expect.equals(4, checkPoint3);
Expect.equals(0, checkPoint4);
Expect.equals(8, checkPoint5);
Expect.equals(6, checkPoint6);
}
}
main() {
BranchesTest.testMain();
}

View file

@ -0,0 +1,53 @@
// Copyright (c) 2011, 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.
// Dart test for breaks in for, do/while and while loops.
import "package:expect/expect.dart";
class BreakTest {
static testMain() {
int i;
int forCounter = 0;
for (i = 0; i < 10; i++) {
forCounter++;
if (i > 3) break;
}
Expect.equals(5, forCounter);
Expect.equals(4, i);
i = 0;
int doWhileCounter = 0;
do {
i++;
doWhileCounter++;
if (i > 3) break;
} while (i < 10);
Expect.equals(4, doWhileCounter);
Expect.equals(4, i);
i = 0;
int whileCounter = 0;
while (i < 10) {
i++;
whileCounter++;
if (i > 3) break;
}
Expect.equals(4, whileCounter);
Expect.equals(4, i);
// Use a label to break to the outer loop.
i = 0;
L: while (i < 10) {
i++;
while (i > 5) {
break L;
}
}
Expect.equals(6, i);
}
}
main() {
BreakTest.testMain();
}

View file

@ -0,0 +1,24 @@
// 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.
// Check that we cannot use a pseudo keyword at the class level code.
// Pseudo keywords are not allowed to be used as class names.
class abstract { } /// 01: compile-time error
class as { } /// 19: compile-time error
class dynamic { } /// 04: compile-time error
class export { } /// 17: compile-time error
class external { } /// 20: compile-time error
class factory { } /// 05: compile-time error
class get { } /// 06: compile-time error
class implements { } /// 07: compile-time error
class import { } /// 08: compile-time error
class library { } /// 10: compile-time error
class operator { } /// 12: compile-time error
class part { } /// 18: compile-time error
class set { } /// 13: compile-time error
class static { } /// 15: compile-time error
class typedef { } /// 16: compile-time error
main() { }

View file

@ -0,0 +1,14 @@
// 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.
library abstract;
class A {
}
class B<T> {
}
class C<T, S> {
}

View file

@ -0,0 +1,14 @@
// 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.
library as;
class A {
}
class B<T> {
}
class C<T, S> {
}

View file

@ -0,0 +1,14 @@
// 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.
library dynamic;
class A {
}
class B<T> {
}
class C<T, S> {
}

View file

@ -0,0 +1,14 @@
// 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.
library export;
class A {
}
class B<T> {
}
class C<T, S> {
}

View file

@ -0,0 +1,14 @@
// 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.
library external;
class A {
}
class B<T> {
}
class C<T, S> {
}

View file

@ -0,0 +1,14 @@
// 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.
library factory;
class A {
}
class B<T> {
}
class C<T, S> {
}

View file

@ -0,0 +1,14 @@
// 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.
library get;
class A {
}
class B<T> {
}
class C<T, S> {
}

View file

@ -0,0 +1,14 @@
// 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.
library implements;
class A {
}
class B<T> {
}
class C<T, S> {
}

View file

@ -0,0 +1,14 @@
// 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.
library import;
class A {
}
class B<T> {
}
class C<T, S> {
}

Some files were not shown because too many files have changed in this diff Show more