blob: 2f7e4153e7c8f348a85ae97ca5344830a1fc3a1c [file] [log] [blame]
// Copyright (c) 2019, 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:analyzer/src/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../dart/resolution/driver_resolution.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(NotMapSpreadTest);
});
}
@reflectiveTest
class NotMapSpreadTest extends DriverResolutionTest {
test_map() async {
await assertNoErrorsInCode('''
var a = {0: 0};
var v = <int, int>{...a};
''');
}
test_map_null() async {
await assertNoErrorsInCode('''
var v = <int, int>{...?null};
''');
}
test_notMap_direct() async {
await assertErrorsInCode('''
var a = 0;
var v = <int, int>{...a};
''', [
error(CompileTimeErrorCode.NOT_MAP_SPREAD, 33, 1),
]);
}
test_notMap_forElement() async {
await assertErrorsInCode('''
var a = 0;
var v = <int, int>{for (var i in []) ...a};
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 39, 1),
error(CompileTimeErrorCode.NOT_MAP_SPREAD, 51, 1),
]);
}
test_notMap_ifElement_else() async {
await assertErrorsInCode('''
var a = 0;
var v = <int, int>{if (1 > 0) ...<int, int>{} else ...a};
''', [
error(CompileTimeErrorCode.NOT_MAP_SPREAD, 65, 1),
]);
}
test_notMap_ifElement_then() async {
await assertErrorsInCode('''
var a = 0;
var v = <int, int>{if (1 > 0) ...a};
''', [
error(CompileTimeErrorCode.NOT_MAP_SPREAD, 44, 1),
]);
}
}