mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 02:07:50 +08:00
Draft Complete
This commit is contained in:
parent
c83e24d8bd
commit
b6a9cff1ba
@ -40,7 +40,7 @@ public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testFormatter() {
|
||||
myFixture.configureByFiles("FormatterTestData.simple");
|
||||
myFixture.configureByFile("FormatterTestData.simple");
|
||||
CodeStyle.getLanguageSettings(myFixture.getFile()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true;
|
||||
CodeStyle.getLanguageSettings(myFixture.getFile()).KEEP_BLANK_LINES_IN_CODE = 2;
|
||||
WriteCommandAction.writeCommandAction(getProject()).run(() -> {
|
||||
@ -57,7 +57,7 @@ public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testFolding() {
|
||||
myFixture.configureByFiles("DefaultTestData.simple");
|
||||
myFixture.configureByFile("DefaultTestData.simple");
|
||||
myFixture.testFolding(getTestDataPath() + "/FoldingTestData.java");
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,9 @@ Rather than the usual practice of using a folding builder to collapse a class, m
|
||||
The `SimpleFoldingBuilder` replaces usages of properties with their values by default.
|
||||
Start by subclassing [`FoldingBuilderEx`](upsource:///community/platform/core-api/src/com/intellij/lang/folding/FoldingBuilderEx.java)
|
||||
|
||||
Note that `SimpleFoldingBuilder` also implements `DumbAware`, which means the class is allowed to run in dumb mode, when indices are in background update.
|
||||
Implementing `DumbAware` is required for successful operation and testing.
|
||||
Note that `SimpleFoldingBuilder` also implements [`DumbAware`](upsource:///platform/core-api/src/com/intellij/openapi/project/DumbAware.java), which means the class is allowed to run in dumb mode, when indices are in background update.
|
||||
|
||||
> **NOTE** A folding builder must implement [`DumbAware`](upsource:///platform/core-api/src/com/intellij/openapi/project/DumbAware.java) to function in this tutorial and pass tests.
|
||||
|
||||
The `buildFoldRegions()` method searches down a PSI tree from `root` to find all literal expressions containing the [simple prefix](/tutorials/custom_language_support/annotator.md#define-an-annotator) `simple:`.
|
||||
The remainder of such a string is expected to contain a Simple language key, and so the text range is stored as a [`FoldingDescriptor`](upsource:///platform/core-api/src/com/intellij/lang/folding/FoldingDescriptor.java).
|
||||
|
@ -2,16 +2,15 @@
|
||||
title: 4. Annotator Test
|
||||
---
|
||||
|
||||
In this test we will check if the annotator, implemented in the
|
||||
[Annotator](/tutorials/custom_language_support/annotator.md) section
|
||||
of the
|
||||
[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md)
|
||||
works as expected.
|
||||
This test checks if the Simple language annotator functionality, implemented in the [Annotator](/tutorials/custom_language_support/annotator.md) section of the Custom Language Support Tutorial, works as expected.
|
||||
|
||||
### 4.1. Define test data
|
||||
|
||||
Create a file *AnnotatorTestData.java*.
|
||||
## 4.1. Define Input Test Data
|
||||
The `DefaultTestData.simple` properties file is reused for this test.
|
||||
|
||||
Create an input test file `AnnotatorTestData.java` in the `testData` directory.
|
||||
This file contains two instances of Simple language embedded in the Java code.
|
||||
The first instance is a valid use of the `simple:` prefix followed by the Simple language key `website`.
|
||||
The second is a valid prefix but an invalid key, as noted by the test `<error>` [highlighting](/basics/testing_plugins/testing_highlighting.md).
|
||||
```java
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
@ -21,8 +20,10 @@ public class Test {
|
||||
}
|
||||
```
|
||||
|
||||
### 4.2. Define a test method
|
||||
|
||||
## 4.2. Define a Test Method
|
||||
Add the `testAnnotator()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test).
|
||||
Again, this method configures the test fixture by using the test files.
|
||||
It then calls the `checkHighlighting()` method to verify weak warnings.
|
||||
```java
|
||||
public void testAnnotator() {
|
||||
myFixture.configureByFiles("AnnotatorTestData.java", "DefaultTestData.simple");
|
||||
@ -30,6 +31,5 @@ public void testAnnotator() {
|
||||
}
|
||||
```
|
||||
|
||||
### 4.3. Run the test
|
||||
|
||||
Run the test and make sure it's green.
|
||||
## 4.3. Run the Test
|
||||
[Run](completion_test.md#run-the-test) the test and make sure it's green.
|
||||
|
@ -2,21 +2,24 @@
|
||||
title: 9. Commenter Test
|
||||
---
|
||||
|
||||
In this test we will check if the commenter, implemented in the [Commenter](/tutorials/custom_language_support/commenter.md) section of the [Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md), works as we expect.
|
||||
This test will check if the commenter, implemented in the [Commenter](/tutorials/custom_language_support/commenter.md) section of the Custom Language Support Tutorial, works as expected.
|
||||
|
||||
### 9.1. Define a test method
|
||||
### 9.1. Define a Test Method
|
||||
Add the `testCommenter()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test).
|
||||
This test constructs a Simple language properties file containing one line, with the virtual caret positioned at the beginning of the line.
|
||||
The test calls the commenter to insert a comment character at the caret, then verifies the results.
|
||||
It again calls the line comment action to remove the comment character and verifies the results.
|
||||
|
||||
```java
|
||||
public void testCommenter() {
|
||||
public void testCommenter() {
|
||||
myFixture.configureByText(SimpleFileType.INSTANCE, "<caret>website = http://en.wikipedia.org/");
|
||||
CommentByLineCommentAction commentAction = new CommentByLineCommentAction();
|
||||
commentAction.actionPerformedImpl(getProject(), myFixture.getEditor());
|
||||
myFixture.checkResult("#website = http://en.wikipedia.org/");
|
||||
commentAction.actionPerformedImpl(getProject(), myFixture.getEditor());
|
||||
myFixture.checkResult("website = http://en.wikipedia.org/");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 9.2. Run the test
|
||||
|
||||
Run the test and make sure it's green.
|
||||
### 9.2. Run the Test
|
||||
[Run](completion_test.md#run-the-test) the test and make sure it's green.
|
||||
|
@ -2,15 +2,17 @@
|
||||
title: 3. Completion Test
|
||||
---
|
||||
|
||||
This test checks if code completion, implemented in the [Reference Contributor](/tutorials/custom_language_support/reference_contributor.md) section of the Custom Language Support Tutorial, works as expected.
|
||||
This test checks if the Simple language code completion functionality, implemented in the [Reference Contributor](/tutorials/custom_language_support/reference_contributor.md) section of the Custom Language Support Tutorial, works as expected.
|
||||
|
||||
## 3.1. Define Test Data
|
||||
Create an input Simple file `DefaultTestData.simple` for the test.
|
||||
Create the `DefaultTestData.simple` properties file in the `testData` directory.
|
||||
|
||||
```bash
|
||||
{% include /code_samples/simple_language_plugin/src/test/testData/DefaultTestData.simple %}
|
||||
```
|
||||
|
||||
Create an input java file `CompleteTestData.java` for the test.
|
||||
Create a test input Java file `CompleteTestData.java` in the `testData` directory.
|
||||
This file contains a Simple language snippet within the Java.
|
||||
```java
|
||||
{% include /code_samples/simple_language_plugin/src/test/testData/CompleteTestData.java %}
|
||||
```
|
||||
@ -18,7 +20,14 @@ Create an input java file `CompleteTestData.java` for the test.
|
||||
## 3.2. Define a Test
|
||||
Subclass `LightJavaCodeInsightFixtureTestCase` to create `SimpleCodeInsightTest`.
|
||||
Override `getTestDataPath()`, and return the path from the root of this plugin module to the `testData` directory.
|
||||
At this point only one test is defined, `testCompletion()`.
|
||||
|
||||
At this point only one test is defined in `SimpleCodeInsightTest`: `testCompletion()`.
|
||||
This method:
|
||||
* Configures the test using the two input files.
|
||||
* Calls the basic completion functionality.
|
||||
Behind the scenes, this method call creates a list of possible elements to complete the embedded Simple language reference.
|
||||
* Checks the list of possible element names to ensure it contains all Simple language completion possibilities.
|
||||
|
||||
```java
|
||||
public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
@Override
|
||||
@ -36,5 +45,10 @@ public class SimpleCodeInsightTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
}
|
||||
```
|
||||
|
||||
## 3.3. Run the test
|
||||
As [before](parsing_test.md#run-the-test), run the test and make sure it's green.
|
||||
## 3.3. Run the Test
|
||||
Run the test by:
|
||||
* Opening the Gradle Tool Window.
|
||||
* Drill down to the `simple_language_plugin`.
|
||||
You may need to reimport it as a Gradle project.
|
||||
* Drill down under `simple_language_plugin` to the *test* task under *verification*.
|
||||
* Run the *test* task.
|
||||
|
@ -2,51 +2,31 @@
|
||||
title: 8. Find Usages Test
|
||||
---
|
||||
|
||||
In this test we will check if the find usages provider, implemented in the
|
||||
[Find Usages Provider](/tutorials/custom_language_support/find_usages_provider.md)
|
||||
section of the
|
||||
[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md),
|
||||
works correctly.
|
||||
This test ensures the find usages provider, implemented in the [Find Usages Provider](/tutorials/custom_language_support/find_usages_provider.md) section of the Custom Language Support Tutorial, works correctly.
|
||||
|
||||
### 8.1. Define test data
|
||||
|
||||
Create a file *FindUsagesTestData.simple*.
|
||||
## 8.1. Define test data
|
||||
Create the `FindUsagesTestData.simple` properties file in the `testData` directory.
|
||||
|
||||
```bash
|
||||
# You are reading the ".properties" entry.
|
||||
! The exclamation mark can also mark text as comments.
|
||||
<caret>website = http://en.wikipedia.org/
|
||||
|
||||
language = English
|
||||
# The backslash below tells the application to continue reading
|
||||
# the value onto the next line.
|
||||
message = Welcome to \
|
||||
Wikipedia!
|
||||
# Add spaces to the key
|
||||
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
|
||||
# Unicode
|
||||
tab : \u0009
|
||||
{% include /code_samples/simple_language_plugin/src/test/testData/FindUsagesTestData.simple %}
|
||||
```
|
||||
|
||||
Create a file *FindUsagesTestData.java*.
|
||||
Create the test file `FindUsagesTestData.java`, which contains one embedded Simple language prefix and key.
|
||||
|
||||
```java
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("simple:website");
|
||||
}
|
||||
}
|
||||
{% include /code_samples/simple_language_plugin/src/test/testData/FindUsagesTestData.java %}
|
||||
```
|
||||
|
||||
### 8.2. Define a test method
|
||||
## 8.2. Define a Test Method
|
||||
Add the `testFindUsages()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test).
|
||||
This test verifies the find usage functionality will identify the "key with spaces".
|
||||
|
||||
```java
|
||||
public void testFindUsages() {
|
||||
public void testFindUsages() {
|
||||
Collection<UsageInfo> usageInfos = myFixture.testFindUsages("FindUsagesTestData.simple", "FindUsagesTestData.java");
|
||||
assertEquals(1, usageInfos.size());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 8.3. Run the test
|
||||
|
||||
Run the test and make sure it's green.
|
||||
## 8.3. Run the Test
|
||||
[Run](completion_test.md#run-the-test) the test and make sure it's green.
|
||||
|
@ -2,33 +2,26 @@
|
||||
title: 7. Folding Test
|
||||
---
|
||||
|
||||
In this test we will check if the folding builder, implemented in the
|
||||
[Folding Builder](/tutorials/custom_language_support/folding_builder.md)
|
||||
section of the
|
||||
[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md),
|
||||
works as we expect.
|
||||
This test verifies the Simple language folding builder, implemented in the [Folding Builder](/tutorials/custom_language_support/folding_builder.md) section of the Custom Language Support Tutorial, works as expected.
|
||||
|
||||
### 7.1. Define test data
|
||||
|
||||
Create a file *FoldingTestData.java*.
|
||||
> **NOTE** A folding builder must implement [`DumbAware`](upsource:///platform/core-api/src/com/intellij/openapi/project/DumbAware.java) to pass tests. See [Define a Folding Builder](/tutorials/custom_language_support/folding_builder.md#define-a-folding-builder) for more information.
|
||||
|
||||
## 7.1. Define Test Data
|
||||
Create a file `FoldingTestData.java` in the `testData` directory.
|
||||
This java file contains markup instructions for three different cases of code folding.
|
||||
```java
|
||||
public class Test {
|
||||
public static void main(String[] args)<fold text=' { '> {
|
||||
</fold>System.out.println("<fold text='http://en.wikipedia.org/'>simple:website</fold>");<fold text=' }'>
|
||||
}</fold>
|
||||
}
|
||||
{% include /code_samples/simple_language_plugin/src/test/testData/FoldingTestData.java %}
|
||||
```
|
||||
|
||||
### 7.2. Define a test
|
||||
|
||||
## 7.2. Define a Test
|
||||
Add the `testFolding()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test).
|
||||
This test method reuses the `DefaultTestData.simple` properties file.
|
||||
```java
|
||||
public void testFolding() {
|
||||
myFixture.configureByFiles("DefaultTestData.simple");
|
||||
public void testFolding() {
|
||||
myFixture.configureByFile("DefaultTestData.simple");
|
||||
myFixture.testFolding(getTestDataPath() + "/FoldingTestData.java");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 7.3. Run the test
|
||||
|
||||
Run the test and make sure it's green.
|
||||
## 7.3. Run the Test
|
||||
[Run](completion_test.md#run-the-test) the test and make sure it's green.
|
||||
|
@ -2,51 +2,36 @@
|
||||
title: 5. Formatter Test
|
||||
---
|
||||
|
||||
In this test we will check if the formatter, implemented in the
|
||||
[Formatter](/tutorials/custom_language_support/formatter.md)
|
||||
section of the
|
||||
[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md)
|
||||
works as we expect.
|
||||
This test checks if the Simple language formatter, implemented in the [Formatter](/tutorials/custom_language_support/formatter.md) section of the Custom Language Support Tutorial, works as expected.
|
||||
|
||||
### 5.1. Define test data
|
||||
|
||||
Create a file *FormatterTestData.simple*.
|
||||
## 5.1. Define Test Data
|
||||
Create the `FormatterTestData.simple` properties file in the `testData` directory.
|
||||
|
||||
```bash
|
||||
# You are reading the ".properties" entry.
|
||||
! The exclamation mark can also mark text as comments.
|
||||
website=http://en.wikipedia.org/
|
||||
|
||||
language= English
|
||||
# The backslash below tells the application to continue reading
|
||||
# the value onto the next line.
|
||||
message = Welcome to \
|
||||
Wikipedia!
|
||||
# Add spaces to the key
|
||||
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
|
||||
# Unicode
|
||||
tab :\u0009
|
||||
{% include /code_samples/simple_language_plugin/src/test/testData/FormatterTestData.simple %}
|
||||
```
|
||||
|
||||
### 5.2. Define a test method
|
||||
## 5.2. Define a Test Method
|
||||
Add the `testFormatter()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test).
|
||||
* Again, this method configures the test fixture by using the test file.
|
||||
* The code style Simple language settings for spaces and blank lines are set.
|
||||
* The file is then formatted according to the settings.
|
||||
* The formatted file is compared to the expected results in the benchmark file `DefaultTestData.simple`.
|
||||
|
||||
```java
|
||||
public void testFormatter() {
|
||||
myFixture.configureByFiles("FormatterTestData.simple");
|
||||
CodeStyleSettingsManager.getSettings(getProject()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true;
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
CodeStyleManager.getInstance(getProject()).reformatText(myFixture.getFile(),
|
||||
ContainerUtil.newArrayList(myFixture.getFile().getTextRange()));
|
||||
}
|
||||
}.execute();
|
||||
public void testFormatter() {
|
||||
myFixture.configureByFile("FormatterTestData.simple");
|
||||
CodeStyle.getLanguageSettings(myFixture.getFile()).SPACE_AROUND_ASSIGNMENT_OPERATORS = true;
|
||||
CodeStyle.getLanguageSettings(myFixture.getFile()).KEEP_BLANK_LINES_IN_CODE = 2;
|
||||
WriteCommandAction.writeCommandAction(getProject()).run(() -> {
|
||||
CodeStyleManager.getInstance(getProject()).reformatText(myFixture.getFile(),
|
||||
ContainerUtil.newArrayList(myFixture.getFile().getTextRange()));
|
||||
});
|
||||
myFixture.checkResultByFile("DefaultTestData.simple");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 5.3. Run the test
|
||||
|
||||
Run the test and make sure it's green.
|
||||
## 5.3. Run the Test
|
||||
[Run](completion_test.md#run-the-test) the test and make sure it's green.
|
||||
|
||||
>> **TIP** See also [`FormatterTestCase`](upsource:///platform/testFramework/src/com/intellij/psi/formatter/FormatterTestCase.java) as convenient base class.
|
||||
|
@ -2,14 +2,16 @@
|
||||
title: 2. Parsing Test
|
||||
---
|
||||
|
||||
The first test checks if the parser, implemented in the [Lexer and Parser Definition](/tutorials/custom_language_support/lexer_and_parser_definition.md) section of the Custom Language Support Tutorial, works as expected.
|
||||
The first test checks if the Simple language parser, implemented in the [Lexer and Parser Definition](/tutorials/custom_language_support/lexer_and_parser_definition.md) section of the Custom Language Support Tutorial, works as expected.
|
||||
|
||||
## 2.1. Update Grammar and Regenerate the Parser
|
||||
Before creating the parsing test, ensure the parser definition (`Simple.bnf`) includes the lines shown below.
|
||||
These additional lines facilitate testing mangled keys.
|
||||
These additional lines facilitate testing incorrect keys.
|
||||
|
||||
If the lines below are not present in `Simple.bnf`, replace the existing `property` definition with the lines below.
|
||||
Don't forget to regenerate the parser after updating the file!
|
||||
Right-click on the `Simple.bnf` file and select **Generate Parser Code**.
|
||||
|
||||
```java
|
||||
property ::= (KEY? SEPARATOR VALUE?) | KEY {
|
||||
pin=3
|
||||
@ -22,7 +24,7 @@ private recover_property ::= !(KEY|SEPARATOR|COMMENT)
|
||||
```
|
||||
|
||||
## 2.2. Define Input Test Data
|
||||
Create a file *ParsingTestData.simple* in the *testData* folder.
|
||||
Create the *ParsingTestData.simple* properties file in the *testData* folder.
|
||||
Note the last few lines define a purposely incorrect key.
|
||||
```bash
|
||||
{% include /code_samples/simple_language_plugin/src/test/testData/ParsingTestData.simple %}
|
||||
|
@ -2,35 +2,30 @@
|
||||
title: 10. Reference Test
|
||||
---
|
||||
|
||||
This test checks if references functionality, implemented in the [Reference Contributor](/tutorials/custom_language_support/reference_contributor.md) section of the Custom Language Support Tutorial, works as expected.
|
||||
|
||||
In this test we will check if references, implemented in the
|
||||
[Reference Contributor](/tutorials/custom_language_support/reference_contributor.md)
|
||||
section of the
|
||||
[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md),
|
||||
works as we expect.
|
||||
## 10.1. Define Test Data
|
||||
This test reuses the Simple language properties file `DefaultTestData.simple`.
|
||||
|
||||
### 10.1. Define test data
|
||||
|
||||
Create a file *ReferenceTestData.java*.
|
||||
Create the test file `ReferenceTestData.java` in the `testData` directory.
|
||||
This file has one Simple language prefix and key, with the caret placed after the key.
|
||||
|
||||
```java
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("simple:website<caret>");
|
||||
}
|
||||
}
|
||||
{% include /code_samples/simple_language_plugin/src/test/testData/ReferenceTestData.java %}
|
||||
```
|
||||
|
||||
### 10.2. Define a test method
|
||||
## 10.2. Define a Test Method
|
||||
Add the `testReference()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test).
|
||||
This test is configured by the test files.
|
||||
The fixture gets the `PsiElement` at the caret, then compares its value with the known value of that key.
|
||||
|
||||
```java
|
||||
public void testReference() {
|
||||
public void testReference() {
|
||||
myFixture.configureByFiles("ReferenceTestData.java", "DefaultTestData.simple");
|
||||
PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent();
|
||||
assertEquals("http://en.wikipedia.org/", ((SimpleProperty) element.getReferences()[0].resolve()).getValue());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 10.3. Run the test
|
||||
|
||||
Run the test and make sure it's green.
|
||||
## 10.3. Run the Test
|
||||
[Run](completion_test.md#run-the-test) the test and make sure it's green.
|
||||
|
@ -2,72 +2,44 @@
|
||||
title: 6. Rename Test
|
||||
---
|
||||
|
||||
This test verifies the Simple language in-place rename functionality, implemented in the [Reference Contributor](/tutorials/custom_language_support/reference_contributor.md) section of the Custom Language Support Tutorial, works as expected.
|
||||
|
||||
In this test we will check if in-place rename, implemented in the
|
||||
[Reference Contributor](/tutorials/custom_language_support/reference_contributor.md)
|
||||
section of the
|
||||
[Custom Language Support Tutorial](/tutorials/custom_language_support_tutorial.md), works as we expect.
|
||||
|
||||
### 6.1. Define input test data
|
||||
|
||||
Create a file *RenameTestData.simple*.
|
||||
## 6.1. Define Input Test Data
|
||||
Create the `RenameTestData.simple` properties file in the `testData` directory.
|
||||
|
||||
```bash
|
||||
# You are reading the ".properties" entry.
|
||||
! The exclamation mark can also mark text as comments.
|
||||
website = http://en.wikipedia.org/
|
||||
|
||||
language = English
|
||||
# The backslash below tells the application to continue reading
|
||||
# the value onto the next line.
|
||||
message = Welcome to \
|
||||
Wikipedia!
|
||||
# Add spaces to the key
|
||||
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
|
||||
# Unicode
|
||||
tab : \u0009
|
||||
{% include /code_samples/simple_language_plugin/src/test/testData/RenameTestData.simple %}
|
||||
```
|
||||
|
||||
Create a file *RenameTestData.java*.
|
||||
Create the file `RenameTestData.java` in the `testData` directory.
|
||||
This file contains one Simple language reference embedded in Java, with the [caret position](/basics/testing_plugins/test_project_and_testdata_directories.md#special-markup) placed just after a Simple language key.
|
||||
|
||||
```java
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("simple:website<caret>");
|
||||
}
|
||||
}
|
||||
{% include /code_samples/simple_language_plugin/src/test/testData/RenameTestData.java %}
|
||||
```
|
||||
|
||||
### 6.2. Create output test data
|
||||
|
||||
Create a file *RenameTestDataAfter.simple*.
|
||||
## 6.2. Create Output Test Data
|
||||
Create the `RenameTestDataAfter.simple` properties file in the `testData` directory.
|
||||
This file contains the expected outcome of the test.
|
||||
Note the `website =` in `RenameTestData.simple` should be renamed to `websiteUrl =` by the test.
|
||||
|
||||
```bash
|
||||
# You are reading the ".properties" entry.
|
||||
! The exclamation mark can also mark text as comments.
|
||||
websiteUrl = http://en.wikipedia.org/
|
||||
|
||||
language = English
|
||||
# The backslash below tells the application to continue reading
|
||||
# the value onto the next line.
|
||||
message = Welcome to \
|
||||
Wikipedia!
|
||||
# Add spaces to the key
|
||||
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
|
||||
# Unicode
|
||||
tab : \u0009
|
||||
{% include /code_samples/simple_language_plugin/src/test/testData/RenameTestDataAfter.simple %}
|
||||
```
|
||||
|
||||
### 6.3. Define a test method
|
||||
|
||||
## 6.3. Define a Test Method
|
||||
Add the `testRename()` method to the `SimpleCodeInsightTest` class [previously defined](completion_test.md#define-a-test).
|
||||
* Again, this method configures the test fixture by using the test files.
|
||||
* The fixture then renames the Simple language element at the caret in `RenameTestData.java`.
|
||||
* It then compares the input and output property files, ignoring whitespace.
|
||||
|
||||
```java
|
||||
public void testRename() {
|
||||
public void testRename() {
|
||||
myFixture.configureByFiles("RenameTestData.java", "RenameTestData.simple");
|
||||
myFixture.renameElementAtCaret("websiteUrl");
|
||||
myFixture.checkResultByFile("RenameTestData.simple", "RenameTestDataAfter.simple", false);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 6.4. Run the test
|
||||
|
||||
Run the test and make sure it's green.
|
||||
## 6.4. Run the Test
|
||||
[Run](completion_test.md#run-the-test) the test and make sure it's green.
|
||||
|
@ -20,11 +20,12 @@ Mark the `java` folder as a test source root via the context menu `Mark Director
|
||||
Similarly, mark the `testData` folder as a test resource root via the context menu `Mark Directory As` → `Test Resources Root`.
|
||||
|
||||
## 1.2. Set the Run Configuration Parameters
|
||||
Since some of the tests use Java files as test data, the tests need to mock up the project SDK.
|
||||
IntelliJ IDEA does everything automatically when we use the utility class [`LightJavaCodeInsightFixtureTestCase`](upsource:///java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java) as the basis for our tests.
|
||||
Because some of the tests use Java files as test data, the tests need to mock up the project SDK.
|
||||
IntelliJ IDEA does everything automatically when the utility class [`LightJavaCodeInsightFixtureTestCase`](upsource:///java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java) is used as the basis for the tests.
|
||||
|
||||
The system properties are defined in the `build.gradle` file using the snippet shown below.
|
||||
The "/path/to/community/" is set to the absolute path to the root directory of the local intellij-community source on the machine running the tests.
|
||||
For example, on macOS the "path/to/community/" might be `/Users/<user name>/Documents/<community source root>/`
|
||||
```groovy
|
||||
test {
|
||||
systemProperty "idea.home.path", "/path/to/community/"
|
||||
|
Loading…
x
Reference in New Issue
Block a user