1 package org.incava.doctorj; 2 3 import java.io.*; 4 import java.util.*; 5 import junit.framework.TestCase; 6 7 8 public class TestCommentSpellCheck extends TestCase 9 { 10 static class TestableCommentSpellCheck extends CommentSpellCheck 11 { 12 class Misspelling 13 { 14 public String word; 15 16 public int position; 17 18 public Map nearMatches; 19 20 public Misspelling(String word, int position, Map nearMatches) 21 { 22 this.word = word; 23 this.position = position; 24 this.nearMatches = nearMatches; 25 } 26 27 public String toString() 28 { 29 return "[" + word + ", " + position + ", {" + nearMatches + "}"; 30 } 31 } 32 33 private List misspellings = new ArrayList(); 34 35 public void check(String desc) 36 { 37 misspellings = new ArrayList(); 38 super.check(desc); 39 } 40 41 protected void wordMisspelled(String word, int position, Map nearMatches) 42 { 43 misspellings.add(new Misspelling(word, position, nearMatches)); 44 } 45 } 46 47 private static TestableCommentSpellCheck tcsc = new TestableCommentSpellCheck(); 48 static { 49 tcsc.addDictionary("/home/jpace/proj/doctorj/etc/words.en_US"); 50 } 51 52 public TestCommentSpellCheck(String name) 53 { 54 super(name); 55 } 56 57 public void runSpellTest(String comment, int nMisspellings) 58 { 59 tcsc.check(comment); 60 tr.Ace.log("misspellings: " + tcsc.misspellings); 61 assertEquals(nMisspellings, tcsc.misspellings.size()); 62 } 63 64 public void testOK() 65 { 66 runSpellTest("// This is a comment.", 0); 67 } 68 69 public void testMisspelling() 70 { 71 runSpellTest("// This is comment has a mispelled word.", 1); 72 } 73 74 public void testMisspellings() 75 { 76 runSpellTest("// This is comment has twoo mispelled word.", 2); 77 } 78 79 public void testOKCapitalized() 80 { 81 runSpellTest("// This is a Comment.", 0); 82 } 83 84 public void testOKPreBlock() 85 { 86 runSpellTest( 87 "/** This is a comment.\n" + 88 " *\n" + 89 " *<pre>\n" + 90 " * nuffim eh?\n" + 91 " *</pre>\n" + 92 " */\n", 93 0); 94 95 runSpellTest( 96 "/** This is a comment.\n" + 97 " *\n" + 98 " *<pre>\n" + 99 " * nuttin in heer shuld bie checkt\n" + 100 " *</pre>\n" + 101 " */\n", 102 0); 103 104 runSpellTest( 105 "/** This is a comment.\n" + 106 " *\n" + 107 " *<pre>\n" + 108 " * This pre block has no end.\n" + 109 " */\n", 110 0); 111 } 112 113 public void testOKCodeBlock() 114 { 115 runSpellTest("/** This is a comment that refers to <code>str</code>. */", 0); 116 runSpellTest("/** This is a comment that refers to <code>somethingthatdoesnotend */", 0); 117 } 118 119 public void testOKLink() 120 { 121 runSpellTest("/** This is a comment that refers to a {@link tosomewhere}. */", 0); 122 runSpellTest("/** This is a comment that refers to a {@link tosomewherefarbeyond */", 0); } 124 125 } 126 | Popular Tags |