add android rename tests

This commit is contained in:
Mikhail Mutcianko
2014-09-18 14:58:32 +04:00
committed by Yan Zhulanow
parent e922a91958
commit 4145991bea
13 changed files with 272 additions and 1 deletions
@@ -148,6 +148,7 @@ import org.jetbrains.jet.lang.resolve.android.AbstractAndroidBoxTest
import org.jetbrains.jet.android.AbstractAndroidCompletionTest
import org.jetbrains.jet.android.AbstractAndroidGotoTest
import org.jetbrains.jet.jps.build.android.AbstractAndroidJpsTestCase
import org.jetbrains.jet.android.AbstractAndroidRenameTest
fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true")
@@ -721,6 +722,10 @@ fun main(args: Array<String>) {
testClass(javaClass<AbstractAndroidGotoTest>()) {
model("android/goto", recursive = false, extension = null)
}
testClass(javaClass<AbstractAndroidRenameTest>()) {
model("android/rename", recursive = false, extension = null)
}
}
testGroup("idea/tests", "compiler/testData") {
@@ -0,0 +1,9 @@
package com.myapp
import android.app.Activity
class MyActivity: Activity() {
val button = this.MyButton<caret>
}
@@ -0,0 +1,15 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<view
class="org.my.cool.Button"
android:id="@+id/MyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,9 @@
package com.myapp
import android.app.Activity
class MyActivity: Activity() {
val button = this.MyButton<caret>
}
@@ -0,0 +1,14 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<org.my.cool.Button
android:id="@+id/MyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,10 @@
package com.myapp
import android.app.Activity
class MyActivity: Activity() {
val button = this.login<caret>
val button1 = this.loginButton
}
@@ -0,0 +1,29 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your password" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,29 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/passwordField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your password" />
<EditText
android:id="@+id/passwordCaption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,17 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,12 @@
package com.myapp
import android.app.Activity
import android.os.Bundle
import java.io.File
public class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {}
val button = login<caret>
}
@@ -0,0 +1,60 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.android
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil
import com.intellij.codeInsight.TargetElementUtilBase
import com.intellij.refactoring.rename.RenamePsiElementProcessor
import com.intellij.refactoring.rename.RenameProcessor
import org.jetbrains.jet.plugin.PluginTestCaseBase
import com.intellij.codeInsight.navigation.actions.GotoDeclarationAction
import kotlin.test.assertEquals
public abstract class AbstractAndroidRenameTest : KotlinAndroidTestCase() {
private val NEW_NAME = "NEWNAME"
public fun doTest(path: String) {
val f = myFixture!!
f.copyDirectoryToProject(getResDir()!!, "res")
f.configureByFile(path + getTestName(true) + ".kt")
renameElementWithTextOccurences(NEW_NAME)
val resolved = GotoDeclarationAction.findTargetElement(f.getProject(), f.getEditor(), f.getCaretOffset())
assertEquals("\"@+id/$NEW_NAME\"", resolved?.getText())
}
private fun renameElementWithTextOccurences(newName: String) {
val f = myFixture!!
object : WriteCommandAction.Simple<Unit>(f.getProject()) {
protected override fun run() {
val editor = f.getEditor()
val file = f.getFile()
val completionEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(editor, file)
val element = TargetElementUtilBase.findTargetElement(completionEditor, TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED or TargetElementUtilBase.ELEMENT_NAME_ACCEPTED)
// val element = TargetElementUtilBase.findReference(editor)?.getElement()
assert(element != null)
val substitution = RenamePsiElementProcessor.forElement(element!!).substituteElementToRename(element, editor)
RenameProcessor(f.getProject(), substitution, newName, false, true).run()
}
}.execute().throwException()
}
override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/android/rename/" + getTestName(true) + "/"
}
@@ -58,5 +58,5 @@ public class AndroidGotoTestGenerated extends AbstractAndroidGotoTest {
String fileName = JetTestUtils.navigationMetadata("idea/testData/android/goto/simple/");
doTest(fileName);
}
}
@@ -0,0 +1,62 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.android;
import com.intellij.testFramework.TestDataPath;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/android/rename")
@TestDataPath("$PROJECT_ROOT")
public class AndroidRenameTestGenerated extends AbstractAndroidRenameTest {
public void testAllFilesPresentInRename() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/android/rename"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("fqNameInAttr")
public void testFqNameInAttr() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/android/rename/fqNameInAttr/");
doTest(fileName);
}
@TestMetadata("fqNameInTag")
public void testFqNameInTag() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/android/rename/fqNameInTag/");
doTest(fileName);
}
@TestMetadata("multiFile")
public void testMultiFile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/android/rename/multiFile/");
doTest(fileName);
}
@TestMetadata("simple")
public void testSimple() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/android/rename/simple/");
doTest(fileName);
}
}