mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
Move some of the old JSON parsing tests to new plugin
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
<exclude-output />
|
<exclude-output />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/testData" type="java-test-resource" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
|||||||
@@ -1,28 +1,14 @@
|
|||||||
package com.intellij.json;
|
package com.intellij.json;
|
||||||
|
|
||||||
import com.intellij.testFramework.IdeaTestCase;
|
|
||||||
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
|
|
||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mikhail Golubev
|
* @author Mikhail Golubev
|
||||||
*/
|
*/
|
||||||
public class JsonCompletionTest extends CodeInsightFixtureTestCase {
|
public class JsonCompletionTest extends JsonTestCase {
|
||||||
private static final String[] KEYWORDS = new String[]{"true", "false", "null"};
|
private static final String[] KEYWORDS = new String[]{"true", "false", "null"};
|
||||||
private static final String[] NOTHING = ArrayUtil.EMPTY_STRING_ARRAY;
|
private static final String[] NOTHING = ArrayUtil.EMPTY_STRING_ARRAY;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
IdeaTestCase.initPlatformPrefix();
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
protected String getBasePath() {
|
|
||||||
return "/json/tests/testData/completion";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean isCommunity() {
|
protected boolean isCommunity() {
|
||||||
return true;
|
return true;
|
||||||
@@ -49,6 +35,6 @@ public class JsonCompletionTest extends CodeInsightFixtureTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doTest(String... variants) {
|
private void doTest(String... variants) {
|
||||||
myFixture.testCompletionVariants(getTestName(false) + ".json", variants);
|
myFixture.testCompletionVariants("completion/" + getTestName(false) + ".json", variants);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.intellij.json;
|
|||||||
|
|
||||||
import com.intellij.openapi.diagnostic.Logger;
|
import com.intellij.openapi.diagnostic.Logger;
|
||||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||||
|
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||||
import com.intellij.psi.formatter.FormatterTestCase;
|
import com.intellij.psi.formatter.FormatterTestCase;
|
||||||
import com.intellij.testFramework.IdeaTestCase;
|
import com.intellij.testFramework.IdeaTestCase;
|
||||||
import com.intellij.testFramework.PlatformTestUtil;
|
import com.intellij.testFramework.PlatformTestUtil;
|
||||||
@@ -23,7 +24,6 @@ public class JsonFormattingTest extends FormatterTestCase {
|
|||||||
return "formatting";
|
return "formatting";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Why the heck do I specify path to testData in each kind of test differently?
|
|
||||||
@Override
|
@Override
|
||||||
protected String getTestDataPath() {
|
protected String getTestDataPath() {
|
||||||
return PlatformTestUtil.getCommunityPath() + "/json/tests/testData/";
|
return PlatformTestUtil.getCommunityPath() + "/json/tests/testData/";
|
||||||
@@ -48,9 +48,7 @@ public class JsonFormattingTest extends FormatterTestCase {
|
|||||||
|
|
||||||
public void testWrapping() throws Exception {
|
public void testWrapping() throws Exception {
|
||||||
CodeStyleSettings settings = getSettings();
|
CodeStyleSettings settings = getSettings();
|
||||||
int indentSize = settings.getCommonSettings(JsonLanguage.INSTANCE).getIndentOptions().INDENT_SIZE;
|
settings.setRightMargin(JsonLanguage.INSTANCE, 20);
|
||||||
// LOG.debug("Intend size for JSON: " + indentSize);
|
|
||||||
settings.RIGHT_MARGIN = 20;
|
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,31 @@ public class JsonParsingTest extends ParsingTestCase {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSimple1() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimple2() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimple4() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: ask about these tests
|
||||||
|
//public void testSimple3() {
|
||||||
|
// doTest();
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//public void testReal1() {
|
||||||
|
// doTest();
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//public void testReal2() {
|
||||||
|
// doTest();
|
||||||
|
//}
|
||||||
|
|
||||||
private void doTest() {
|
private void doTest() {
|
||||||
doTest(true);
|
doTest(true);
|
||||||
}
|
}
|
||||||
|
|||||||
24
json/tests/test/com/intellij/json/JsonTestCase.java
Normal file
24
json/tests/test/com/intellij/json/JsonTestCase.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package com.intellij.json;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.PlatformTestCase;
|
||||||
|
import com.intellij.testFramework.TestDataPath;
|
||||||
|
import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mikhail Golubev
|
||||||
|
*/
|
||||||
|
@TestDataPath("$CONTENT_ROOT/../testData")
|
||||||
|
public abstract class JsonTestCase extends CodeInsightFixtureTestCase {
|
||||||
|
@Override
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
PlatformTestCase.autodetectPlatformPrefix();
|
||||||
|
//IdeaTestCase.initPlatformPrefix();
|
||||||
|
super.setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public String getBasePath() {
|
||||||
|
return "/json/tests/testData";
|
||||||
|
}
|
||||||
|
}
|
||||||
8
json/tests/testData/psi/Real1.json
Normal file
8
json/tests/testData/psi/Real1.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
navigation: [
|
||||||
|
{
|
||||||
|
name: "Demo Applications",
|
||||||
|
demos: [ "Mail", "Moxie" ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
43
json/tests/testData/psi/Real1.txt
Normal file
43
json/tests/testData/psi/Real1.txt
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
JSFile:Real.json
|
||||||
|
JSObjectLiteralExpression
|
||||||
|
PsiElement(JS:LBRACE)('{')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
JSProperty
|
||||||
|
PsiElement(JS:IDENTIFIER)('navigation')
|
||||||
|
PsiElement(JS:COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JSArrayLiteralExpression
|
||||||
|
PsiElement(JS:LBRACKET)('[')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
JSObjectLiteralExpression
|
||||||
|
PsiElement(JS:LBRACE)('{')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
JSProperty
|
||||||
|
PsiElement(JS:IDENTIFIER)('name')
|
||||||
|
PsiElement(JS:COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JSLiteralExpression
|
||||||
|
PsiElement(JS:STRING_LITERAL)('"Demo Applications"')
|
||||||
|
PsiElement(JS:COMMA)(',')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
JSProperty
|
||||||
|
PsiElement(JS:IDENTIFIER)('demos')
|
||||||
|
PsiElement(JS:COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JSArrayLiteralExpression
|
||||||
|
PsiElement(JS:LBRACKET)('[')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JSLiteralExpression
|
||||||
|
PsiElement(JS:STRING_LITERAL)('"Mail"')
|
||||||
|
PsiElement(JS:COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JSLiteralExpression
|
||||||
|
PsiElement(JS:STRING_LITERAL)('"Moxie"')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(JS:RBRACKET)(']')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
PsiElement(JS:RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
PsiElement(JS:RBRACKET)(']')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PsiElement(JS:RBRACE)('}')
|
||||||
3
json/tests/testData/psi/Real2.json
Normal file
3
json/tests/testData/psi/Real2.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
/*xxx*/ navigation: "111" // yyy
|
||||||
|
}
|
||||||
16
json/tests/testData/psi/Real2.txt
Normal file
16
json/tests/testData/psi/Real2.txt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
JSFile:Real2.json
|
||||||
|
JSObjectLiteralExpression
|
||||||
|
PsiElement(JS:LBRACE)('{')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
PsiComment(JS:C_STYLE_COMMENT)('/*xxx*/')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JSProperty
|
||||||
|
PsiElement(JS:IDENTIFIER)('navigation')
|
||||||
|
PsiElement(JS:COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JSLiteralExpression
|
||||||
|
PsiElement(JS:STRING_LITERAL)('"111"')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiComment(JS:END_OF_LINE_COMMENT)('// yyy')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PsiElement(JS:RBRACE)('}')
|
||||||
1
json/tests/testData/psi/Simple1.json
Normal file
1
json/tests/testData/psi/Simple1.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{ "x": "x value", "y": "y value", "z": "z value", "z2":[] }
|
||||||
40
json/tests/testData/psi/Simple1.txt
Normal file
40
json/tests/testData/psi/Simple1.txt
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
FILE
|
||||||
|
JsonObject
|
||||||
|
PsiElement({)('{')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonProperty
|
||||||
|
JsonPropertyName
|
||||||
|
PsiElement(STRING)('"x"')
|
||||||
|
PsiElement(:)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonStringLiteral
|
||||||
|
PsiElement(STRING)('"x value"')
|
||||||
|
PsiElement(,)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonProperty
|
||||||
|
JsonPropertyName
|
||||||
|
PsiElement(STRING)('"y"')
|
||||||
|
PsiElement(:)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonStringLiteral
|
||||||
|
PsiElement(STRING)('"y value"')
|
||||||
|
PsiElement(,)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonProperty
|
||||||
|
JsonPropertyName
|
||||||
|
PsiElement(STRING)('"z"')
|
||||||
|
PsiElement(:)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonStringLiteral
|
||||||
|
PsiElement(STRING)('"z value"')
|
||||||
|
PsiElement(,)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonProperty
|
||||||
|
JsonPropertyName
|
||||||
|
PsiElement(STRING)('"z2"')
|
||||||
|
PsiElement(:)(':')
|
||||||
|
JsonArray
|
||||||
|
PsiElement([)('[')
|
||||||
|
PsiElement(])(']')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(})('}')
|
||||||
1
json/tests/testData/psi/Simple2.json
Normal file
1
json/tests/testData/psi/Simple2.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[ "x", 555, null, true, false, "z value", "z2",[] ],
|
||||||
38
json/tests/testData/psi/Simple2.txt
Normal file
38
json/tests/testData/psi/Simple2.txt
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
FILE
|
||||||
|
JsonArray
|
||||||
|
PsiElement([)('[')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonStringLiteral
|
||||||
|
PsiElement(STRING)('"x"')
|
||||||
|
PsiElement(,)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonNumberLiteral
|
||||||
|
PsiElement(NUMBER)('555')
|
||||||
|
PsiElement(,)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonNullLiteral
|
||||||
|
PsiElement(null)('null')
|
||||||
|
PsiElement(,)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonBooleanLiteral
|
||||||
|
PsiElement(true)('true')
|
||||||
|
PsiElement(,)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonBooleanLiteral
|
||||||
|
PsiElement(false)('false')
|
||||||
|
PsiElement(,)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonStringLiteral
|
||||||
|
PsiElement(STRING)('"z value"')
|
||||||
|
PsiElement(,)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
JsonStringLiteral
|
||||||
|
PsiElement(STRING)('"z2"')
|
||||||
|
PsiElement(,)(',')
|
||||||
|
JsonArray
|
||||||
|
PsiElement([)('[')
|
||||||
|
PsiElement(])(']')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(])(']')
|
||||||
|
PsiErrorElement:',' unexpected
|
||||||
|
PsiElement(,)(',')
|
||||||
1
json/tests/testData/psi/Simple3.json
Normal file
1
json/tests/testData/psi/Simple3.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
[ ++x, "x value", y + "y value", z, "z value", z2,[ a = b], {z=c} ]
|
||||||
45
json/tests/testData/psi/Simple3.txt
Normal file
45
json/tests/testData/psi/Simple3.txt
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
JSFile:Simple3.json
|
||||||
|
JSArrayLiteralExpression
|
||||||
|
PsiElement(JS:LBRACKET)('[')
|
||||||
|
PsiErrorElement:expression expected
|
||||||
|
<empty list>
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(BAD_CHARACTER)('++')
|
||||||
|
PsiElement(JS:IDENTIFIER)('x')
|
||||||
|
PsiElement(JS:COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(JS:STRING_LITERAL)('"x value"')
|
||||||
|
PsiElement(JS:COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(JS:IDENTIFIER)('y')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(BAD_CHARACTER)('+')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(JS:STRING_LITERAL)('"y value"')
|
||||||
|
PsiElement(JS:COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(JS:IDENTIFIER)('z')
|
||||||
|
PsiElement(JS:COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(JS:STRING_LITERAL)('"z value"')
|
||||||
|
PsiElement(JS:COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(JS:IDENTIFIER)('z2')
|
||||||
|
PsiElement(JS:COMMA)(',')
|
||||||
|
PsiElement(JS:LBRACKET)('[')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(JS:IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(BAD_CHARACTER)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(JS:IDENTIFIER)('b')
|
||||||
|
PsiElement(JS:RBRACKET)(']')
|
||||||
|
PsiElement(JS:COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(JS:LBRACE)('{')
|
||||||
|
PsiElement(JS:IDENTIFIER)('z')
|
||||||
|
PsiElement(BAD_CHARACTER)('=')
|
||||||
|
PsiElement(JS:IDENTIFIER)('c')
|
||||||
|
PsiElement(JS:RBRACE)('}')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(JS:RBRACKET)(']')
|
||||||
1
json/tests/testData/psi/Simple4.json
Normal file
1
json/tests/testData/psi/Simple4.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
true
|
||||||
3
json/tests/testData/psi/Simple4.txt
Normal file
3
json/tests/testData/psi/Simple4.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
FILE
|
||||||
|
PsiErrorElement:'[' or '{' expected, got 'true'
|
||||||
|
PsiElement(true)('true')
|
||||||
Reference in New Issue
Block a user