/plugins/XML/tags/release-2-8-0/test/xml/TagUtilsTest.java

# · Java · 143 lines · 80 code · 35 blank · 28 comment · 0 complexity · af8af9322022b8518e41d65e3d109f7a MD5 · raw file

  1. /*
  2. * TagUtilsTest.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;
  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 static xml.XMLTestUtils.*;
  27. import static org.gjt.sp.jedit.testframework.EBFixture.*;
  28. import static org.gjt.sp.jedit.testframework.TestUtils.*;
  29. import org.gjt.sp.jedit.testframework.TestUtils;
  30. // }}}
  31. import org.gjt.sp.jedit.jEdit;
  32. import org.gjt.sp.jedit.EBMessage;
  33. import org.gjt.sp.jedit.textarea.JEditTextArea;
  34. import org.gjt.sp.jedit.Buffer;
  35. import java.io.*;
  36. import java.awt.event.KeyEvent;
  37. import java.awt.event.InputEvent;
  38. import org.gjt.sp.jedit.gui.CompletionPopup;
  39. /**
  40. * tests for Split/Join/Close/etc.
  41. * $Id: TagUtilsTest.java 18427 2010-08-27 06:53:38Z kerik-sf $
  42. */
  43. public class TagUtilsTest{
  44. private static File testData;
  45. @BeforeClass
  46. public static void setUpjEdit() throws IOException{
  47. TestUtils.beforeClass();
  48. testData = new File(System.getProperty("test_data")).getCanonicalFile();
  49. assertTrue(testData.exists());
  50. }
  51. @AfterClass
  52. public static void tearDownjEdit() {
  53. TestUtils.afterClass();
  54. }
  55. @Test
  56. public void testSplit(){
  57. File xml = new File(testData,"split_tag/test.xml");
  58. Buffer b = TestUtils.openFile(xml.getPath());
  59. action("sidekick-parse",1);
  60. // wait for end of parsing
  61. simplyWaitForMessageOfClass(sidekick.SideKickUpdate.class,10000);
  62. // after bbbb
  63. gotoPositionAndWait(48);
  64. action("xml-split-tag",1);
  65. assertEquals("<a> bbbb</a>",b.getLineText(1));
  66. action("undo",1);
  67. // just after <a> : was causing an issue since split() believed that it was
  68. // inside <a>
  69. gotoPositionAndWait(43);
  70. action("xml-split-tag",1);
  71. assertEquals("<a></a>",b.getLineText(1));
  72. assertEquals("<a> bbbb",b.getLineText(2));
  73. action("undo",1);
  74. // just after </b> : was causing an issue since split() believed that it was
  75. // inside <a>
  76. gotoPositionAndWait(56);
  77. action("xml-split-tag",1);
  78. assertEquals("<b></b></a>",b.getLineText(2));
  79. assertEquals("<a> ",b.getLineText(3));
  80. assertEquals("<c:c xmlns:c=\"urn:hello\">you could",b.getLineText(4));//untouched
  81. action("undo",1);
  82. }
  83. @Test
  84. public void testSplitTag() throws IOException{
  85. File xml = new File(testData,"split_tag/test.xml");
  86. Buffer b = TestUtils.openFile(xml.getPath());
  87. action("sidekick-parse");
  88. // wait for end of parsing
  89. simplyWaitForMessageOfClass(sidekick.SideKickUpdate.class,10000);
  90. // <c:c |xmlns:c="urn:hello">you could
  91. gotoPositionAndWait(62);
  92. action("xml-split-tag");
  93. String text = b.getText(0,b.getLength());
  94. action("undo",1);
  95. assertThat(text).contains("xmlns:c");
  96. gotoPositionAndWait(131);
  97. action("xml-split-tag");
  98. text = b.getText(0,b.getLength());
  99. action("undo",1);
  100. assertThat(text).contains("&lt;");
  101. // <simple |a="1" b="2"
  102. gotoPositionAndWait(204);
  103. action("xml-split-tag");
  104. assertEquals(" c = \"3\"",b.getLineText(9));
  105. action("undo",1);
  106. close(view(),b);
  107. }
  108. }