PageRenderTime 28ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/RubyPlugin/src/org/jedit/ruby/test/TestAutoIndent.java

#
Java | 118 lines | 72 code | 22 blank | 24 comment | 0 complexity | a6f3bf2d15cb18e3de00b53fd957b60b 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. * TestAutoIndent.java -
  3. *
  4. * Copyright 2005 Robert McKinnon
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. package org.jedit.ruby.test;
  21. import junit.framework.TestCase;
  22. import org.jedit.ruby.structure.AutoIndentAndInsertEnd;
  23. import java.util.regex.MatchResult;
  24. /**
  25. * @author robmckinnon at users.sourceforge.net
  26. */
  27. public final class TestAutoIndent extends TestCase {
  28. public final void testTrailingIfCondition() {
  29. boolean match = AutoIndentAndInsertEnd.TrailingConditionRegExp.instance.isMatch(" red if true");
  30. assertFalse("Assert doesn't match trailing condition", match);
  31. }
  32. public final void testMatchIgnoreSyntax() {
  33. boolean match = AutoIndentAndInsertEnd.IgnoreRegExp.instance.isMatch(" red if true");
  34. assertTrue("Assert matchs ignore condition", match);
  35. }
  36. public final void testDoesntMatchIgnoreSyntax() {
  37. boolean match = AutoIndentAndInsertEnd.IgnoreRegExp.instance.isMatch(" if true");
  38. assertFalse("Assert doesn't match ignore condition", match);
  39. }
  40. public final void testEndCount() {
  41. int endCount = AutoIndentAndInsertEnd.getEndCount("end");
  42. assertEquals("Assert end count correct.", 1, endCount);
  43. }
  44. public final void testEndTrue() {
  45. assertTrue(hasEnd("end"));
  46. }
  47. public final void testEndTrue2() {
  48. assertTrue(hasEnd(" end "));
  49. }
  50. public final void testEndTrue3() {
  51. assertTrue(hasEnd(" end #red"));
  52. }
  53. public final void testEndTrue4() {
  54. assertTrue(hasEnd(" end if true"));
  55. }
  56. public final void testEndTrue5() {
  57. assertTrue(hasEnd(" def quack a, b, d; c blue; puts 'quack'; end"));
  58. }
  59. public final void testEndFalse() {
  60. assertFalse(hasEnd("#end"));
  61. }
  62. public final void testEndFalse2() {
  63. assertFalse(hasEnd(" #end"));
  64. }
  65. public final void testEndFalse3() {
  66. assertFalse(hasEnd("# end"));
  67. }
  68. public final void testEndFalse4() {
  69. assertFalse(hasEnd(" # end"));
  70. }
  71. public final void testEndFalse5() {
  72. assertFalse(hasEnd(" def tag_end name"));
  73. }
  74. public final void testMatchIf() {
  75. // REMatch match = AutoIndentAndInsertEnd.MatchRegExp.instance.getMatch(" if true");
  76. MatchResult match = AutoIndentAndInsertEnd.MatchRegExp.instance.firstMatch(" if true");
  77. assertMatchResultCorrect(match, " true");
  78. }
  79. public final void testMatchIfWithBracket() {
  80. // REMatch match = AutoIndentAndInsertEnd.MatchRegExp.instance.getMatch(" if(true)");
  81. MatchResult match = AutoIndentAndInsertEnd.MatchRegExp.instance.firstMatch(" if(true)");
  82. assertMatchResultCorrect(match, "(true)");
  83. }
  84. private static void assertMatchResultCorrect(MatchResult match, String partMatch) {
  85. assertNotNull("Assert match not null.", match);
  86. assertEquals("Assert match correct.", " ", match.group(1));
  87. assertEquals("Assert match correct.", "", match.group(2));
  88. assertEquals("Assert match correct.", "if"+partMatch, match.group(3));
  89. assertEquals("Assert match correct.", "if"+partMatch, match.group(4));
  90. assertEquals("Assert match correct.", "if", match.group(5));
  91. assertEquals("Assert match correct.", partMatch, match.group(6));
  92. }
  93. private static boolean hasEnd(String line) {
  94. return AutoIndentAndInsertEnd.hasEndKeyword(line.trim());
  95. }
  96. }