Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(608)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/correction/QuickAssistProcessorTest.java

Issue 10828169: 'Split && condition' quick assist. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/correction/QuickAssistProcessorTest.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/correction/QuickAssistProcessorTest.java b/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/correction/QuickAssistProcessorTest.java
index aa80396b546a5abbb2c118d453ad53da9ccc0460..abcc0115ac2d2dcacc5c5bb98afddeba24a5b559 100644
--- a/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/correction/QuickAssistProcessorTest.java
+++ b/editor/tools/plugins/com.google.dart.tools.ui_test/src/com/google/dart/tools/ui/correction/QuickAssistProcessorTest.java
@@ -525,6 +525,163 @@ public final class QuickAssistProcessorTest extends AbstractDartTest {
assert_replaceIfElseWithConditional_wrong(initial, "if (true)");
}
+ public void test_splitAndCondition_OK_innerAndExpression() throws Exception {
+ String initial = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (1 == 1 && 2 == 2 && 3 == 3) {",
+ " print(0);",
+ " }",
+ "}");
+ String expected = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (1 == 1) {",
+ " if (2 == 2 && 3 == 3) {",
+ " print(0);",
+ " }",
+ " }",
+ "}");
+ assert_splitAndCondition(initial, "&& 2 == 2", expected);
+ }
+
+ public void test_splitAndCondition_OK_thenBlock() throws Exception {
+ String initial = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (true && false) {",
+ " print(0);",
+ " if (3 == 3) {",
+ " print(1);",
+ " }",
+ " }",
+ "}");
+ String expected = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (true) {",
+ " if (false) {",
+ " print(0);",
+ " if (3 == 3) {",
+ " print(1);",
+ " }",
+ " }",
+ " }",
+ "}");
+ assert_splitAndCondition(initial, "&& false)", expected);
+ }
+
+ public void test_splitAndCondition_OK_thenBlock_elseBlock() throws Exception {
+ String initial = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (true && false) {",
+ " print(0);",
+ " } else {",
+ " print(1);",
+ " if (2 == 2) {",
+ " print(2);",
+ " }",
+ " }",
+ "}");
+ String expected = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (true) {",
+ " if (false) {",
+ " print(0);",
+ " } else {",
+ " print(1);",
+ " if (2 == 2) {",
+ " print(2);",
+ " }",
+ " }",
+ " }",
+ "}");
+ assert_splitAndCondition(initial, "&& false)", expected);
+ }
+
+ public void test_splitAndCondition_OK_thenStatement() throws Exception {
+ String initial = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (true && false)",
+ " print(0);",
+ "}");
+ String expected = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (true)",
+ " if (false)",
+ " print(0);",
+ "}");
+ assert_splitAndCondition(initial, "&& false)", expected);
+ }
+
+ public void test_splitAndCondition_OK_thenStatement_elseStatement() throws Exception {
+ String initial = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (true && false)",
+ " print(0);",
+ " else",
+ " print(1);",
+ "}");
+ String expected = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (true)",
+ " if (false)",
+ " print(0);",
+ " else",
+ " print(1);",
+ "}");
+ assert_splitAndCondition(initial, "&& false)", expected);
+ }
+
+ public void test_splitAndCondition_wrong() throws Exception {
+ String initial = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (1 == 1 && 2 == 2) {",
+ " print(0);",
+ " }",
+ " print(3 == 3 && 4 == 4);",
+ "}");
+ // not binary expression
+ assert_splitAndCondition_wrong(initial, "main() {");
+ // selection is not empty and includes more than just operator
+ {
+ selectionLength = 5;
+ assert_splitAndCondition_wrong(initial, "&& 2 == 2");
+ selectionLength = 0;
+ }
+ }
+
+ public void test_splitAndCondition_wrong_notPartOfIf() throws Exception {
+ String initial = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " print(1 == 1 && 2 == 2);",
+ "}");
+ assert_splitAndCondition_wrong(initial, "&& 2");
+ }
+
+ public void test_splitAndCondition_wrong_notTopLevelAnd() throws Exception {
+ String initial = makeSource(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "main() {",
+ " if (true || (1 == 1 && 2 == 2)) {",
+ " print(0);",
+ " }",
+ " if (true && (3 == 3 && 4 == 4)) {",
+ " print(0);",
+ " }",
+ "}");
+ assert_splitAndCondition_wrong(initial, "&& 2");
+ assert_splitAndCondition_wrong(initial, "&& 4");
+ }
+
public void test_splitVariableDeclaration_OK() throws Exception {
String initial = makeSource(
"// filler filler filler filler filler filler filler filler filler filler",
@@ -753,7 +910,7 @@ public final class QuickAssistProcessorTest extends AbstractDartTest {
String offsetPattern,
String expectedSource) throws Exception {
// XXX used to see coverage of only one quick assist
-// if (!proposalName.equals(CorrectionMessages.QuickAssistProcessor_replaceIfElseWithConditional)) {
+// if (!proposalName.equals(CorrectionMessages.QuickAssistProcessor_splitAndCondition)) {
// return;
// }
// set initial source
@@ -775,6 +932,22 @@ public final class QuickAssistProcessorTest extends AbstractDartTest {
assertEquals(expectedSource, result);
}
+ private void assert_splitAndCondition(
+ String initialSource,
+ String offsetPattern,
+ String expectedSource) throws Exception {
+ assert_runProcessor(
+ CorrectionMessages.QuickAssistProcessor_splitAndCondition,
+ initialSource,
+ offsetPattern,
+ expectedSource);
+ }
+
+ private void assert_splitAndCondition_wrong(String initialSource, String offsetPattern)
+ throws Exception {
+ assert_splitAndCondition(initialSource, offsetPattern, initialSource);
+ }
+
private void assert_splitVariableDeclaration(
String initialSource,
String offsetPattern,
« no previous file with comments | « editor/tools/plugins/com.google.dart.tools.ui/src/com/google/dart/tools/ui/internal/text/correction/QuickAssistProcessor.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698