diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2013-01-08 11:11:20 -0800 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2013-01-08 11:11:20 -0800 |
commit | b56ea2a18f232d79481e778085fd64e8ae486fc3 (patch) | |
tree | 44e1f6eb4864a45033f865b74fe783e3d784dd6a /plugins/properties/testSrc | |
download | idea-b56ea2a18f232d79481e778085fd64e8ae486fc3.tar.gz |
Snapshot of commit d5ec1d5018ed24f1b4f32b1d09df6dbd7e2fc425
from branch master of git://git.jetbrains.org/idea/community.git
Diffstat (limited to 'plugins/properties/testSrc')
10 files changed, 821 insertions, 0 deletions
diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesCommenterTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesCommenterTest.java new file mode 100644 index 000000000000..d49575cfebc7 --- /dev/null +++ b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesCommenterTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2009 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 com.intellij.lang.properties; + +import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction; +import com.intellij.ide.DataManager; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.PluginPathManager; +import com.intellij.testFramework.LightPlatformCodeInsightTestCase; +import com.intellij.testFramework.PlatformTestCase; +import org.jetbrains.annotations.NotNull; + +/** + * @author cdr + */ +public class PropertiesCommenterTest extends LightPlatformCodeInsightTestCase { + public void testProp1() throws Exception { doTest(); } + public void testUncomment() throws Exception { doTest(); } + + public PropertiesCommenterTest() { + PlatformTestCase.initPlatformLangPrefix(); + } + + @NotNull + @Override + protected String getTestDataPath() { + return PluginPathManager.getPluginHomePath("properties") + "/testData"; + } + + private void doTest() throws Exception { + configureByFile("/propertiesFile/comment/before" + getTestName(false)+".properties"); + performAction(); + checkResultByFile("/propertiesFile/comment/after" + getTestName(false)+".properties"); + } + + private static void performAction() { + CommentByLineCommentAction action = new CommentByLineCommentAction(); + action.actionPerformed(new AnActionEvent( + null, + DataManager.getInstance().getDataContext(), + "", + action.getTemplatePresentation(), + ActionManager.getInstance(), + 0) + ); + } +} diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesEnterTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesEnterTest.java new file mode 100644 index 000000000000..daa5b42c6863 --- /dev/null +++ b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesEnterTest.java @@ -0,0 +1,62 @@ +/* + * Copyright 2000-2009 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 com.intellij.lang.properties; + +import com.intellij.ide.DataManager; +import com.intellij.openapi.actionSystem.IdeActions; +import com.intellij.openapi.editor.actionSystem.EditorActionHandler; +import com.intellij.openapi.editor.actionSystem.EditorActionManager; +import com.intellij.openapi.application.PluginPathManager; +import com.intellij.testFramework.LightPlatformCodeInsightTestCase; +import com.intellij.testFramework.PlatformTestCase; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +/** + * @author cdr + */ +public class PropertiesEnterTest extends LightPlatformCodeInsightTestCase { + @NonNls private static final String BASE_PATH = "/propertiesFile/enter/"; + + public PropertiesEnterTest() { + PlatformTestCase.initPlatformLangPrefix(); + } + + @NotNull + @Override + protected String getTestDataPath() { + return PluginPathManager.getPluginHomePath("properties") + "/testData"; + } + + private static void typeEnter() { + EditorActionManager actionManager = EditorActionManager.getInstance(); + EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER); + actionHandler.execute(getEditor(), DataManager.getInstance().getDataContext()); + } + + public void testEndLine() throws Exception { doTest(); } + public void testComment() throws Exception { doTest(); } + public void testKey() throws Exception { doTest(); } + public void testValue() throws Exception { doTest(); } + public void testBackslash() throws Exception { doTest(); } + public void testBeforeComment() throws Exception { doTest(); } + + private void doTest() throws Exception { + configureByFile(BASE_PATH + getTestName(false)+".properties"); + typeEnter(); + checkResultByFile(BASE_PATH + getTestName(false)+"_after.properties"); + } +} diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFileTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFileTest.java new file mode 100644 index 000000000000..89af66ae0be8 --- /dev/null +++ b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFileTest.java @@ -0,0 +1,186 @@ +/* + * Copyright 2000-2009 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 com.intellij.lang.properties; + +import com.intellij.lang.properties.psi.PropertiesElementFactory; +import com.intellij.lang.properties.psi.PropertiesFile; +import com.intellij.lang.properties.psi.Property; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.testFramework.LightPlatformTestCase; +import com.intellij.testFramework.PlatformTestCase; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NonNls; + +import java.util.List; + +/** + * @author max + */ +public class PropertiesFileTest extends LightPlatformTestCase { + private Property myPropertyToAdd; + + public PropertiesFileTest() { + PlatformTestCase.initPlatformLangPrefix(); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + myPropertyToAdd = (Property)PropertiesElementFactory.createProperty(getProject(), "kkk", "vvv"); + } + + public void testAddPropertyAfterComment() throws Exception { + final PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "#xxxxx"); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + propertiesFile.addProperty(myPropertyToAdd); + } + }); + + + List<IProperty> properties = propertiesFile.getProperties(); + IProperty added = properties.get(0); + assertPropertyEquals(added, myPropertyToAdd.getName(), myPropertyToAdd.getValue()); + } + + private static void assertPropertyEquals(final IProperty property, @NonNls String name, @NonNls String value) { + assertEquals(name, property.getName()); + assertEquals(value, property.getValue()); + } + + public void testAddPropertyAfterProperty() throws Exception { + final PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "xxx=yyy"); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + propertiesFile.addProperty(myPropertyToAdd); + } + }); + + + List<IProperty> properties = propertiesFile.getProperties(); + assertEquals(2, properties.size()); + assertPropertyEquals(properties.get(0), "xxx", "yyy"); + assertPropertyEquals(properties.get(1), myPropertyToAdd.getName(), myPropertyToAdd.getValue()); + } + public void testDeleteProperty() throws Exception { + PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "xxx=yyy\n#s\nzzz=ttt\n\n"); + + final List<IProperty> properties = propertiesFile.getProperties(); + assertEquals(2, properties.size()); + assertPropertyEquals(properties.get(0), "xxx", "yyy"); + assertPropertyEquals(properties.get(1), "zzz", "ttt"); + + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + properties.get(1).getPsiElement().delete(); + } + }); + + List<IProperty> propertiesAfter = propertiesFile.getProperties(); + assertEquals(1, propertiesAfter.size()); + assertPropertyEquals(propertiesAfter.get(0), "xxx", "yyy"); + } + + public void testDeletePropertyWhitespaceAround() throws Exception { + PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "xxx=yyy\nxxx2=tyrt\nxxx3=ttt\n\n"); + + final Property property = (Property)propertiesFile.findPropertyByKey("xxx2"); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + property.delete(); + } + }); + + + assertEquals("xxx=yyy\nxxx3=ttt\n\n", propertiesFile.getContainingFile().getText()); + } + public void testDeletePropertyWhitespaceAhead() throws Exception { + PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "xxx=yyy\nxxx2=tyrt\nxxx3=ttt\n\n"); + + final Property property = (Property)propertiesFile.findPropertyByKey("xxx"); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + property.delete(); + } + }); + + + assertEquals("xxx2=tyrt\nxxx3=ttt\n\n", propertiesFile.getText()); + } + + public void testAddToEnd() throws IncorrectOperationException { + final PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "a=b\\nccc"); + assertEquals(1,propertiesFile.getProperties().size()); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + propertiesFile.addProperty(myPropertyToAdd); + } + }); + + assertEquals("a=b\\nccc\nkkk=vvv", propertiesFile.getText()); + } + + public void testUnescapedValue() { + PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "a=b\\nc\\u0063c"); + assertEquals("b\nccc", propertiesFile.getProperties().get(0).getUnescapedValue()); + } + + public void testUnescapedLineBreak() { + PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "a=b\\\n\t c"); + assertEquals("bc", propertiesFile.getProperties().get(0).getUnescapedValue()); + } + + public void testAddPropertyAfter() throws IncorrectOperationException { + final PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "a=b\nc=d\ne=f"); + final Property c = (Property)propertiesFile.findPropertyByKey("c"); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + propertiesFile.addPropertyAfter(myPropertyToAdd, c); + } + }); + + assertEquals("a=b\nc=d\nkkk=vvv\ne=f", propertiesFile.getText()); + } + public void testAddPropertyAfterLast() throws IncorrectOperationException { + final PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "a=b\nc=d\ne=f"); + final Property p = (Property)propertiesFile.findPropertyByKey("e"); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + propertiesFile.addPropertyAfter(myPropertyToAdd, p); + } + }); + + assertEquals("a=b\nc=d\ne=f\nkkk=vvv", propertiesFile.getText()); + } + public void testAddPropertyAfterInBeginning() throws IncorrectOperationException { + final PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "a=b\nc=d\ne=f"); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + propertiesFile.addPropertyAfter(myPropertyToAdd, null); + } + }); + + assertEquals("kkk=vvv\na=b\nc=d\ne=f", propertiesFile.getText()); + } + public void testUnescapedKey() throws IncorrectOperationException { + PropertiesFile propertiesFile = PropertiesElementFactory.createPropertiesFile(getProject(), "a\\:b=xxx\nc\\ d=xxx\n\\ e\\=f=xxx\n\\u1234\\uxyzt=xxxx"); + List<IProperty> properties = propertiesFile.getProperties(); + assertEquals("a:b", properties.get(0).getUnescapedKey()); + assertEquals("c d", properties.get(1).getUnescapedKey()); + assertEquals(" e=f", properties.get(2).getUnescapedKey()); + assertEquals("\u1234\\uxyzt", properties.get(3).getUnescapedKey()); + } +} diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFoldingTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFoldingTest.java new file mode 100644 index 000000000000..a1c74a93865f --- /dev/null +++ b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesFoldingTest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2000-2012 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 com.intellij.lang.properties; + +import com.intellij.openapi.application.PluginPathManager; +import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; + +/** + * @author Rustam Vishnyakov + */ +public class PropertiesFoldingTest extends LightPlatformCodeInsightFixtureTestCase { + + @Override + protected String getTestDataPath() { + return PluginPathManager.getPluginHomePath("properties") + "/testData/propertiesFile/folding/"; + } + + private void doTest() { + myFixture.testFolding(getTestDataPath() + getTestName(true) + ".test.properties"); + } + + public void testCustomFolding() throws Exception { + doTest(); + } + + @Override + protected boolean isCommunity() { + return true; + } +} diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesLexerTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesLexerTest.java new file mode 100644 index 000000000000..4fd61f0b46cf --- /dev/null +++ b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesLexerTest.java @@ -0,0 +1,225 @@ +/* + * Copyright 2000-2009 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 com.intellij.lang.properties; + +import com.intellij.lang.properties.parsing.PropertiesLexer; +import com.intellij.lexer.Lexer; +import com.intellij.testFramework.LightPlatformTestCase; +import com.intellij.testFramework.PlatformTestCase; +import org.jetbrains.annotations.NonNls; + +/** + * @author max + */ +public class PropertiesLexerTest extends LightPlatformTestCase { + + public PropertiesLexerTest() { + PlatformTestCase.initPlatformLangPrefix(); + } + + private static void doTest(@NonNls String text, @NonNls String[] expectedTokens) { + Lexer lexer = new PropertiesLexer(); + doTest(text, expectedTokens, lexer); + } + + private static void doTestHL(@NonNls String text, @NonNls String[] expectedTokens) { + Lexer lexer = new PropertiesHighlightingLexer(); + doTest(text, expectedTokens, lexer); + } + + private static void doTest(String text, String[] expectedTokens,Lexer lexer) { + lexer.start(text); + int idx = 0; + while (lexer.getTokenType() != null) { + if (idx >= expectedTokens.length) fail("Too many tokens"); + String tokenName = lexer.getTokenType().toString(); + String expectedTokenType = expectedTokens[idx++]; + String expectedTokenText = expectedTokens[idx++]; + assertEquals(expectedTokenType, tokenName); + String tokenText = lexer.getBufferSequence().subSequence(lexer.getTokenStart(), lexer.getTokenEnd()).toString(); + assertEquals(expectedTokenText, tokenText); + lexer.advance(); + } + + if (idx < expectedTokens.length) fail("Not enough tokens"); + } + + public void testSimple() throws Exception { + doTest("xxx=yyy", new String[]{ + "Properties:KEY_CHARACTERS", "xxx", + "Properties:KEY_VALUE_SEPARATOR", "=", + "Properties:VALUE_CHARACTERS", "yyy", + }); + } + + public void testTwoWords() throws Exception { + doTest("xxx=yyy zzz", new String[]{ + "Properties:KEY_CHARACTERS", "xxx", + "Properties:KEY_VALUE_SEPARATOR", "=", + "Properties:VALUE_CHARACTERS", "yyy zzz", + }); + } + + public void testMulti() throws Exception { + doTest("a b\n \nx\ty", new String[]{ + "Properties:KEY_CHARACTERS", "a", + "Properties:KEY_VALUE_SEPARATOR", " ", + "Properties:VALUE_CHARACTERS", "b", + "WHITE_SPACE", "\n \n", + "Properties:KEY_CHARACTERS", "x", + "Properties:KEY_VALUE_SEPARATOR", "\t", + "Properties:VALUE_CHARACTERS", "y" + }); + } + + public void testIncompleteProperty() throws Exception { + doTest("a", new String[]{ + "Properties:KEY_CHARACTERS", "a" + }); + } + + public void testIncompleteProperty2() throws Exception { + doTest("a.2=", new String[]{ + "Properties:KEY_CHARACTERS", "a.2", + "Properties:KEY_VALUE_SEPARATOR", "=" + }); + } + + public void testEscaping() throws Exception { + doTest("sdlfkjsd\\l\\\\\\:\\=gk = s\\nsssd", new String[]{ + "Properties:KEY_CHARACTERS", "sdlfkjsd\\l\\\\\\:\\=gk", + "Properties:KEY_VALUE_SEPARATOR", " = ", + "Properties:VALUE_CHARACTERS", "s\\nsssd" + }); + } + + public void testCRLFEscaping() throws Exception { + doTest("sdlfkjsdsssd:a\\\nb", new String[]{ + "Properties:KEY_CHARACTERS", "sdlfkjsdsssd", + "Properties:KEY_VALUE_SEPARATOR", ":", + "Properties:VALUE_CHARACTERS", "a\\\nb" + }); + } + + public void testCRLFEscapingKey() throws Exception { + doTest("x\\\ny:z", new String[]{ + "Properties:KEY_CHARACTERS", "x\\\ny", + "Properties:KEY_VALUE_SEPARATOR", ":", + "Properties:VALUE_CHARACTERS", "z" + }); + } + + public void testWhitespace() throws Exception { + doTest("x y", new String[]{ + "Properties:KEY_CHARACTERS", "x", + "Properties:KEY_VALUE_SEPARATOR", " ", + "Properties:VALUE_CHARACTERS", "y" + }); + } + public void testHashInValue() throws Exception { + doTest("x=# y", new String[]{ + "Properties:KEY_CHARACTERS", "x", + "Properties:KEY_VALUE_SEPARATOR", "=", + "Properties:VALUE_CHARACTERS", "# y" + }); + } + public void testComments() throws Exception { + doTest("#hhhh kkkk \n\n", new String[]{ + "Properties:END_OF_LINE_COMMENT", "#hhhh kkkk ", + "WHITE_SPACE", "\n\n", + }); + } + public void testTabs() throws Exception { + doTest("install/htdocs/imcms/html/link_editor.jsp/1002 = URL\\n\\\n" + + "\t\\t\\teller meta_id:", new String[]{ + "Properties:KEY_CHARACTERS", "install/htdocs/imcms/html/link_editor.jsp/1002", + "Properties:KEY_VALUE_SEPARATOR", " = ", + "Properties:VALUE_CHARACTERS", "URL\\n\\\n" + "\t\\t\\teller meta_id:" + }); + } + public void testIndentedComments() throws Exception { + doTest(" #comm1\n#comm2=n\n\t#comm3", new String[]{ + "WHITE_SPACE", " ", + "Properties:END_OF_LINE_COMMENT", "#comm1", + "WHITE_SPACE", "\n", + "Properties:END_OF_LINE_COMMENT", "#comm2=n", + "WHITE_SPACE", "\n\t", + "Properties:END_OF_LINE_COMMENT", "#comm3", + }); + } + + public void testHighlighting() throws Exception { + doTestHL("x y", new String[]{ + "Properties:KEY_CHARACTERS", "x", + "Properties:KEY_VALUE_SEPARATOR", " ", + "Properties:VALUE_CHARACTERS", "y" + }); + } + + public void testHighlighting2() throws Exception { + doTestHL("x\\n\\kz y", new String[]{ + "Properties:KEY_CHARACTERS", "x", + "VALID_STRING_ESCAPE_TOKEN", "\\n", + "INVALID_CHARACTER_ESCAPE_TOKEN", "\\k", + "Properties:KEY_CHARACTERS", "z", + "Properties:KEY_VALUE_SEPARATOR", " ", + "Properties:VALUE_CHARACTERS", "y" + }); + } + + public void testHighlighting3() throws Exception { + doTestHL("x \\uxyzt\\pz\\tp", new String[]{ + "Properties:KEY_CHARACTERS", "x", + "Properties:KEY_VALUE_SEPARATOR", " ", + "INVALID_UNICODE_ESCAPE_TOKEN", "\\uxyzt", + "INVALID_CHARACTER_ESCAPE_TOKEN", "\\p", + "Properties:VALUE_CHARACTERS", "z", + "VALID_STRING_ESCAPE_TOKEN", "\\t", + "Properties:VALUE_CHARACTERS", "p", + }); + } + public void testFramingSpaces() throws Exception { + doTestHL("\\ x\\ y\\ =\\ z\\ t\\ \\ ", new String[]{ + "VALID_STRING_ESCAPE_TOKEN", "\\ ", + "Properties:KEY_CHARACTERS", "x", + "VALID_STRING_ESCAPE_TOKEN", "\\ ", + "Properties:KEY_CHARACTERS", "y", + "VALID_STRING_ESCAPE_TOKEN", "\\ ", + "Properties:KEY_VALUE_SEPARATOR", "=", + "VALID_STRING_ESCAPE_TOKEN", "\\ ", + "Properties:VALUE_CHARACTERS", "z", + "INVALID_CHARACTER_ESCAPE_TOKEN", "\\ ", + "Properties:VALUE_CHARACTERS", "t", + "VALID_STRING_ESCAPE_TOKEN", "\\ ", + "VALID_STRING_ESCAPE_TOKEN", "\\ ", + }); + } + public void testSpecialCharsInValue() throws Exception { + doTestHL("xxx=\\ x\\ y\\!\\=\\#\\:", new String[]{ + "Properties:KEY_CHARACTERS", "xxx", + "Properties:KEY_VALUE_SEPARATOR", "=", + "VALID_STRING_ESCAPE_TOKEN", "\\ ", + "Properties:VALUE_CHARACTERS", "x", + "INVALID_CHARACTER_ESCAPE_TOKEN", "\\ ", + "Properties:VALUE_CHARACTERS", "y", + "VALID_STRING_ESCAPE_TOKEN", "\\!", + "VALID_STRING_ESCAPE_TOKEN", "\\=", + "VALID_STRING_ESCAPE_TOKEN", "\\#", + "VALID_STRING_ESCAPE_TOKEN", "\\:", + }); + } + +} diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesParsingTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesParsingTest.java new file mode 100644 index 000000000000..ec8ced434e32 --- /dev/null +++ b/plugins/properties/testSrc/com/intellij/lang/properties/PropertiesParsingTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2000-2009 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 com.intellij.lang.properties; + +import com.intellij.lang.LanguageASTFactory; +import com.intellij.lang.properties.parsing.PropertiesParserDefinition; +import com.intellij.lang.properties.psi.impl.PropertiesASTFactory; +import com.intellij.openapi.application.PluginPathManager; +import com.intellij.testFramework.ParsingTestCase; +import com.intellij.testFramework.PlatformTestCase; + +/** + * @author max + */ +public class PropertiesParsingTest extends ParsingTestCase { + + public PropertiesParsingTest() { + super("", "properties", new PropertiesParserDefinition()); + PlatformTestCase.initPlatformLangPrefix(); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + addExplicitExtension(LanguageASTFactory.INSTANCE, PropertiesLanguage.INSTANCE, new PropertiesASTFactory()); + } + + @Override + protected String getTestDataPath() { + return PluginPathManager.getPluginHomePath("properties") + "/testData/propertiesFile/psi"; + } + + public void testProp1() throws Exception { doTest(true); } + public void testComments() throws Exception { doTest(true); } +} diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/TrailingSpacesInPropertyInspectionTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/TrailingSpacesInPropertyInspectionTest.java new file mode 100644 index 000000000000..19dc8911a117 --- /dev/null +++ b/plugins/properties/testSrc/com/intellij/lang/properties/TrailingSpacesInPropertyInspectionTest.java @@ -0,0 +1,42 @@ +package com.intellij.lang.properties; + +import com.intellij.openapi.application.PluginPathManager; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.testFramework.PlatformTestCase; +import com.intellij.testFramework.UsefulTestCase; +import com.intellij.testFramework.fixtures.CodeInsightTestFixture; +import com.intellij.testFramework.fixtures.IdeaProjectTestFixture; +import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory; +import com.intellij.testFramework.fixtures.TestFixtureBuilder; + +public class TrailingSpacesInPropertyInspectionTest extends UsefulTestCase { + private CodeInsightTestFixture myFixture; + + public TrailingSpacesInPropertyInspectionTest() { + PlatformTestCase.initPlatformLangPrefix(); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + final TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createLightFixtureBuilder(); + + myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture()); + myFixture.setTestDataPath(PluginPathManager.getPluginHomePath("properties") + "/testData"); + myFixture.setUp(); + } + + @Override + protected void tearDown() throws Exception { + myFixture.tearDown(); + myFixture = null; + super.tearDown(); + } + + public void testSimple() throws Exception{ + myFixture.enableInspections(new TrailingSpacesInPropertyInspection()); + VirtualFile file = myFixture.copyFileToProject("/propertiesFile/highlighting/trailingSpaces.properties"); + myFixture.configureFromExistingVirtualFile(file); + myFixture.checkHighlighting(true, false, true); + } +}
\ No newline at end of file diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/editor/ResourceBundleUtilTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/editor/ResourceBundleUtilTest.java new file mode 100644 index 000000000000..ec0c65efd02e --- /dev/null +++ b/plugins/properties/testSrc/com/intellij/lang/properties/editor/ResourceBundleUtilTest.java @@ -0,0 +1,58 @@ +package com.intellij.lang.properties.editor; + +import gnu.trove.TIntHashSet; +import org.jetbrains.annotations.NotNull; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * @author Denis Zhdanov + * @since 10/5/11 2:37 PM + */ +public class ResourceBundleUtilTest { + + /** + * Holds pairs like <code>('property value'; 'value editor text')</code>. + */ + private static final String[][] TEST_DATA = { + // Common. + { "", "" }, + { "as-is", "as-is" }, + { "with escaped escape symbol - \\\\", "with escaped escape symbol - \\" }, + + // Special symbols. + { "special symbols - \\# and \\! and \\= and \\:", "special symbols - # and ! and = and :" }, + + // White spaces. + { "trailing white space ", "trailing white space " }, + { "trailing white spaces ", "trailing white spaces " }, + { "trailing tab\t", "trailing tab\t" }, + { "trailing tabs\t\t\t", "trailing tabs\t\t\t" }, + { "\\\tstarting from tab", "\tstarting from tab" }, + { "\\\t\t\tstarting from tabs", "\t\t\tstarting from tabs" }, + { "\\ starting from white space", " starting from white space" }, + { "\\ starting from white spaces", " starting from white spaces" }, + { "\\ \t starting from white spaces and tabs", " \t starting from white spaces and tabs" }, + { "first line \\\nsecond line", "first line \nsecond line" }, + + // All together. + { "\\\t text with \\\nspecial symbols\\:\\\n\\#", "\t text with \nspecial symbols:\n#" } + }; + + @Test + public void checkAllTestData() { + for (String[] entry : TEST_DATA) { + assertEquals( + "Expected property value differs from the one converted from value editor text", + entry[0], + ResourceBundleUtil.fromValueEditorToPropertyValue(entry[1]) + ); + assertEquals( + "Expected value editor text differs from the one converted from property value", + entry[1], + ResourceBundleUtil.fromPropertyValueToValueEditor(entry[0]) + ); + } + } +} diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesIndexTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesIndexTest.java new file mode 100644 index 000000000000..c0a3ddb44e8b --- /dev/null +++ b/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesIndexTest.java @@ -0,0 +1,42 @@ +package com.intellij.lang.properties.xml; + +import com.intellij.openapi.application.PluginPathManager; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.testFramework.PlatformTestCase; +import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; +import com.intellij.util.indexing.FileContentImpl; + +import java.util.Map; + +/** + * @author Dmitry Avdeev + * Date: 7/25/11 + */ +public class XmlPropertiesIndexTest extends LightPlatformCodeInsightFixtureTestCase { + public XmlPropertiesIndexTest() { + PlatformTestCase.initPlatformLangPrefix(); + } + + public void testIndex() { + final VirtualFile file = myFixture.configureByFile("foo.xml").getVirtualFile(); + Map<XmlPropertiesIndex.Key, String> map = new XmlPropertiesIndex().map(FileContentImpl.createByFile(file)); + + assertEquals(3, map.size()); + assertEquals("bar", map.get(new XmlPropertiesIndex.Key("foo"))); + assertEquals("baz", map.get(new XmlPropertiesIndex.Key("fu"))); + assertTrue(map.containsKey(XmlPropertiesIndex.MARKER_KEY)); + } + + public void testSystemId() throws Exception { + final VirtualFile file = myFixture.configureByFile("wrong.xml").getVirtualFile(); + Map<XmlPropertiesIndex.Key, String> map = new XmlPropertiesIndex().map(FileContentImpl.createByFile(file)); + + assertEquals(0, map.size()); + } + + @Override + protected String getTestDataPath() { + return PluginPathManager.getPluginHomePath("properties") + "/testData/xml/"; + } + +} diff --git a/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesTest.java b/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesTest.java new file mode 100644 index 000000000000..cbcd77f5383e --- /dev/null +++ b/plugins/properties/testSrc/com/intellij/lang/properties/xml/XmlPropertiesTest.java @@ -0,0 +1,54 @@ +package com.intellij.lang.properties.xml; + +import com.intellij.lang.properties.IProperty; +import com.intellij.lang.properties.PropertiesReferenceManager; +import com.intellij.lang.properties.PropertiesUtil; +import com.intellij.lang.properties.psi.PropertiesFile; +import com.intellij.openapi.application.PluginPathManager; +import com.intellij.psi.PsiFile; +import com.intellij.testFramework.PlatformTestCase; +import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; + +import java.util.List; + +/** + * @author Dmitry Avdeev + * Date: 7/26/11 + */ +public class XmlPropertiesTest extends LightPlatformCodeInsightFixtureTestCase { + + public void testXmlProperties() throws Exception { + myFixture.configureByFile("foo.xml"); + List<PropertiesFile> files = PropertiesReferenceManager.getInstance(getProject()).findPropertiesFiles(myModule, "foo"); + assertEquals(1, files.size()); + PropertiesFile file = files.get(0); + assertEquals(1, file.findPropertiesByKey("foo").size()); + + List<IProperty> properties = PropertiesUtil.findPropertiesByKey(getProject(), "foo"); + assertEquals(1, properties.size()); + } + + public void testWrongFile() throws Exception { + PsiFile psiFile = myFixture.configureByFile("wrong.xml"); + PropertiesFile file = PropertiesUtil.getPropertiesFile(psiFile); + assertNull(file); + } + + public void testHighlighting() throws Exception { + myFixture.testHighlighting("foo.xml"); + } + + @Override + protected String getTestDataPath() { + return PluginPathManager.getPluginHomePath("properties") + "/testData/xml/"; + } + + @Override + protected boolean isWriteActionRequired() { + return false; + } + + public XmlPropertiesTest() { + PlatformTestCase.initPlatformLangPrefix(); + } +} |