| // 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:analysis_server/src/services/correction/assist.dart'; |
| import 'package:analyzer_plugin/utilities/assist/assist.dart'; |
| import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| |
| import 'assist_processor.dart'; |
| |
| main() { |
| defineReflectiveSuite(() { |
| defineReflectiveTests(ConvertToSetLiteralTest); |
| }); |
| } |
| |
| @reflectiveTest |
| class ConvertToSetLiteralTest extends AssistProcessorTest { |
| @override |
| AssistKind get kind => DartAssistKind.CONVERT_TO_SET_LITERAL; |
| |
| test_default_declaredType() async { |
| await resolveTestUnit(''' |
| Set s = S/*caret*/et(); |
| '''); |
| await assertHasAssist(''' |
| Set s = {}; |
| '''); |
| } |
| |
| test_default_minimal() async { |
| await resolveTestUnit(''' |
| var s = S/*caret*/et(); |
| '''); |
| await assertHasAssist(''' |
| var s = <dynamic>{}; |
| '''); |
| } |
| |
| test_default_newKeyword() async { |
| await resolveTestUnit(''' |
| var s = new S/*caret*/et(); |
| '''); |
| await assertHasAssist(''' |
| var s = <dynamic>{}; |
| '''); |
| } |
| |
| test_default_typeArg() async { |
| await resolveTestUnit(''' |
| var s = S/*caret*/et<int>(); |
| '''); |
| await assertHasAssist(''' |
| var s = <int>{}; |
| '''); |
| } |
| |
| test_from_empty() async { |
| await resolveTestUnit(''' |
| var s = S/*caret*/et.from([]); |
| '''); |
| await assertHasAssist(''' |
| var s = <dynamic>{}; |
| '''); |
| } |
| |
| test_from_newKeyword() async { |
| await resolveTestUnit(''' |
| var s = new S/*caret*/et.from([2, 3]); |
| '''); |
| await assertHasAssist(''' |
| var s = {2, 3}; |
| '''); |
| } |
| |
| test_from_noKeyword_declaredType() async { |
| await resolveTestUnit(''' |
| Set s = S/*caret*/et.from([2, 3]); |
| '''); |
| await assertHasAssist(''' |
| Set s = {2, 3}; |
| '''); |
| } |
| |
| test_from_noKeyword_typeArg_onConstructor() async { |
| await resolveTestUnit(''' |
| var s = S/*caret*/et<int>.from([2, 3]); |
| '''); |
| await assertHasAssist(''' |
| var s = <int>{2, 3}; |
| '''); |
| } |
| |
| test_from_noKeyword_typeArg_onConstructorAndLiteral() async { |
| await resolveTestUnit(''' |
| var s = S/*caret*/et<int>.from(<num>[2, 3]); |
| '''); |
| await assertHasAssist(''' |
| var s = <int>{2, 3}; |
| '''); |
| } |
| |
| test_from_noKeyword_typeArg_onLiteral() async { |
| await resolveTestUnit(''' |
| var s = S/*caret*/et.from(<int>[2, 3]); |
| '''); |
| await assertHasAssist(''' |
| var s = <int>{2, 3}; |
| '''); |
| } |
| |
| test_from_nonEmpty() async { |
| await resolveTestUnit(''' |
| var s = S/*caret*/et.from([2, 3]); |
| '''); |
| await assertHasAssist(''' |
| var s = {2, 3}; |
| '''); |
| } |
| |
| test_from_notALiteral() async { |
| await resolveTestUnit(''' |
| var l = [1]; |
| Set s = new S/*caret*/et.from(l); |
| '''); |
| await assertNoAssist(); |
| } |
| |
| test_from_trailingComma() async { |
| await resolveTestUnit(''' |
| var s = S/*caret*/et.from([2, 3,]); |
| '''); |
| await assertHasAssist(''' |
| var s = {2, 3,}; |
| '''); |
| } |
| |
| test_toSet_empty() async { |
| await resolveTestUnit(''' |
| var s = [].to/*caret*/Set(); |
| '''); |
| await assertHasAssist(''' |
| var s = <dynamic>{}; |
| '''); |
| } |
| |
| test_toSet_empty_typeArg() async { |
| await resolveTestUnit(''' |
| var s = <int>[].to/*caret*/Set(); |
| '''); |
| await assertHasAssist(''' |
| var s = <int>{}; |
| '''); |
| } |
| |
| test_toSet_nonEmpty() async { |
| await resolveTestUnit(''' |
| var s = [2, 3].to/*caret*/Set(); |
| '''); |
| await assertHasAssist(''' |
| var s = {2, 3}; |
| '''); |
| } |
| |
| test_toSet_nonEmpty_typeArg() async { |
| await resolveTestUnit(''' |
| var s = <int>[2, 3].to/*caret*/Set(); |
| '''); |
| await assertHasAssist(''' |
| var s = <int>{2, 3}; |
| '''); |
| } |
| |
| test_toSet_notALiteral() async { |
| await resolveTestUnit(''' |
| var l = []; |
| var s = l.to/*caret*/Set(); |
| '''); |
| await assertNoAssist(); |
| } |
| } |