PageRenderTime 50ms CodeModel.GetById 37ms app.highlight 10ms RepoModel.GetById 1ms 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
  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 */
 20package org.jedit.ruby.test;
 21
 22import junit.framework.TestCase;
 23import org.jedit.ruby.structure.AutoIndentAndInsertEnd;
 24
 25import java.util.regex.MatchResult;
 26
 27/**
 28 * @author robmckinnon at users.sourceforge.net
 29 */
 30public final class TestAutoIndent extends TestCase {
 31
 32    public final void testTrailingIfCondition() {
 33        boolean match = AutoIndentAndInsertEnd.TrailingConditionRegExp.instance.isMatch("    red if true");
 34        assertFalse("Assert doesn't match trailing condition", match);
 35    }
 36
 37    public final void testMatchIgnoreSyntax() {
 38        boolean match = AutoIndentAndInsertEnd.IgnoreRegExp.instance.isMatch("   red if true");
 39        assertTrue("Assert matchs ignore condition", match);
 40    }
 41
 42    public final void testDoesntMatchIgnoreSyntax() {
 43        boolean match = AutoIndentAndInsertEnd.IgnoreRegExp.instance.isMatch("   if true");
 44        assertFalse("Assert doesn't match ignore condition", match);
 45    }
 46
 47    public final void testEndCount() {
 48        int endCount = AutoIndentAndInsertEnd.getEndCount("end");
 49        assertEquals("Assert end count correct.", 1, endCount);
 50    }
 51
 52    public final void testEndTrue() {
 53        assertTrue(hasEnd("end"));
 54    }
 55
 56    public final void testEndTrue2() {
 57        assertTrue(hasEnd(" end "));
 58    }
 59
 60    public final void testEndTrue3() {
 61        assertTrue(hasEnd(" end #red"));
 62    }
 63
 64    public final void testEndTrue4() {
 65        assertTrue(hasEnd(" end if true"));
 66    }
 67
 68    public final void testEndTrue5() {
 69        assertTrue(hasEnd("  def quack a, b, d;    c blue;  puts 'quack';  end"));
 70    }
 71
 72    public final void testEndFalse() {
 73        assertFalse(hasEnd("#end"));
 74    }
 75
 76    public final void testEndFalse2() {
 77        assertFalse(hasEnd(" #end"));
 78    }
 79
 80    public final void testEndFalse3() {
 81        assertFalse(hasEnd("# end"));
 82    }
 83
 84    public final void testEndFalse4() {
 85        assertFalse(hasEnd(" # end"));
 86    }
 87
 88    public final void testEndFalse5() {
 89        assertFalse(hasEnd("  def tag_end name"));
 90    }
 91
 92    public final void testMatchIf() {
 93//        REMatch match = AutoIndentAndInsertEnd.MatchRegExp.instance.getMatch("  if true");
 94        MatchResult match = AutoIndentAndInsertEnd.MatchRegExp.instance.firstMatch("  if true");
 95        assertMatchResultCorrect(match, " true");
 96    }
 97
 98    public final void testMatchIfWithBracket() {
 99//        REMatch match = AutoIndentAndInsertEnd.MatchRegExp.instance.getMatch("  if(true)");
100        MatchResult match = AutoIndentAndInsertEnd.MatchRegExp.instance.firstMatch("  if(true)");
101        assertMatchResultCorrect(match, "(true)");
102    }
103
104    private static void assertMatchResultCorrect(MatchResult match, String partMatch) {
105        assertNotNull("Assert match not null.", match);
106        assertEquals("Assert match correct.", "  ", match.group(1));
107        assertEquals("Assert match correct.", "", match.group(2));
108        assertEquals("Assert match correct.", "if"+partMatch, match.group(3));
109        assertEquals("Assert match correct.", "if"+partMatch, match.group(4));
110        assertEquals("Assert match correct.", "if", match.group(5));
111        assertEquals("Assert match correct.", partMatch, match.group(6));
112    }
113
114    private static boolean hasEnd(String line) {
115        return AutoIndentAndInsertEnd.hasEndKeyword(line.trim());
116    }
117
118}