PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/XML/test/xml/parser/SchemaToCompletionTest.java

#
Java | 138 lines | 101 code | 18 blank | 19 comment | 0 complexity | b0fe4282bef72f0453dcf5cd815f335e MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * RelaxNGCompletionTest.java
  3. * :folding=explicit:collapseFolds=1:
  4. *
  5. * Copyright (C) 2010 Eric Le Lay
  6. *
  7. * The XML plugin is licensed under the GNU General Public License, with
  8. * the following exception:
  9. *
  10. * "Permission is granted to link this code with software released under
  11. * the Apache license version 1.1, for example used by the Xerces XML
  12. * parser package."
  13. */
  14. package xml.parser;
  15. // {{{ jUnit imports
  16. import java.util.concurrent.TimeUnit;
  17. import org.junit.*;
  18. import static org.junit.Assert.*;
  19. import org.fest.swing.fixture.*;
  20. import org.fest.swing.core.*;
  21. import org.fest.swing.finder.*;
  22. import org.fest.swing.edt.*;
  23. import org.fest.swing.timing.*;
  24. import static org.fest.assertions.Assertions.*;
  25. import org.gjt.sp.jedit.testframework.Log;
  26. import org.gjt.sp.jedit.testframework.TestUtils;
  27. import static xml.XMLTestUtils.*;
  28. // }}}
  29. import java.io.*;
  30. import java.net.*;
  31. import java.util.*;
  32. import xml.completion.*;
  33. import xml.completion.ElementDecl.AttributeDecl;
  34. /**
  35. * $Id: SchemaToCompletionTest.java 18330 2010-08-11 19:53:08Z kerik-sf $
  36. */
  37. public class SchemaToCompletionTest{
  38. private static File testData;
  39. @BeforeClass
  40. public static void setUpjEdit() throws IOException{
  41. TestUtils.beforeClass();
  42. testData = new File(System.getProperty("test_data")).getCanonicalFile();
  43. assertTrue(testData.exists());
  44. }
  45. @AfterClass
  46. public static void tearDownjEdit() {
  47. TestUtils.afterClass();
  48. }
  49. @Test
  50. public void testParentRef(){
  51. File f = new File(testData,"parentRef/actual_table.rng");
  52. Map<String,CompletionInfo> rng = SchemaToCompletion.rngSchemaToCompletionInfo(null,f.getPath(),null,null);
  53. assertEquals(1,rng.size());
  54. assertTrue(rng.containsKey(""));
  55. CompletionInfo info = rng.get("");
  56. assertEquals(1,info.elementHash.size());
  57. assertThat(info.elementHash.keySet()).containsOnly("doc");
  58. ElementDecl doc = info.elementHash.get("doc");
  59. assertThat(doc.content).contains("table","p");
  60. ElementDecl em = doc.elementHash.get("p").elementHash.get("em");
  61. // true loop in the model mirroring the loop in the schema
  62. assertSame(em, em.elementHash.get("em"));
  63. ElementDecl td = doc.elementHash.get("table").elementHash.get("tr").elementHash.get("td");
  64. assertThat(td.content).containsOnly("em");
  65. }
  66. @Test
  67. public void testRelaxNG(){
  68. File f = new File(testData,"../xml/dtds/relaxng.rng");
  69. Map<String,CompletionInfo> rng = SchemaToCompletion.rngSchemaToCompletionInfo(null,f.getPath(),null,null);
  70. assertEquals(1,rng.size());
  71. assertTrue(rng.containsKey("http://relaxng.org/ns/structure/1.0"));
  72. CompletionInfo info = rng.get("http://relaxng.org/ns/structure/1.0");
  73. assertThat(info.elementHash.keySet()).contains("element");
  74. ElementDecl element = info.elementHash.get("element");
  75. assertThat(element.content).contains("choice");
  76. assertTrue(element.attributeHash.containsKey("name"));
  77. assertTrue(element.attributeHash.containsKey("ns"));
  78. AttributeDecl a = element.attributeHash.get("name");
  79. assertEquals("QName",a.type);
  80. }
  81. @Test
  82. public void testLocate(){
  83. File f = new File(testData,"../xml/dtds/locate.rng");
  84. Map<String,CompletionInfo> rng = SchemaToCompletion.rngSchemaToCompletionInfo(null,f.getPath(),null,null);
  85. assertEquals(1,rng.size());
  86. assertTrue(rng.containsKey("http://thaiopensource.com/ns/locating-rules/1.0"));
  87. CompletionInfo info = rng.get("http://thaiopensource.com/ns/locating-rules/1.0");
  88. assertThat(info.elementHash.keySet()).containsOnly("locatingRules");
  89. ElementDecl locatingRules = info.elementHash.get("locatingRules");
  90. assertTrue(locatingRules.attributeHash.containsKey("base"));
  91. assertThat(locatingRules.content).contains("include");
  92. ElementDecl include = locatingRules.elementHash.get("include");
  93. assertTrue(include.attributeHash.containsKey("base"));
  94. AttributeDecl base = include.attributeHash.get("base");
  95. assertEquals("http://www.w3.org/XML/1998/namespace",base.namespace);
  96. assertEquals("anyURI",base.type);
  97. assertFalse(base.required);
  98. AttributeDecl rules = include.attributeHash.get("rules");
  99. assertEquals("",rules.namespace);
  100. assertEquals("anyURI",rules.type);
  101. assertTrue(rules.required);
  102. }
  103. @Test
  104. public void testOptionalRef(){
  105. File f = new File(testData,"optionalRef/schema.rng");
  106. Map<String,CompletionInfo> rng = SchemaToCompletion.rngSchemaToCompletionInfo(null,f.getPath(),null,null);
  107. assertEquals(1,rng.size());
  108. assertTrue(rng.containsKey(""));
  109. CompletionInfo info = rng.get("");
  110. assertThat(info.elementHash.keySet()).containsOnly("doc");
  111. ElementDecl doc = info.elementHash.get("doc");
  112. assertTrue(doc.attributeHash.containsKey("inline"));
  113. assertFalse(doc.getAttribute("inline").required);
  114. assertThat(doc.content).contains("needsinline");
  115. ElementDecl e = doc.elementHash.get("needsinline");
  116. assertTrue(e.attributeHash.containsKey("inline"));
  117. AttributeDecl inline = e.attributeHash.get("inline");
  118. assertTrue(inline.required);
  119. }
  120. }