| // 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:analyzer/src/generated/engine.dart'; |
| import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| |
| import '../dart/resolution/driver_resolution.dart'; |
| |
| main() { |
| defineReflectiveSuite(() { |
| defineReflectiveTests(ConstSpreadExpectedMapTest); |
| }); |
| } |
| |
| @reflectiveTest |
| class ConstSpreadExpectedMapTest extends DriverResolutionTest { |
| @override |
| AnalysisOptionsImpl get analysisOptions => AnalysisOptionsImpl() |
| ..enabledExperiments = ['control-flow-collections', 'spread-collections']; |
| |
| test_const_mapInt() async { |
| await assertErrorsInCode(''' |
| const dynamic a = 5; |
| var b = const <int, int>{...a}; |
| ''', [CompileTimeErrorCode.CONST_SPREAD_EXPECTED_MAP]); |
| } |
| |
| test_const_mapList() async { |
| await assertErrorsInCode(''' |
| const dynamic a = <int>[5]; |
| var b = const <int, int>{...a}; |
| ''', [CompileTimeErrorCode.CONST_SPREAD_EXPECTED_MAP]); |
| } |
| |
| test_const_mapMap() async { |
| await assertNoErrorsInCode(''' |
| const dynamic a = <int, int>{1: 2}; |
| var b = <int, int>{...a}; |
| '''); |
| } |
| |
| test_const_mapNull() async { |
| await assertErrorsInCode(''' |
| const dynamic a = null; |
| var b = const <int, int>{...a}; |
| ''', [CompileTimeErrorCode.CONST_SPREAD_EXPECTED_MAP]); |
| } |
| |
| test_const_mapNull_nullable() async { |
| await assertNoErrorsInCode(''' |
| const dynamic a = null; |
| var b = <int, int>{...?a}; |
| '''); |
| } |
| |
| test_const_mapSet() async { |
| await assertErrorsInCode(''' |
| const dynamic a = <int>{5}; |
| var b = const <int, int>{...a}; |
| ''', [CompileTimeErrorCode.CONST_SPREAD_EXPECTED_MAP]); |
| } |
| |
| test_nonConst_mapInt() async { |
| await assertNoErrorsInCode(''' |
| const dynamic a = 5; |
| var b = <int, int>{...a}; |
| '''); |
| } |
| |
| test_nonConst_mapMap() async { |
| await assertNoErrorsInCode(''' |
| const dynamic a = {1: 2}; |
| var b = <int, int>{...a}; |
| '''); |
| } |
| } |