XmlDocumentationTest goes back home

This commit is contained in:
Dmitry Avdeev
2013-07-24 17:37:14 +04:00
parent e6d1714dc1
commit 62ea1b4aa8
49 changed files with 8731 additions and 0 deletions
@@ -110,6 +110,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
}
protected VirtualFile configureByFiles(@Nullable String projectRoot,String... files) throws Exception {
if (files.length == 0) return null;
final VirtualFile[] vFiles = new VirtualFile[files.length];
for (int i = 0; i < files.length; i++) {
String path = files[i];
@@ -0,0 +1,167 @@
package com.intellij.codeInsight;
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
import com.intellij.codeInsight.documentation.DocumentationManager;
import com.intellij.lang.documentation.DocumentationProvider;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.PlatformTestUtil;
import org.jetbrains.annotations.Nullable;
import java.io.File;
/**
* @by maxim
*/
public class XmlDocumentationTest extends DaemonAnalyzerTestCase {
public void testXmlDoc() throws Exception {
doOneTest("1.xml", "display-name", false, "web-app_2_3.dtd");
doOneTest("2.xml", null, false, "web-app_2_4.xsd");
doOneTest("3.xml", null, false, "web-app_2_4.xsd", "j2ee_1_4.xsd");
doOneTest("3_2.xml", null, false, "web-app_2_4.xsd", "j2ee_1_4.xsd");
doOneTest("3_3.xml", null, false, "web-app_2_4.xsd", "j2ee_1_4.xsd");
testOne("4.xml", "context-param", false, false, "web-app_2_4.xsd");
testOne("5.xml", "aaa:context-param", false, false, "web-app_2_4.xsd");
testOne("6.xsd", "xs:complexType", true, true);
doOneTest("7.xml", "bbb", false);
doOneTest("8.xml", "bbb", false);
doOneTest("9.xml", "laquo", false);
}
public void testXmlDocWithCData() throws Exception {
doQuickDocGenerationTestWithCheckExpectedResult(getTestName(false) + ".xml","spring-beans.xsd");
doQuickDocGenerationTestWithCheckExpectedResult(getTestName(false) + "2.xml","spring-beans.xsd");
}
public void testXmlDoc2() throws Exception {
doQuickDocGenerationTestWithCheckExpectedResult(getTestName(false) + ".xml", "web-app_2_4.xsd");
}
public void testXmlDoc3() throws Exception {
doQuickDocGenerationTestWithCheckExpectedResult(getTestName(false) + ".xml", "hibernate-mapping-3.0.dtd");
}
public void testXmlDoc4() throws Exception {
final String testName = getTestName(false);
doQuickDocGenerationTestWithCheckExpectedResult(testName + ".xml", testName + ".xsd");
}
public void testXmlDoc5() throws Exception {
doQuickDocGenerationTestWithCheckExpectedResult(getTestName(false) + ".xml", "maven-4.0.0.xsd");
}
public void testSchemaPrefix() throws Exception {
DocumentationTestContext context = new DocumentationTestContext("SchemaPrefix.xml");
assertEquals("XML Namespace Prefix \"xs\" (http://www.w3.org/2001/XMLSchema)", context.getQuickNavigateInfo());
}
public void testXmlDoc6() throws Exception {
final String testName = getTestName(false);
doQuickDocGenerationTestWithCheckExpectedResult((Object)"car",testName + ".xml", testName + ".xsd");
}
public void testXmlDoc7() throws Exception {
final String testName = getTestName(false);
doQuickDocGenerationTestWithCheckExpectedResult((Object)"$Paste",testName + ".xml", testName + ".xsd");
}
private void doQuickDocGenerationTestWithCheckExpectedResult(final String... baseFileNames) throws Exception {
doQuickDocGenerationTestWithCheckExpectedResult(null, baseFileNames);
}
private void doQuickDocGenerationTestWithCheckExpectedResult(Object completionVariant, final String... baseFileNames) throws Exception {
final DocumentationTestContext context = new DocumentationTestContext(baseFileNames);
VirtualFile vfile =
LocalFileSystem.getInstance().findFileByIoFile(new File(getTestDataPath() +baseFileNames[0] + ".expected.html"));
String expectedText = StringUtil.convertLineSeparators(VfsUtilCore.loadText(vfile));
assertEquals(expectedText, context.generateDoc());
if (completionVariant != null) {
vfile = LocalFileSystem.getInstance().findFileByIoFile(new File(getTestDataPath() +baseFileNames[0] + ".expected.completion.html"));
expectedText = StringUtil.convertLineSeparators(VfsUtilCore.loadText(vfile));
assertEquals(expectedText, context.generateDocForCompletion(completionVariant));
}
}
public void testDtdDoc() throws Exception {
testOne("dtd.dtd", "foo", false, true, "web-app_2_4.xsd");
testOne("dtd.xml", "foo", false, true, "web-app_2_4.xsd");
}
private void doOneTest(String fileName, String lookupObject, boolean testExternal, String... additional) throws Exception {
configureByFiles(null, additional);
testOne(fileName, lookupObject, testExternal, true, "web-app_2_4.xsd");
}
public class DocumentationTestContext {
final DocumentationProvider documentationProvider;
final PsiElement originalElement;
PsiElement element;
final PsiFile psiFile;
DocumentationTestContext(String... fileNames) throws Exception {
configureByFiles(null,fileNames);
psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(myEditor.getDocument());
originalElement = psiFile.findElementAt(myEditor.getCaretModel().getOffset());
element = DocumentationManager.getInstance(myProject).findTargetElement(myEditor, myFile, originalElement);
if (element == null) {
element = originalElement;
}
documentationProvider = DocumentationManager.getProviderFromElement(element);
}
@Nullable
String generateDoc() {
return documentationProvider.generateDoc(element, originalElement);
}
@Nullable
String getQuickNavigateInfo() {
return documentationProvider.getQuickNavigateInfo(element, originalElement);
}
@Nullable
public String generateDocForCompletion(Object completionVariant) {
PsiElement lookupItem = documentationProvider.getDocumentationElementForLookupItem(myPsiManager, completionVariant, originalElement);
assert lookupItem != null;
return documentationProvider.generateDoc(lookupItem, originalElement);
}
}
private void testOne(String fileName, String lookupObject, boolean testExternal, boolean testForElementUnderCaret, String... additional) throws Exception {
configureByFiles(null, additional);
final DocumentationTestContext context = new DocumentationTestContext(fileName);
if (testForElementUnderCaret) {
assertNotNull( "inline help for " + fileName, context.generateDoc() );
if (testExternal) {
assertNotNull( "external help", context.documentationProvider.getUrlFor(context.element, context.originalElement) );
}
}
if(lookupObject!=null) {
PsiElement docElement = context.documentationProvider.getDocumentationElementForLookupItem(
context.psiFile.getManager(), lookupObject,context.originalElement);
assertNotNull("no element for " + fileName, docElement);
assertNotNull( "inline help for lookup", context.documentationProvider.generateDoc(docElement, context.originalElement) );
if (testExternal) {
assertNotNull( "external help for lookup", context.documentationProvider.getUrlFor(docElement, context.originalElement) );
}
}
}
@Override
protected String getTestDataPath() {
return PlatformTestUtil.getCommunityPath() + "/xml/tests/testData/documentation/";
}
}
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "web-app_2_3.dtd">
<we<caret>b-app>
</web-app>
+4
View File
@@ -0,0 +1,4 @@
<html>
<body bgcol<caret>or="blue">
</body>
</html>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-a<caret>pp xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
</web-app>
+4
View File
@@ -0,0 +1,4 @@
<html>
<body bgcolor="b<caret>lue">
</body>
</html>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
<ejb-ref></ejb-ref>
</web-app>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee j2ee_1_4.xsd"
version="2.4">
<ejb-ref> <caret> </ejb-ref>
</web-app>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee j2ee_1_4.xsd"
version="2.4">
<ejb-ref <caret>> </ejb-ref>
</web-app>
+3
View File
@@ -0,0 +1,3 @@
<html>
<body <caret>
</html>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
<<caret>ejb-ref></ejb-ref>
</web-app>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<aaa:web-app xmlns:aaa="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
version="2.4">
<<caret>
</aaa:web-app>
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:schemas-dig-de:test2">
<xs:in<caret>clude schemaLocation="XsiSchemaLocation3.xsd"/>
</xs:schema>
+5
View File
@@ -0,0 +1,5 @@
<html>
<caret>
<body id="">
</body>
</html>
+6
View File
@@ -0,0 +1,6 @@
<!DOCTYPE aaa [
<!ELEMENT aaa (#PCDATA)>
<!ATTLIST aaa
bbb CDATA #REQUIRED> <!-- this is the class name -->
]>
<aaa b<caret>bb="ccc"/>
+5
View File
@@ -0,0 +1,5 @@
<html>
<caret>
<body alink="#aa<caret>aaaa">
</body>
</html>
+7
View File
@@ -0,0 +1,7 @@
<!DOCTYPE aaa [
<!ELEMENT aaa (#PCDATA)>
<!-- this is the class name -->
<!ATTLIST aaa
bbb CDATA #REQUIRED>
]>
<aaa b<caret>bb="ccc"/>
+11
View File
@@ -0,0 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Windows (vers 1st July 2003), see www.w3.org" />
<meta http-equiv="Refresh" content="0;URL=./welcome.do" />
<title>&n<caret>bsp;</title>
</head>
<body>
</body>
</html>
+5
View File
@@ -0,0 +1,5 @@
<!DOCTYPE aaa [
<!ENTITY laquo "&#171;"> <!-- left-pointing double angle quotation mark
= left pointing guillemet, U+00AB ISOnum -->
]>
<aaa bbb="c&la<caret>quo;cc"/>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://mySchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:my="http://mySchema">
<xs:element name="myElement" type="my:TYPE"/>
<xs:simpleType name="TYPE" id="TYPE">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0" id="nonNegativeInteger.minInclusive"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="T" id="T">
<xs:restriction base="xs:integer">
<xs:minInclusive value="0" id="id"/>
</xs:restriction>
</xs:simpleType>
</x<caret>s:schema>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd">
<servlet-mapping>
<caret><servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.seam</url-pattern>
</servlet-mapping>
</web-app>
@@ -0,0 +1,3 @@
Complex type:&nbsp;<b>servlet-nameType</b><br>Description :&nbsp;The servlet-name element contains the canonical name of the
servlet. Each servlet name is unique within the web
application.
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "hibernate-mapping-3.0.dtd">
<hibernate-mapping package="auction">
<class name="Bid" discriminator-value="N">
<sub<caret>class/>
</class>
</hibernate-mapping>
@@ -0,0 +1,4 @@
Tag name:&nbsp;<b>subclass</b><br>Description :&nbsp;Subclass declarations are nested beneath the root class declaration to achieve<br>
polymorphic persistence with the table-per-hierarchy mapping strategy.<br>
<br>
See the note on the class element regarding &lt;pojo/&gt; vs. @name usage...
@@ -0,0 +1 @@
<test att<caret>ribute="aaa" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="XmlDoc4.xsd"/>
@@ -0,0 +1 @@
Complex type:&nbsp;<b>myRefType</b><br>Description :&nbsp;Hello, world!
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="test" type="testType"/>
<xs:complexType name="testType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="myRefType" name="attribute"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="myRefType">
<xs:annotation>
<xs:documentation>
Hello, world!
</xs:documentation>
</xs:annotation>
<xs:union memberTypes="xs:string"/>
</xs:simpleType>
</xs:schema>
@@ -0,0 +1,3 @@
<pro<caret>ject xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 maven-4.0.0.xsd">
</project>
@@ -0,0 +1,2 @@
Tag name:&nbsp;<b>project</b><br>Description :&nbsp;The &lt;code&gt;&amp;lt;project&amp;gt;&lt;/code&gt; element is the root of the descriptor.
The following table lists all of the possible child elements.<br>Version :&nbsp;3.0.0+
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://test.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://test.com XmlDoc6.xsd">
<foo value="b<caret>ar"/>
</root>
@@ -0,0 +1 @@
Enumeration value:&nbsp;<b>car</b><br>Description :&nbsp;A vehicle to get you from A to B
@@ -0,0 +1 @@
Enumeration value:&nbsp;<b>bar</b><br>Description :&nbsp;A great place to get a drink
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns="http://test.com"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
targetNamespace="http://test.com">
<xsd:element name="root" type="rootType">
<xsd:annotation>
<xsd:documentation>
The root of foo
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="rootType">
<xsd:sequence>
<xsd:element name="foo">
<xsd:annotation>
<xsd:documentation>
A generic non-useful element
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="value">
<xsd:annotation>
<xsd:documentation>
A value for Foo
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:NMTOKEN">
<xsd:enumeration value="bar">
<xsd:annotation>
<xsd:documentation>
A great place to get a drink
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="car">
<xsd:annotation>
<xsd:documentation>
A vehicle to get you from A to B
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="dar">
<xsd:annotation>
<xsd:documentation>
A made up word
</xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
@@ -0,0 +1,2 @@
<shortcut xmlns="http://test.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://test.com XmlDoc7.xsd" key="$C<caret>ut">gero cum</shortcut>
@@ -0,0 +1 @@
Enumeration value:&nbsp;<b>$Paste</b><br>Description :&nbsp;Ctrl+V
@@ -0,0 +1 @@
Enumeration value:&nbsp;<b>$Cut</b><br>Description :&nbsp;Ctrl+X, Shift+Delete
@@ -0,0 +1,26 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test.com">
<xs:element name="shortcut">
<xs:complexType mixed="true">
<xs:attribute name="key" type="KeyboardShortcutType" use="optional"/>
</xs:complexType>
</xs:element>
<xs:simpleType name="KeyboardShortcutType">
<xs:restriction base="xs:token">
<xs:enumeration value="$Copy">
<xs:annotation>
<xs:documentation>Ctrl+C, Ctrl+Insert</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="$Cut">
<xs:annotation>
<xs:documentation>Ctrl+X, Shift+Delete</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="$Paste">
<xs:annotation>
<xs:documentation>Ctrl+V</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:schema>
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<be<caret>ans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<util:properties id="myProperties" location="classpath:org/springframework/beans/factory/config/util.properties"/>
<util:constant id="min" static-field="java.lang.Integer.MIN_VALUE"/>
<util:map id="myProps">
<entry key="bbb" value="aaa"/>
</util:map>
</beans>
@@ -0,0 +1,2 @@
Tag name:&nbsp;<b>beans</b><br>Description :&nbsp;The top level (typically root) element. Allows the definition &lt;&gt;&quot;&#39;/&gt;<br>
of default values for all nested bean definitions.
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean class="java.lang.String" scope="request">
<co<caret>nstructor-arg value="foo"/>
<aop:scoped-proxy/>
</bean>
</beans>
@@ -0,0 +1,11 @@
Tag name:&nbsp;<b>constructor-arg</b><br>Description :&nbsp;Bean definitions can specify zero or more constructor arguments.<br>
This is an alternative to &quot;autowire constructor&quot;.<br>
Arguments correspond to either a specific index of the constructor<br>
argument list or are supposed to be matched generically by type.<br>
<br>
Note: A single generic argument value will just be used once, rather<br>
than potentially matched multiple times (as of Spring 1.1).<br>
<br>
constructor-arg elements are also used in conjunction with the<br>
factory-method element to construct beans using static or instance<br>
factory methods.
+3
View File
@@ -0,0 +1,3 @@
<!--Foo-->
<!ELEMENT foo (#PCDATA)>
<!ELEMENT bar (f<caret>oo)>
+5
View File
@@ -0,0 +1,5 @@
<!DOCTYPE foo [
<!--Foo-->
<!ELEMENT foo (#PCDATA)>
]>
<f<caret>oo />
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff