/projects/drjava-stable-20100913-r5387/src/src/edu/rice/cs/drjava/model/definitions/indent/QuestionCurrLineStartsWithSkipCommentsTest.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus · Java · 189 lines · 132 code · 17 blank · 40 comment · 0 complexity · 22dc2c87e60d459fd386b7b9ec320019 MD5 · raw file

  1. /*BEGIN_COPYRIGHT_BLOCK
  2. *
  3. * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
  14. * names of its contributors may be used to endorse or promote products
  15. * derived from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  21. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  24. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  25. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * This software is Open Source Initiative approved Open Source Software.
  30. * Open Source Initative Approved is a trademark of the Open Source Initiative.
  31. *
  32. * This file is part of DrJava. Download the current version of this project
  33. * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
  34. *
  35. * END_COPYRIGHT_BLOCK*/
  36. package edu.rice.cs.drjava.model.definitions.indent;
  37. import javax.swing.text.BadLocationException;
  38. /** Tests the proper functionality of the class QuestionCurrLineStartsWithSkipComments.
  39. * @version $Id: QuestionCurrLineStartsWithSkipCommentsTest.java 5175 2010-01-20 08:46:32Z mgricken $
  40. */
  41. public final class QuestionCurrLineStartsWithSkipCommentsTest extends IndentRulesTestCase {
  42. private String _text;
  43. private IndentRuleQuestion _rule;
  44. public void testNoPrefix() throws BadLocationException {
  45. _text =
  46. "class A \n" + /* 0 */
  47. "{ \n" + /* 25 */
  48. " // one line comment \n" + /* 50 */
  49. " int method1 \n" + /* 75 */
  50. " /** \n" + /* 100 */
  51. " * javadoc comment \n" + /* 125 */
  52. " */ \n" + /* 150 */
  53. " int method() \n" + /* 175 */
  54. " { \n" + /* 200 */
  55. " } \n" + /* 225 */
  56. " /* multi line \n" + /* 250 */
  57. " comment \n" + /* 275 */
  58. " boolean method() \n" + /* 300 */
  59. " { \n" + /* 325 */
  60. " } \n" + /* 350 */
  61. " */ \n" + /* 375 */
  62. "}"; /* 400 */
  63. _setDocText(_text);
  64. IndentRuleQuestion rule = new QuestionCurrLineStartsWithSkipComments("", null, null);
  65. // This rule should always apply, unless the entire line is inside a comment.
  66. assertTrue("At 0.", rule.testApplyRule(_doc, 0, Indenter.IndentReason.OTHER));
  67. assertTrue("At start of block.", rule.testApplyRule(_doc, 25, Indenter.IndentReason.OTHER));
  68. // System.err.println("****** Starting test that fails ******");
  69. assertTrue("START starts one-line comment.", ! rule.testApplyRule(_doc, 54, Indenter.IndentReason.OTHER));
  70. assertTrue("START starts one-line comment.", ! rule.testApplyRule(_doc, 60, Indenter.IndentReason.OTHER));
  71. assertTrue("START starts javadoc comment.", ! rule.testApplyRule(_doc, 104, Indenter.IndentReason.OTHER));
  72. assertTrue("START starts javadoc comment.", ! rule.testApplyRule(_doc, 110, Indenter.IndentReason.OTHER));
  73. assertTrue("Line inside javadoc comment.", ! rule.testApplyRule(_doc, 130, Indenter.IndentReason.OTHER));
  74. assertTrue("Line closes javadoc comment.", ! rule.testApplyRule(_doc, 150, Indenter.IndentReason.OTHER));
  75. assertTrue("START is free.", rule.testApplyRule(_doc, 180, Indenter.IndentReason.OTHER));
  76. assertTrue("START is free.", rule.testApplyRule(_doc, 230, Indenter.IndentReason.OTHER));
  77. assertTrue("START starts multi-line comment.", ! rule.testApplyRule(_doc, 260, Indenter.IndentReason.OTHER));
  78. assertTrue("Line inside multi-line comment.", ! rule.testApplyRule(_doc, 275, Indenter.IndentReason.OTHER));
  79. assertTrue("Line inside multi-line comment.", ! rule.testApplyRule(_doc, 300, Indenter.IndentReason.OTHER));
  80. assertTrue("Line closes multi-line comment.", ! rule.testApplyRule(_doc, 399, Indenter.IndentReason.OTHER));
  81. assertTrue("START is free.", rule.testApplyRule(_doc, 400, Indenter.IndentReason.OTHER));
  82. assertTrue("At end of document.", rule.testApplyRule(_doc, 401, Indenter.IndentReason.OTHER));
  83. }
  84. public void testOpenBracePrefix() throws BadLocationException
  85. {
  86. _text =
  87. "class A extends \n" + /* 0 */
  88. "B { \n" + /* 25 */
  89. " // { } \n" + /* 50 */
  90. " int field; \n" + /* 75 */
  91. " /** \n" + /* 100 */
  92. " * { } \n" + /* 125 */
  93. " */ \n" + /* 150 */
  94. " int method() /* \n" + /* 175 */
  95. " */ { \n" + /* 200 */
  96. " } \n" + /* 225 */
  97. " /* multi line \n" + /* 250 */
  98. " comment \n" + /* 275 */
  99. " boolean method() \n" + /* 300 */
  100. "/**stuff*/ { // stuff\n" + /* 325 */
  101. " } \n" + /* 350 */
  102. " \n" + /* 375 */
  103. "}"; /* 400 */
  104. _setDocText(_text);
  105. _rule = new QuestionCurrLineStartsWithSkipComments("{", null, null);
  106. assertTrue("At 0 - line doesn't start with an open brace.", !_rule.testApplyRule(_doc, 0, Indenter.IndentReason.OTHER));
  107. assertTrue("Line starts a block, but not the start of the line.", !_rule.testApplyRule(_doc, 25, Indenter.IndentReason.OTHER));
  108. assertTrue("Inside block - line starts with an alphanumeric character.",!_rule.testApplyRule(_doc, 30, Indenter.IndentReason.OTHER));
  109. assertTrue("Line starts a one-line comment.", !_rule.testApplyRule(_doc, 54, Indenter.IndentReason.OTHER));
  110. assertTrue("Line starts a one-line comment.", !_rule.testApplyRule(_doc, 60, Indenter.IndentReason.OTHER));
  111. assertTrue("Line starts with alphanumeric character.", !_rule.testApplyRule(_doc, 80, Indenter.IndentReason.OTHER));
  112. assertTrue("Line starts a javadoc comment.", !_rule.testApplyRule(_doc, 104, Indenter.IndentReason.OTHER));
  113. assertTrue("Line starts a javadoc comment.", !_rule.testApplyRule(_doc, 110, Indenter.IndentReason.OTHER));
  114. assertTrue("Line inside javadoc comment.", !_rule.testApplyRule(_doc, 130, Indenter.IndentReason.OTHER));
  115. assertTrue("Line starts with alphanumeric character.", !_rule.testApplyRule(_doc, 180, Indenter.IndentReason.OTHER));
  116. assertTrue("Line closes comment. It follows an open brace.", _rule.testApplyRule(_doc, 201, Indenter.IndentReason.OTHER));
  117. assertTrue("Line closes comment. It follows an open brace.", _rule.testApplyRule(_doc, 221, Indenter.IndentReason.OTHER));
  118. assertTrue("At end of block - line starts with a close brace.", !_rule.testApplyRule(_doc, 225, Indenter.IndentReason.OTHER));
  119. assertTrue("Line starts a multi-line comment.", !_rule.testApplyRule(_doc, 260, Indenter.IndentReason.OTHER));
  120. assertTrue("Line inside multi-line comment.", !_rule.testApplyRule(_doc, 275, Indenter.IndentReason.OTHER));
  121. assertTrue("Line inside multi-line comment.", !_rule.testApplyRule(_doc, 300, Indenter.IndentReason.OTHER));
  122. assertTrue("Line closes comment. It follows an open brace.", _rule.testApplyRule(_doc, 325, Indenter.IndentReason.OTHER));
  123. assertTrue("Line starts with a close brace.", !_rule.testApplyRule(_doc, 355, Indenter.IndentReason.OTHER));
  124. assertTrue("Empty line.", !_rule.testApplyRule(_doc, 390, Indenter.IndentReason.OTHER));
  125. assertTrue("At last character - line starts with a close brace.", !_rule.testApplyRule(_doc, 400, Indenter.IndentReason.OTHER));
  126. assertTrue("At end of document - line starts with a close brace.", !_rule.testApplyRule(_doc, 401, Indenter.IndentReason.OTHER));
  127. }
  128. public void testCloseBracePrefix() throws BadLocationException
  129. {
  130. _text =
  131. "class A \n" + /* 0 */
  132. "{ \n" + /* 25 */
  133. " // } } \n" + /* 50 */
  134. " int field; \n" + /* 75 */
  135. " /** \n" + /* 100 */
  136. " * javadoc comment \n" + /* 125 */
  137. " */ } \n" + /* 150 */
  138. " int method() \n" + /* 175 */
  139. "/**/} \n" + /* 200 */
  140. "/ * } \n" + /* 225 */
  141. " /* multi line \n" + /* 250 */
  142. " comment \n" + /* 275 */
  143. " boolean method() \n" + /* 300 */
  144. " { \n" + /* 325 */
  145. "*/ / } \n" + /* 350 */
  146. " * } \n" + /* 375 */
  147. "}"; /* 400 */
  148. _setDocText(_text);
  149. _rule = new QuestionCurrLineStartsWithSkipComments("}", null, null);
  150. assertTrue("At 0 - line doesn't start with a close brace.", !_rule.testApplyRule(_doc, 0, Indenter.IndentReason.OTHER));
  151. assertTrue("At start of block - line starts with an open brace.", !_rule.testApplyRule(_doc, 25, Indenter.IndentReason.OTHER));
  152. assertTrue("Inside block - line starts with an open brace.", !_rule.testApplyRule(_doc, 30, Indenter.IndentReason.OTHER));
  153. assertTrue("Line starts a one-line comment.", !_rule.testApplyRule(_doc, 54, Indenter.IndentReason.OTHER));
  154. assertTrue("Line starts a one-line comment.", !_rule.testApplyRule(_doc, 60, Indenter.IndentReason.OTHER));
  155. assertTrue("Line starts with alphanumeric character.", !_rule.testApplyRule(_doc, 80, Indenter.IndentReason.OTHER));
  156. assertTrue("Line starts a javadoc comment.", !_rule.testApplyRule(_doc, 104, Indenter.IndentReason.OTHER));
  157. assertTrue("Line starts a javadoc comment.", !_rule.testApplyRule(_doc, 110, Indenter.IndentReason.OTHER));
  158. assertTrue("Line inside javadoc comment.", !_rule.testApplyRule(_doc, 130, Indenter.IndentReason.OTHER));
  159. assertTrue("Line closes multi-line comment, it follows a close brace.", _rule.testApplyRule(_doc, 150, Indenter.IndentReason.OTHER));
  160. assertTrue("Line starts with alphanumeric character.", !_rule.testApplyRule(_doc, 180, Indenter.IndentReason.OTHER));
  161. assertTrue("Line starts with a comment, it follows a close brace.", _rule.testApplyRule(_doc, 221, Indenter.IndentReason.OTHER));
  162. assertTrue("At end of block - line starts with a slash.", !_rule.testApplyRule(_doc, 225, Indenter.IndentReason.OTHER));
  163. assertTrue("Line starts a multi-line comment.", !_rule.testApplyRule(_doc, 260, Indenter.IndentReason.OTHER));
  164. assertTrue("Line inside multi-line comment.", !_rule.testApplyRule(_doc, 275, Indenter.IndentReason.OTHER));
  165. assertTrue("Line inside multi-line comment.", !_rule.testApplyRule(_doc, 300, Indenter.IndentReason.OTHER));
  166. assertTrue("Line inside multi-line comment.", !_rule.testApplyRule(_doc, 325, Indenter.IndentReason.OTHER));
  167. assertTrue("Line closes multi-line comment, it follows a slash.", !_rule.testApplyRule(_doc, 355, Indenter.IndentReason.OTHER));
  168. assertTrue("Line starts with a star.", !_rule.testApplyRule(_doc, 376, Indenter.IndentReason.OTHER));
  169. assertTrue("At last character - line starts with a close brace.", _rule.testApplyRule(_doc, 400, Indenter.IndentReason.OTHER));
  170. assertTrue("At end of document - line starts with a close brace.", _rule.testApplyRule(_doc, 401, Indenter.IndentReason.OTHER));
  171. }
  172. }