ba2211fe2b5898ebbdce92aa18d7c1ecdd3304f1
[idea/community.git] / python / testSrc / com / jetbrains / python / intentions / PyConvertCollectionLiteralIntentionTest.java
1 /*
2  * Copyright 2000-2015 JetBrains s.r.o.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.jetbrains.python.intentions;
17
18 import com.jetbrains.python.PyBundle;
19 import com.jetbrains.python.psi.LanguageLevel;
20
21 /**
22  * @author Mikhail Golubev
23  */
24 public class PyConvertCollectionLiteralIntentionTest extends PyIntentionTestCase {
25
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");
32
33   // PY-9419
34   public void testConvertParenthesizedTupleToList() {
35     doIntentionTest(CONVERT_TUPLE_TO_LIST);
36   }
37
38   // PY-9419
39   public void testConvertTupleWithoutParenthesesToList() {
40     doIntentionTest(CONVERT_TUPLE_TO_LIST);
41   }
42
43   // PY-9419
44   public void testConvertTupleWithoutClosingParenthesisToList() {
45     doIntentionTest(CONVERT_TUPLE_TO_LIST);
46   }
47
48   // PY-9419
49   public void testConvertParenthesizedTupleToSet() {
50     doIntentionTest(CONVERT_TUPLE_TO_SET);
51   }
52
53   // PY-9419
54   public void testConvertTupleToSetNotAvailableWithoutSetLiterals() {
55     runWithLanguageLevel(LanguageLevel.PYTHON25, new Runnable() {
56       public void run() {
57         doNegativeTest(CONVERT_TUPLE_TO_SET);
58       }
59     });
60   }
61
62   // PY-9419
63   public void testConvertTupleToSetNotAvailableInAssignmentTarget() {
64     doNegativeTest(CONVERT_TUPLE_TO_SET);
65   }
66
67   // PY-9419
68   public void testConvertTupleToSetNotAvailableInForLoop() {
69     doNegativeTest(CONVERT_TUPLE_TO_SET);
70   }
71
72   // PY-9419
73   public void testConvertTupleToSetNotAvailableInComprehension() {
74     doNegativeTest(CONVERT_TUPLE_TO_SET);
75   }
76
77   // PY-9419
78   public void testConvertListToTuple() {
79     doIntentionTest(CONVERT_LIST_TO_TUPLE);
80   }
81
82   // PY-9419
83   public void testConvertListWithoutClosingBracketToTuple() {
84     doIntentionTest(CONVERT_LIST_TO_TUPLE);
85   }
86
87   // PY-9419
88   public void testConvertListToSet() {
89     doIntentionTest(CONVERT_LIST_TO_SET);
90   }
91
92   // PY-9419
93   public void testConvertSetToTuple() {
94     doIntentionTest(CONVERT_SET_TO_TUPLE);
95   }
96
97   // PY-9419
98   public void testConvertSetWithoutClosingBraceToTuple() {
99     doIntentionTest(CONVERT_SET_TO_TUPLE);
100   }
101
102   // PY-9419
103   public void testConvertSetToList() {
104     doIntentionTest(CONVERT_SET_TO_LIST);
105   }
106
107   // PY-16335
108   public void testConvertLiteralPreservesFormattingAndComments() {
109     doIntentionTest(CONVERT_TUPLE_TO_LIST);
110   }
111
112   // PY-16553
113   public void testConvertOneElementListToTuple() {
114     doIntentionTest(CONVERT_LIST_TO_TUPLE);
115   }
116   
117   // PY-16553
118   public void testConvertOneElementIncompleteListToTuple() {
119     doIntentionTest(CONVERT_LIST_TO_TUPLE);
120   }
121
122   // PY-16553
123   public void testConvertOneElementListWithCommentToTuple() {
124     doIntentionTest(CONVERT_LIST_TO_TUPLE);
125   }
126   
127   // PY-16553
128   public void testConvertOneElementListWithCommaAfterCommentToTuple() {
129     doIntentionTest(CONVERT_LIST_TO_TUPLE);
130   }
131
132   // PY-16553
133   public void testConvertOneElementTupleToList() {
134     doIntentionTest(CONVERT_TUPLE_TO_LIST);
135   }
136
137   // PY-16553
138   public void testConvertOneElementTupleWithoutParenthesesToSet() {
139     doIntentionTest(CONVERT_TUPLE_TO_SET);
140   }
141
142   // PY-16553
143   public void testConvertOneElementTupleWithCommentToList() {
144     doIntentionTest(CONVERT_TUPLE_TO_LIST);
145   }
146 }