From 6153f6636ed5d7e24f7474d28ee7577194617039 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Thu, 21 Aug 2014 15:08:27 +0400 Subject: [PATCH] Move some of the old JSON parsing tests to new plugin --- json/tests/json-tests.iml | 1 + .../com/intellij/json/JsonCompletionTest.java | 18 +------- .../com/intellij/json/JsonFormattingTest.java | 6 +-- .../com/intellij/json/JsonParsingTest.java | 25 +++++++++++ .../test/com/intellij/json/JsonTestCase.java | 24 ++++++++++ json/tests/testData/psi/Real1.json | 8 ++++ json/tests/testData/psi/Real1.txt | 43 ++++++++++++++++++ json/tests/testData/psi/Real2.json | 3 ++ json/tests/testData/psi/Real2.txt | 16 +++++++ json/tests/testData/psi/Simple1.json | 1 + json/tests/testData/psi/Simple1.txt | 40 +++++++++++++++++ json/tests/testData/psi/Simple2.json | 1 + json/tests/testData/psi/Simple2.txt | 38 ++++++++++++++++ json/tests/testData/psi/Simple3.json | 1 + json/tests/testData/psi/Simple3.txt | 45 +++++++++++++++++++ json/tests/testData/psi/Simple4.json | 1 + json/tests/testData/psi/Simple4.txt | 3 ++ 17 files changed, 254 insertions(+), 20 deletions(-) create mode 100644 json/tests/test/com/intellij/json/JsonTestCase.java create mode 100644 json/tests/testData/psi/Real1.json create mode 100644 json/tests/testData/psi/Real1.txt create mode 100644 json/tests/testData/psi/Real2.json create mode 100644 json/tests/testData/psi/Real2.txt create mode 100644 json/tests/testData/psi/Simple1.json create mode 100644 json/tests/testData/psi/Simple1.txt create mode 100644 json/tests/testData/psi/Simple2.json create mode 100644 json/tests/testData/psi/Simple2.txt create mode 100644 json/tests/testData/psi/Simple3.json create mode 100644 json/tests/testData/psi/Simple3.txt create mode 100644 json/tests/testData/psi/Simple4.json create mode 100644 json/tests/testData/psi/Simple4.txt diff --git a/json/tests/json-tests.iml b/json/tests/json-tests.iml index b399fc32f657..3edce1f127c9 100644 --- a/json/tests/json-tests.iml +++ b/json/tests/json-tests.iml @@ -4,6 +4,7 @@ + diff --git a/json/tests/test/com/intellij/json/JsonCompletionTest.java b/json/tests/test/com/intellij/json/JsonCompletionTest.java index 1f9727593ce7..efde53dcbcfe 100644 --- a/json/tests/test/com/intellij/json/JsonCompletionTest.java +++ b/json/tests/test/com/intellij/json/JsonCompletionTest.java @@ -1,28 +1,14 @@ package com.intellij.json; -import com.intellij.testFramework.IdeaTestCase; -import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase; import com.intellij.util.ArrayUtil; /** * @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[] 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 protected boolean isCommunity() { return true; @@ -49,6 +35,6 @@ public class JsonCompletionTest extends CodeInsightFixtureTestCase { } private void doTest(String... variants) { - myFixture.testCompletionVariants(getTestName(false) + ".json", variants); + myFixture.testCompletionVariants("completion/" + getTestName(false) + ".json", variants); } } diff --git a/json/tests/test/com/intellij/json/JsonFormattingTest.java b/json/tests/test/com/intellij/json/JsonFormattingTest.java index 3f3be60c551b..28703b7da7a1 100644 --- a/json/tests/test/com/intellij/json/JsonFormattingTest.java +++ b/json/tests/test/com/intellij/json/JsonFormattingTest.java @@ -2,6 +2,7 @@ package com.intellij.json; import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.codeStyle.CodeStyleSettings; +import com.intellij.psi.codeStyle.CommonCodeStyleSettings; import com.intellij.psi.formatter.FormatterTestCase; import com.intellij.testFramework.IdeaTestCase; import com.intellij.testFramework.PlatformTestUtil; @@ -23,7 +24,6 @@ public class JsonFormattingTest extends FormatterTestCase { return "formatting"; } - // Why the heck do I specify path to testData in each kind of test differently? @Override protected String getTestDataPath() { return PlatformTestUtil.getCommunityPath() + "/json/tests/testData/"; @@ -48,9 +48,7 @@ public class JsonFormattingTest extends FormatterTestCase { public void testWrapping() throws Exception { CodeStyleSettings settings = getSettings(); - int indentSize = settings.getCommonSettings(JsonLanguage.INSTANCE).getIndentOptions().INDENT_SIZE; -// LOG.debug("Intend size for JSON: " + indentSize); - settings.RIGHT_MARGIN = 20; + settings.setRightMargin(JsonLanguage.INSTANCE, 20); doTest(); } diff --git a/json/tests/test/com/intellij/json/JsonParsingTest.java b/json/tests/test/com/intellij/json/JsonParsingTest.java index 6c921c075de2..74eab90632fe 100644 --- a/json/tests/test/com/intellij/json/JsonParsingTest.java +++ b/json/tests/test/com/intellij/json/JsonParsingTest.java @@ -27,6 +27,31 @@ public class JsonParsingTest extends ParsingTestCase { 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() { doTest(true); } diff --git a/json/tests/test/com/intellij/json/JsonTestCase.java b/json/tests/test/com/intellij/json/JsonTestCase.java new file mode 100644 index 000000000000..7807504a2d05 --- /dev/null +++ b/json/tests/test/com/intellij/json/JsonTestCase.java @@ -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"; + } +} \ No newline at end of file diff --git a/json/tests/testData/psi/Real1.json b/json/tests/testData/psi/Real1.json new file mode 100644 index 000000000000..b8926d999ca4 --- /dev/null +++ b/json/tests/testData/psi/Real1.json @@ -0,0 +1,8 @@ +{ + navigation: [ + { + name: "Demo Applications", + demos: [ "Mail", "Moxie" ] + } + ] +} diff --git a/json/tests/testData/psi/Real1.txt b/json/tests/testData/psi/Real1.txt new file mode 100644 index 000000000000..70cfc8d56be1 --- /dev/null +++ b/json/tests/testData/psi/Real1.txt @@ -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)('}') \ No newline at end of file diff --git a/json/tests/testData/psi/Real2.json b/json/tests/testData/psi/Real2.json new file mode 100644 index 000000000000..99d381bb2612 --- /dev/null +++ b/json/tests/testData/psi/Real2.json @@ -0,0 +1,3 @@ +{ + /*xxx*/ navigation: "111" // yyy +} diff --git a/json/tests/testData/psi/Real2.txt b/json/tests/testData/psi/Real2.txt new file mode 100644 index 000000000000..063c058e6368 --- /dev/null +++ b/json/tests/testData/psi/Real2.txt @@ -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)('}') \ No newline at end of file diff --git a/json/tests/testData/psi/Simple1.json b/json/tests/testData/psi/Simple1.json new file mode 100644 index 000000000000..70afdeb1aa0c --- /dev/null +++ b/json/tests/testData/psi/Simple1.json @@ -0,0 +1 @@ +{ "x": "x value", "y": "y value", "z": "z value", "z2":[] } \ No newline at end of file diff --git a/json/tests/testData/psi/Simple1.txt b/json/tests/testData/psi/Simple1.txt new file mode 100644 index 000000000000..7c975121daac --- /dev/null +++ b/json/tests/testData/psi/Simple1.txt @@ -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(})('}') \ No newline at end of file diff --git a/json/tests/testData/psi/Simple2.json b/json/tests/testData/psi/Simple2.json new file mode 100644 index 000000000000..b78f7d6c255c --- /dev/null +++ b/json/tests/testData/psi/Simple2.json @@ -0,0 +1 @@ +[ "x", 555, null, true, false, "z value", "z2",[] ], \ No newline at end of file diff --git a/json/tests/testData/psi/Simple2.txt b/json/tests/testData/psi/Simple2.txt new file mode 100644 index 000000000000..ad46c1c9f6d3 --- /dev/null +++ b/json/tests/testData/psi/Simple2.txt @@ -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(,)(',') \ No newline at end of file diff --git a/json/tests/testData/psi/Simple3.json b/json/tests/testData/psi/Simple3.json new file mode 100644 index 000000000000..41ed9553df48 --- /dev/null +++ b/json/tests/testData/psi/Simple3.json @@ -0,0 +1 @@ +[ ++x, "x value", y + "y value", z, "z value", z2,[ a = b], {z=c} ] \ No newline at end of file diff --git a/json/tests/testData/psi/Simple3.txt b/json/tests/testData/psi/Simple3.txt new file mode 100644 index 000000000000..998f99e78233 --- /dev/null +++ b/json/tests/testData/psi/Simple3.txt @@ -0,0 +1,45 @@ +JSFile:Simple3.json + JSArrayLiteralExpression + PsiElement(JS:LBRACKET)('[') + PsiErrorElement:expression expected + + 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)(']') \ No newline at end of file diff --git a/json/tests/testData/psi/Simple4.json b/json/tests/testData/psi/Simple4.json new file mode 100644 index 000000000000..f32a5804e292 --- /dev/null +++ b/json/tests/testData/psi/Simple4.json @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/json/tests/testData/psi/Simple4.txt b/json/tests/testData/psi/Simple4.txt new file mode 100644 index 000000000000..7b2963ed54a0 --- /dev/null +++ b/json/tests/testData/psi/Simple4.txt @@ -0,0 +1,3 @@ +FILE + PsiErrorElement:'[' or '{' expected, got 'true' + PsiElement(true)('true') \ No newline at end of file