2 * Copyright 2000-2015 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.jetbrains.python.intentions;
18 import com.jetbrains.python.PyBundle;
19 import com.jetbrains.python.psi.LanguageLevel;
22 * @author Mikhail Golubev
24 public class PyConvertCollectionLiteralIntentionTest extends PyIntentionTestCase {
26 private static final String CONVERT_TUPLE_TO_LIST = PyBundle.message("INTN.convert.collection.literal.text", "tuple", "list");
27 private static final String CONVERT_TUPLE_TO_SET = PyBundle.message("INTN.convert.collection.literal.text", "tuple", "set");
28 private static final String CONVERT_LIST_TO_TUPLE = PyBundle.message("INTN.convert.collection.literal.text", "list", "tuple");
29 private static final String CONVERT_LIST_TO_SET = PyBundle.message("INTN.convert.collection.literal.text", "list", "set");
30 private static final String CONVERT_SET_TO_TUPLE = PyBundle.message("INTN.convert.collection.literal.text", "set", "tuple");
31 private static final String CONVERT_SET_TO_LIST = PyBundle.message("INTN.convert.collection.literal.text", "set", "list");
34 public void testConvertParenthesizedTupleToList() {
35 doIntentionTest(CONVERT_TUPLE_TO_LIST);
39 public void testConvertTupleWithoutParenthesesToList() {
40 doIntentionTest(CONVERT_TUPLE_TO_LIST);
44 public void testConvertTupleWithoutClosingParenthesisToList() {
45 doIntentionTest(CONVERT_TUPLE_TO_LIST);
49 public void testConvertParenthesizedTupleToSet() {
50 doIntentionTest(CONVERT_TUPLE_TO_SET);
54 public void testConvertTupleToSetNotAvailableWithoutSetLiterals() {
55 runWithLanguageLevel(LanguageLevel.PYTHON25, new Runnable() {
57 doNegativeTest(CONVERT_TUPLE_TO_SET);
63 public void testConvertTupleToSetNotAvailableInAssignmentTarget() {
64 doNegativeTest(CONVERT_TUPLE_TO_SET);
68 public void testConvertTupleToSetNotAvailableInForLoop() {
69 doNegativeTest(CONVERT_TUPLE_TO_SET);
73 public void testConvertTupleToSetNotAvailableInComprehension() {
74 doNegativeTest(CONVERT_TUPLE_TO_SET);
78 public void testConvertListToTuple() {
79 doIntentionTest(CONVERT_LIST_TO_TUPLE);
83 public void testConvertListWithoutClosingBracketToTuple() {
84 doIntentionTest(CONVERT_LIST_TO_TUPLE);
88 public void testConvertListToSet() {
89 doIntentionTest(CONVERT_LIST_TO_SET);
93 public void testConvertSetToTuple() {
94 doIntentionTest(CONVERT_SET_TO_TUPLE);
98 public void testConvertSetWithoutClosingBraceToTuple() {
99 doIntentionTest(CONVERT_SET_TO_TUPLE);
103 public void testConvertSetToList() {
104 doIntentionTest(CONVERT_SET_TO_LIST);
108 public void testConvertLiteralPreservesFormattingAndComments() {
109 doIntentionTest(CONVERT_TUPLE_TO_LIST);
113 public void testConvertOneElementListToTuple() {
114 doIntentionTest(CONVERT_LIST_TO_TUPLE);
118 public void testConvertOneElementIncompleteListToTuple() {
119 doIntentionTest(CONVERT_LIST_TO_TUPLE);
123 public void testConvertOneElementListWithCommentToTuple() {
124 doIntentionTest(CONVERT_LIST_TO_TUPLE);
128 public void testConvertOneElementListWithCommaAfterCommentToTuple() {
129 doIntentionTest(CONVERT_LIST_TO_TUPLE);
133 public void testConvertOneElementTupleToList() {
134 doIntentionTest(CONVERT_TUPLE_TO_LIST);
138 public void testConvertOneElementTupleWithoutParenthesesToSet() {
139 doIntentionTest(CONVERT_TUPLE_TO_SET);
143 public void testConvertOneElementTupleWithCommentToList() {
144 doIntentionTest(CONVERT_TUPLE_TO_LIST);