Revision: 9420
          
http://languagetool.svn.sourceforge.net/languagetool/?rev=9420&view=rev
Author:   dnaber
Date:     2013-02-18 22:21:42 +0000 (Mon, 18 Feb 2013)
Log Message:
-----------
re-add more tests from pre-Maven days, some of them split up so that they are 
now in the language module they belong to

Added Paths:
-----------
    
trunk/languagetool/languagetool-language-modules/en/src/test/java/org/languagetool/tokenizers/
    
trunk/languagetool/languagetool-language-modules/en/src/test/java/org/languagetool/tokenizers/SRXSentenceTokenizerTest.java
    
trunk/languagetool/languagetool-language-modules/en/src/test/java/org/languagetool/tools/
    
trunk/languagetool/languagetool-language-modules/en/src/test/java/org/languagetool/tools/ToolsTest.java
    
trunk/languagetool/languagetool-language-modules/pl/src/test/java/org/languagetool/rules/pl/MatchTest.java
    
trunk/languagetool/languagetool-language-modules/pl/src/test/java/org/languagetool/tools/
    
trunk/languagetool/languagetool-language-modules/pl/src/test/java/org/languagetool/tools/ToolsTest.java
    
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/LanguageTest.java
    
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/TranslationTest.java
    
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/tokenizers/
    
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/tokenizers/SRXSentenceTokenizerTest.java
    
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/tools/
    
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/tools/ToolsTest.java

Copied: 
trunk/languagetool/languagetool-language-modules/en/src/test/java/org/languagetool/tokenizers/SRXSentenceTokenizerTest.java
 (from rev 9047, 
trunk/JLanguageTool/src/test/java/org/languagetool/tokenizers/SRXSentenceTokenizerTest.java)
===================================================================
--- 
trunk/languagetool/languagetool-language-modules/en/src/test/java/org/languagetool/tokenizers/SRXSentenceTokenizerTest.java
                         (rev 0)
+++ 
trunk/languagetool/languagetool-language-modules/en/src/test/java/org/languagetool/tokenizers/SRXSentenceTokenizerTest.java
 2013-02-18 22:21:42 UTC (rev 9420)
@@ -0,0 +1,109 @@
+/* LanguageTool, a natural language style checker 
+ * Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de)
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool.tokenizers;
+
+import junit.framework.TestCase;
+import org.languagetool.TestTools;
+import org.languagetool.language.English;
+
+public class SRXSentenceTokenizerTest extends TestCase {
+
+  // accept \n as paragraph:
+  private final SentenceTokenizer stokenizer = new SRXSentenceTokenizer(new 
English());
+  // accept only \n\n as paragraph:
+  private final SentenceTokenizer stokenizer2 = new SRXSentenceTokenizer(new 
English());
+
+  @Override
+  public void setUp() {
+    stokenizer.setSingleLineBreaksMarksParagraph(true);  
+    stokenizer2.setSingleLineBreaksMarksParagraph(false);  
+  }
+
+  // NOTE: sentences here need to end with a space character so they
+  // have correct whitespace when appended:
+  public void testTokenize() {
+    // incomplete sentences, need to work for on-thy-fly checking of texts:
+    testSplit(new String[] { "Here's a" });
+    testSplit(new String[] { "Here's a sentence. ", "And here's one that's not 
comp" });
+
+    testSplit(new String[] { "This is a sentence. " });
+    testSplit(new String[] { "This is a sentence. ", "And this is another 
one." });
+    testSplit(new String[] { "This is a sentence.", "Isn't it?", "Yes, it is." 
});
+    testSplit(new String[] { "This is e.g. Mr. Smith, who talks slowly...",
+        "But this is another sentence." });
+    testSplit(new String[] { "Chanel no. 5 is blah." });
+    testSplit(new String[] { "Mrs. Jones gave Peter $4.5, to buy Chanel No 5.",
+        "He never came back." });
+    testSplit(new String[] { "On p. 6 there's nothing. ", "Another sentence." 
});
+    testSplit(new String[] { "Leave me alone!, he yelled. ", "Another 
sentence." });
+    testSplit(new String[] { "\"Leave me alone!\", he yelled." });
+    testSplit(new String[] { "'Leave me alone!', he yelled. ", "Another 
sentence." });
+    testSplit(new String[] { "'Leave me alone!,' he yelled. ", "Another 
sentence." });
+    testSplit(new String[] { "This works on the phrase level, i.e. not on the 
word level." });
+    testSplit(new String[] { "Let's meet at 5 p.m. in the main street." });
+    testSplit(new String[] { "James comes from the U.K. where he worked as a 
programmer." });
+    testSplit(new String[] { "Don't split strings like U.S.A. please." });
+    testSplit(new String[] { "Don't split strings like U. S. A. either." });
+    testSplit(new String[] { "Don't split... ", "Well you know. ", "Here comes 
more text." });
+    testSplit(new String[] { "Don't split... well you know. ", "Here comes 
more text." });
+    testSplit(new String[] { "The \".\" should not be a delimiter in quotes." 
});
+    testSplit(new String[] { "\"Here he comes!\" she said." });
+    testSplit(new String[] { "\"Here he comes!\", she said." });
+    testSplit(new String[] { "\"Here he comes.\" ", "But this is another 
sentence." });
+    testSplit(new String[] { "\"Here he comes!\". ", "That's what he said." });
+    testSplit(new String[] { "The sentence ends here. ", "(Another sentence.)" 
});
+    testSplit(new String[] { "The sentence (...) ends here." });
+    testSplit(new String[] { "The sentence [...] ends here." });
+    testSplit(new String[] { "The sentence ends here (...). ", "Another 
sentence." });
+    // previously known failed but not now :)
+    testSplit(new String[]{"He won't. ", "Really."});
+    testSplit(new String[]{"He will not. ", "Really."});
+    testSplit(new String[] { "He won't go. ", "Really." });
+    testSplit(new String[] { "He won't say no.", "Not really." });
+    testSplit(new String[] { "He won't say No.", "Not really." });
+    testSplit(new String[] { "He won't say no. 5 is better. ", "Not really." 
});
+    testSplit(new String[] { "He won't say No. 5 is better. ", "Not really." 
});
+    testSplit(new String[] { "They met at 5 p.m. on Thursday." });
+    testSplit(new String[] { "They met at 5 p.m. ", "It was Thursday." });
+    testSplit(new String[] { "This is it: a test." });
+    // one/two returns = paragraph = new sentence:
+    TestTools.testSplit(new String[] { "He won't\n\n", "Really." }, 
stokenizer2);
+    TestTools.testSplit(new String[] { "He won't\n", "Really." }, stokenizer);
+    TestTools.testSplit(new String[] { "He won't\n\n", "Really." }, 
stokenizer2);
+    TestTools.testSplit(new String[] { "He won't\nReally." }, stokenizer2);
+    // Missing space after sentence end:
+    testSplit(new String[] { "James is from the Ireland!", "He lives in Spain 
now." });
+    // From the abbreviation list:
+    testSplit(new String[] { "Jones Bros. have built a successful company." });
+    // parentheses:
+    testSplit(new String[] { "It (really!) works." });
+    testSplit(new String[] { "It [really!] works." });
+    testSplit(new String[] { "It works (really!). ", "No doubt." });
+    testSplit(new String[] { "It works [really!]. ", "No doubt." });
+    testSplit(new String[] { "It really(!) works well." });
+    testSplit(new String[] { "It really[!] works well." });
+
+    testSplit(new String[] { "This is a sentence.\u0002 ", "And this is 
another one." });  // footnotes in LibOO/OOo look like this
+  }
+
+  private void testSplit(String[] sentences) {
+    TestTools.testSplit(sentences, stokenizer);
+  }
+  
+}

Copied: 
trunk/languagetool/languagetool-language-modules/en/src/test/java/org/languagetool/tools/ToolsTest.java
 (from rev 9047, 
trunk/JLanguageTool/src/test/java/org/languagetool/tools/ToolsTest.java)
===================================================================
--- 
trunk/languagetool/languagetool-language-modules/en/src/test/java/org/languagetool/tools/ToolsTest.java
                             (rev 0)
+++ 
trunk/languagetool/languagetool-language-modules/en/src/test/java/org/languagetool/tools/ToolsTest.java
     2013-02-18 22:21:42 UTC (rev 9420)
@@ -0,0 +1,38 @@
+/* LanguageTool, a natural language style checker 
+ * Copyright (C) 2009 Marcin Miłkowski (http://www.languagetool.org)
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool.tools;
+
+import junit.framework.TestCase;
+import org.languagetool.JLanguageTool;
+import org.languagetool.language.English;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.IOException;
+
+public class ToolsTest extends TestCase {
+
+  public void testCorrect() throws IOException, ParserConfigurationException, 
SAXException {
+    final JLanguageTool tool = new JLanguageTool(new English());
+    tool.activateDefaultPatternRules();
+    tool.activateDefaultFalseFriendRules();
+    assertEquals("This is a test.", Tools.correctText("This is an test.", 
tool));
+  }
+  
+}

Copied: 
trunk/languagetool/languagetool-language-modules/pl/src/test/java/org/languagetool/rules/pl/MatchTest.java
 (from rev 9047, 
trunk/JLanguageTool/src/test/java/org/languagetool/rules/patterns/MatchTest.java)
===================================================================
--- 
trunk/languagetool/languagetool-language-modules/pl/src/test/java/org/languagetool/rules/pl/MatchTest.java
                          (rev 0)
+++ 
trunk/languagetool/languagetool-language-modules/pl/src/test/java/org/languagetool/rules/pl/MatchTest.java
  2013-02-18 22:21:42 UTC (rev 9420)
@@ -0,0 +1,81 @@
+/* LanguageTool, a natural language style checker 
+ * Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de)
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool.rules.pl;
+
+import junit.framework.TestCase;
+import org.languagetool.AnalyzedToken;
+import org.languagetool.AnalyzedTokenReadings;
+import org.languagetool.language.Polish;
+import org.languagetool.rules.patterns.Match;
+import org.languagetool.rules.patterns.Match.CaseConversion;
+import org.languagetool.rules.patterns.Match.IncludeRange;
+
+import java.io.IOException;
+import java.util.Arrays;
+
+public class MatchTest extends TestCase {
+
+  private AnalyzedTokenReadings getAnalyzedTokenReadings(String token, String 
posTag, String lemma) {
+    return new AnalyzedTokenReadings(new AnalyzedToken(token, posTag, lemma), 
0);
+  }
+
+  private Match getMatch(String posTag, String posTagReplace, boolean spell) 
throws IOException {
+    final Match match = new Match(posTag, posTagReplace, true, null, null, 
CaseConversion.NONE, false, spell, IncludeRange.NONE);
+    return match;
+  }
+
+  private Match getTextMatch(String regexMatch, String regexpReplace, boolean 
spell) throws IOException {
+    final Match match = new Match(null, null, false, regexMatch, 
regexpReplace, CaseConversion.NONE, false, spell, IncludeRange.NONE);
+    return match;
+  }
+
+  public void testSpeller() throws Exception {
+    //tests with synthesizer
+    Match match = getMatch("POS1", "POS2", true);
+    final Polish polish = new Polish();
+    match.setSynthesizer(polish.getSynthesizer());
+    match.setToken(getAnalyzedTokenReadings("inflectedform11", "POS1", 
"Lemma1"));
+    //getting empty strings, which is what we want
+    assertEquals("[]", Arrays.toString(match.toFinalString(polish)));
+
+    // contrast with a speller = false!
+    match = getMatch("POS1", "POS2", false);
+    match.setSynthesizer(polish.getSynthesizer());
+    match.setToken(getAnalyzedTokenReadings("inflectedform11", "POS1", 
"Lemma1"));
+    assertEquals("[(inflectedform11)]", 
Arrays.toString(match.toFinalString(polish)));
+
+    //and now a real word - we should get something
+    match = getMatch("subst:sg:acc.nom:m3", "subst:sg:gen:m3", true);
+    match.setSynthesizer(polish.getSynthesizer());
+    match.setToken(getAnalyzedTokenReadings("AON", "subst:sg:acc.nom:m3", 
"AON"));
+    assertEquals("[AON-u]", Arrays.toString(match.toFinalString(polish)));
+
+    //and now pure text changes        
+    match = getTextMatch("^(.*)$", "$0-u", true);
+    match.setSynthesizer(polish.getSynthesizer());
+    match.setLemmaString("AON");
+    assertEquals("[AON-u]", Arrays.toString(match.toFinalString(polish)));
+    match.setLemmaString("batalion");
+    //should be empty
+    assertEquals("[]", Arrays.toString(match.toFinalString(polish)));
+    match.setLemmaString("ASEAN");
+    //and this one not
+    assertEquals("[ASEAN-u]", Arrays.toString(match.toFinalString(polish)));
+  }
+}

Copied: 
trunk/languagetool/languagetool-language-modules/pl/src/test/java/org/languagetool/tools/ToolsTest.java
 (from rev 9047, 
trunk/JLanguageTool/src/test/java/org/languagetool/tools/ToolsTest.java)
===================================================================
--- 
trunk/languagetool/languagetool-language-modules/pl/src/test/java/org/languagetool/tools/ToolsTest.java
                             (rev 0)
+++ 
trunk/languagetool/languagetool-language-modules/pl/src/test/java/org/languagetool/tools/ToolsTest.java
     2013-02-18 22:21:42 UTC (rev 9420)
@@ -0,0 +1,88 @@
+/* LanguageTool, a natural language style checker 
+ * Copyright (C) 2009 Marcin Miłkowski (http://www.languagetool.org)
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool.tools;
+
+import junit.framework.TestCase;
+import org.languagetool.JLanguageTool;
+import org.languagetool.language.Polish;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+public class ToolsTest extends TestCase {
+
+  private ByteArrayOutputStream out;
+  private PrintStream stdout;
+  private PrintStream stderr;
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    this.stdout = System.out;
+    this.stderr = System.err;
+    this.out = new ByteArrayOutputStream();
+    final ByteArrayOutputStream err = new ByteArrayOutputStream();      
+    System.setOut(new PrintStream(this.out));
+    System.setErr(new PrintStream(err));
+  }
+
+  @Override
+  public void tearDown() throws Exception {
+    super.tearDown();
+    System.setOut(this.stdout);
+    System.setErr(this.stderr);
+  }
+
+  public void testCheck() throws IOException, ParserConfigurationException, 
SAXException {
+    final JLanguageTool tool = new JLanguageTool(new Polish());
+    tool.activateDefaultPatternRules();
+    tool.activateDefaultFalseFriendRules();
+ 
+    int matches = Tools.checkText("To jest całkowicie prawidłowe zdanie.", 
tool);
+    String output = new String(this.out.toByteArray());
+    assertEquals(0, output.indexOf("Time:"));
+    assertEquals(0, matches);
+
+    matches = Tools.checkText("To jest problem problem.", tool);
+    output = new String(this.out.toByteArray());
+    assertTrue(output.contains("Rule ID: WORD_REPEAT_RULE"));
+    assertEquals(1, matches);
+  }
+
+  public void testCorrect() throws IOException, ParserConfigurationException, 
SAXException {
+    JLanguageTool tool = new JLanguageTool(new Polish());
+    tool.activateDefaultPatternRules();
+    tool.activateDefaultFalseFriendRules();
+
+    String correct = Tools.correctText("To jest całkowicie prawidłowe 
zdanie.", tool);
+    assertEquals("To jest całkowicie prawidłowe zdanie.", correct);
+    correct = Tools.correctText("To jest jest problem.", tool);
+    assertEquals("To jest problem.", correct);
+
+    // more sentences, need to apply more suggestions > 1 in subsequent 
sentences
+    correct = Tools.correctText("To jest jest problem. Ale to już już nie jest 
problem.", tool);
+    assertEquals("To jest problem. Ale to już nie jest problem.", correct);
+    correct = Tools.correctText("To jest jest problem. Ale to już już nie jest 
problem. Tak sie nie robi. W tym zdaniu brakuje przecinka bo go zapomniałem.", 
tool);
+    assertEquals("To jest problem. Ale to już nie jest problem. Tak się nie 
robi. W tym zdaniu brakuje przecinka, bo go zapomniałem.", correct);
+  }
+  
+}

Copied: 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/LanguageTest.java
 (from rev 9047, 
trunk/JLanguageTool/src/test/java/org/languagetool/LanguageTest.java)
===================================================================
--- 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/LanguageTest.java
                         (rev 0)
+++ 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/LanguageTest.java
 2013-02-18 22:21:42 UTC (rev 9420)
@@ -0,0 +1,156 @@
+/* LanguageTool, a natural language style checker
+ * Copyright (C) 2012 Daniel Naber (http://www.danielnaber.de)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool;
+
+import java.util.Locale;
+
+import org.junit.Test;
+import org.languagetool.language.*;
+
+import static org.junit.Assert.*;
+
+public class LanguageTest {
+
+  @Test
+  public void testGetAllLanguages() {
+    assertTrue(Language.getAllLanguages().size() > 35);  // includes variants 
like en-GB
+  }
+
+  @Test
+  public void testRuleFileName() {
+    assertEquals("[/org/languagetool/rules/en/grammar.xml, 
/org/languagetool/rules/en/en-GB/grammar.xml]", new 
BritishEnglish().getRuleFileName().toString());
+    assertEquals("[/org/languagetool/rules/en/grammar.xml]", new 
AmericanEnglish().getRuleFileName().toString());
+    assertEquals("[/org/languagetool/rules/en/grammar.xml]", new 
English().getRuleFileName().toString());
+    assertEquals("[/org/languagetool/rules/de/grammar.xml]", new 
German().getRuleFileName().toString());
+  }
+
+  @Test
+  public void testGetTranslatedName() {
+    assertEquals("English", new 
English().getTranslatedName(TestTools.getMessages("en")));
+    assertEquals("English (British)", new 
BritishEnglish().getTranslatedName(TestTools.getMessages("en")));
+
+    assertEquals("Englisch", new 
English().getTranslatedName(TestTools.getMessages("de")));
+    assertEquals("Englisch (Großbritannien)", new 
BritishEnglish().getTranslatedName(TestTools.getMessages("de")));
+    assertEquals("Deutsch", new 
German().getTranslatedName(TestTools.getMessages("de")));
+    assertEquals("Deutsch (Schweiz)", new 
SwissGerman().getTranslatedName(TestTools.getMessages("de")));
+  }
+
+  @Test
+  public void testGetShortNameWithVariant() {
+    assertEquals("en-US", new AmericanEnglish().getShortNameWithVariant());
+    assertEquals("de", new German().getShortNameWithVariant());
+  }
+
+  @Test
+  public void testGetLanguageForShortName() {
+    assertEquals("en-US", 
Language.getLanguageForShortName("en-US").getShortNameWithVariant());
+    assertEquals("de", 
Language.getLanguageForShortName("de").getShortNameWithVariant());
+    try {
+      Language.getLanguageForShortName("xy");
+      fail();
+    } catch (IllegalArgumentException expected) {}
+    try {
+      Language.getLanguageForShortName("YY-KK");
+      fail();
+    } catch (IllegalArgumentException expected) {}
+  }
+
+  @Test(expected=IllegalArgumentException.class)
+  public void testInvalidShortName1() {
+    Language.getLanguageForShortName("de-");
+  }
+
+  @Test(expected=IllegalArgumentException.class)
+  public void testInvalidShortName2() {
+    Language.getLanguageForShortName("dexx");
+  }
+
+  @Test(expected=IllegalArgumentException.class)
+  public void testInvalidShortName3() {
+    Language.getLanguageForShortName("xyz-xx");
+  }
+
+  @Test
+  public void testGetLanguageForName() {
+    assertEquals("en-US", Language.getLanguageForName("English 
(US)").getShortNameWithVariant());
+    assertEquals("de", 
Language.getLanguageForName("German").getShortNameWithVariant());
+    assertEquals(null, Language.getLanguageForName("Foobar"));
+  }
+
+  @Test
+  public void testIsVariant() {
+    assertTrue(Language.getLanguageForShortName("en-US").isVariant());
+    assertTrue(Language.getLanguageForShortName("de-CH").isVariant());
+
+    assertFalse(Language.getLanguageForShortName("en").isVariant());
+    assertFalse(Language.getLanguageForShortName("de").isVariant());
+  }
+
+  @Test
+  public void testHasVariant() {
+    assertTrue(Language.getLanguageForShortName("en").hasVariant());
+    assertTrue(Language.getLanguageForShortName("de").hasVariant());
+
+    assertFalse(Language.getLanguageForShortName("en-US").hasVariant());
+    assertFalse(Language.getLanguageForShortName("de-CH").hasVariant());
+    assertFalse(Language.getLanguageForShortName("ast").hasVariant());
+    assertFalse(Language.getLanguageForShortName("pl").hasVariant());
+
+    for (Language language : Language.LANGUAGES) {
+      if (language.hasVariant()) {
+        assertNotNull("Language " + language + " needs a default variant", 
language.getDefaultVariant());
+      }
+    }
+  }
+
+  @Test
+  public void testGetLanguageForLocale() {
+    assertEquals("de-DE", Language.getLanguageForLocale(new Locale("de", 
"DE")).getShortNameWithVariant());
+    assertEquals("de-AT", Language.getLanguageForLocale(new Locale("de", 
"AT")).getShortNameWithVariant());
+    assertEquals("en-US", Language.getLanguageForLocale(new Locale("en", 
"US")).getShortNameWithVariant());
+    assertEquals("en-GB", Language.getLanguageForLocale(new Locale("en", 
"GB")).getShortNameWithVariant());
+    // fallback to the language's default variant if not specified:
+    assertEquals("en-US", Language.getLanguageForLocale(new 
Locale("en")).getShortNameWithVariant());
+    assertEquals("de-DE", Language.getLanguageForLocale(new 
Locale("de")).getShortNameWithVariant());
+    assertEquals("pl-PL", Language.getLanguageForLocale(new 
Locale("pl")).getShortNameWithVariant());
+    // final fallback is everything else fails:
+    assertEquals("en-US", 
Language.getLanguageForLocale(Locale.KOREAN).getShortNameWithVariant());
+    assertEquals("en-US", Language.getLanguageForLocale(new 
Locale("zz")).getShortNameWithVariant());
+  }
+
+  @Test
+  public void testEqualsConsiderVariantIfSpecified() {
+    // every language equals itself:
+    assertTrue(new German().equalsConsiderVariantsIfSpecified(new German()));
+    assertTrue(new GermanyGerman().equalsConsiderVariantsIfSpecified(new 
GermanyGerman()));
+    assertTrue(new English().equalsConsiderVariantsIfSpecified(new English()));
+    assertTrue(new AmericanEnglish().equalsConsiderVariantsIfSpecified(new 
AmericanEnglish()));
+    // equal if variant is the same, but only if specified:
+    assertTrue(new AmericanEnglish().equalsConsiderVariantsIfSpecified(new 
English()));
+    assertTrue(new English().equalsConsiderVariantsIfSpecified(new 
AmericanEnglish()));
+
+    assertFalse(new AmericanEnglish().equalsConsiderVariantsIfSpecified(new 
BritishEnglish()));
+    assertFalse(new English().equalsConsiderVariantsIfSpecified(new German()));
+  }
+
+  @Test
+  public void testGetAllMaintainers() {
+    
assertTrue(Language.getAllMaintainers(TestTools.getMessages("en")).length() > 
100);
+  }
+}

Copied: 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/TranslationTest.java
 (from rev 9047, 
trunk/JLanguageTool/src/test/java/org/languagetool/TranslationTest.java)
===================================================================
--- 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/TranslationTest.java
                              (rev 0)
+++ 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/TranslationTest.java
      2013-02-18 22:21:42 UTC (rev 9420)
@@ -0,0 +1,110 @@
+/* LanguageTool, a natural language style checker 
+ * Copyright (C) 2007 Daniel Naber (http://www.danielnaber.de)
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool;
+
+import junit.framework.TestCase;
+import org.languagetool.language.English;
+import org.languagetool.tools.StringTools;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * Check if the translations seem to be complete.
+ */
+public class TranslationTest extends TestCase {
+
+  public void testTranslationKeyExistence() throws IOException {
+    // use English version as the reference:
+    final File englishFile = getTranslationFile(new English());
+    final Properties enProps = new Properties();
+    enProps.load(new FileInputStream(englishFile));
+    final Set<Object> englishKeys = enProps.keySet();
+    for (int i = 0; i < Language.LANGUAGES.length; i++) {
+      final Language lang = Language.LANGUAGES[i];
+      if (lang.getShortName().equals("en") || lang == Language.DEMO) {
+        continue;
+      }
+      final Properties langProps = new Properties();
+      final File langFile = getTranslationFile(lang);
+      if (!langFile.exists()) {
+        continue;
+      }
+      langProps.load(new FileInputStream(langFile));
+      final Set<Object> langKeys = langProps.keySet();
+      for (Object englishKey : englishKeys) {
+        if (!langKeys.contains(englishKey)) {
+          System.err.println("***** No key '" + englishKey + "' in file " + 
langFile);
+        }
+      }
+    }
+  }
+
+  /**
+   * Make sure values are not empty.
+   */
+  public void testTranslationsAreNotEmpty() throws IOException {
+    for (int i = 0; i < Language.LANGUAGES.length; i++) {
+      final Language lang = Language.LANGUAGES[i];
+      if (lang == Language.DEMO) {
+        continue;
+      }
+      final File file = getTranslationFile(lang);
+      if (!file.exists()) {
+        System.err.println("Note: no translation available for " + lang);
+        continue;
+      }
+      final List<String> lines = loadFile(file);
+      for (String line : lines) {
+        line = line.trim();
+        if (StringTools.isEmpty(line) || line.charAt(0)=='#') {
+          continue;
+        }
+        final String[] parts = line.split("=");
+        if (parts.length < 2) {
+          System.err.println("***** Empty translation: '" + line + "' in file 
" + file);
+          //fail("Empty translation: '" + line + "' in file " + file);
+        }
+      }
+    }
+  }
+  
+  private List<String> loadFile(File file) throws IOException {
+    final List<String> l = new ArrayList<String>();
+    final Scanner scanner = new Scanner(file);
+    try {
+      while (scanner.hasNextLine()) {
+        l.add(scanner.nextLine());
+      }
+    } finally {
+      scanner.close();
+    }
+    return l;
+  }
+
+  private File getTranslationFile(Language lang) {
+    final String langCode = lang.getShortName();
+    final String name = "../languagetool-language-modules/" + langCode + 
"/src/main/resources/org/languagetool" 
+            + "/MessagesBundle_" + langCode + ".properties";
+    return new File(name.replace("/", File.separator));
+  }
+
+}

Copied: 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/tokenizers/SRXSentenceTokenizerTest.java
 (from rev 9047, 
trunk/JLanguageTool/src/test/java/org/languagetool/tokenizers/SRXSentenceTokenizerTest.java)
===================================================================
--- 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/tokenizers/SRXSentenceTokenizerTest.java
                          (rev 0)
+++ 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/tokenizers/SRXSentenceTokenizerTest.java
  2013-02-18 22:21:42 UTC (rev 9420)
@@ -0,0 +1,42 @@
+/* LanguageTool, a natural language style checker 
+ * Copyright (C) 2005 Daniel Naber (http://www.danielnaber.de)
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool.tokenizers;
+
+import junit.framework.TestCase;
+import org.languagetool.Language;
+
+public class SRXSentenceTokenizerTest extends TestCase {
+
+  public void testOfficeFootnoteTokenize() {
+    for (Language language : Language.REAL_LANGUAGES) {
+      if (language.getSentenceTokenizer().getClass() != 
SRXSentenceTokenizer.class) {
+        continue;
+      }
+      if (language.getShortName().equals("km") || 
language.getShortName().equals("ml") || language.getShortName().equals("pt")) {
+        // TODO: I don't know about these...
+        continue;
+      }
+      final String input = "A sentence.\u0002 And another one.";
+      final SentenceTokenizer tokenizer = new SRXSentenceTokenizer(language);
+      assertEquals("Sentence not split correctly for " + language + ": '" + 
input + "'",
+              "[A sentence.\u0002 , And another one.]", 
tokenizer.tokenize(input).toString());
+    }
+  }
+
+}

Copied: 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/tools/ToolsTest.java
 (from rev 9047, 
trunk/JLanguageTool/src/test/java/org/languagetool/tools/ToolsTest.java)
===================================================================
--- 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/tools/ToolsTest.java
                              (rev 0)
+++ 
trunk/languagetool/languagetool-standalone/src/test/java/org/languagetool/tools/ToolsTest.java
      2013-02-18 22:21:42 UTC (rev 9420)
@@ -0,0 +1,84 @@
+/* LanguageTool, a natural language style checker 
+ * Copyright (C) 2009 Marcin Miłkowski (http://www.languagetool.org)
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
+ * USA
+ */
+package org.languagetool.tools;
+
+import junit.framework.TestCase;
+import org.languagetool.JLanguageTool;
+import org.languagetool.language.English;
+import org.languagetool.language.Polish;
+import org.languagetool.rules.bitext.BitextRule;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.List;
+
+public class ToolsTest extends TestCase {
+
+  private ByteArrayOutputStream out;
+  private PrintStream stdout;
+  private PrintStream stderr;
+
+  @Override
+  public void setUp() throws Exception {
+    super.setUp();
+    this.stdout = System.out;
+    this.stderr = System.err;
+    this.out = new ByteArrayOutputStream();
+    final ByteArrayOutputStream err = new ByteArrayOutputStream();      
+    System.setOut(new PrintStream(this.out));
+    System.setErr(new PrintStream(err));
+  }
+
+  @Override
+  public void tearDown() throws Exception {
+    super.tearDown();
+    System.setOut(this.stdout);
+    System.setErr(this.stderr);
+  }
+  
+  public void testBitextCheck() throws IOException, 
ParserConfigurationException, SAXException {
+    final English english = new English();
+    final JLanguageTool srcTool = new JLanguageTool(english);
+    final Polish polish = new Polish();
+    final JLanguageTool trgTool = new JLanguageTool(polish);
+    trgTool.activateDefaultPatternRules();
+    
+    final List<BitextRule> rules = Tools.getBitextRules(english, polish);
+    
+    int matches = Tools.checkBitext(
+        "This is a perfectly good sentence.",
+        "To jest całkowicie prawidłowe zdanie.", srcTool, trgTool, rules,
+        false, StringTools.XmlPrintMode.NORMAL_XML);
+    String output = new String(this.out.toByteArray());
+    assertTrue(output.indexOf("Time:") == 0);
+    assertEquals(0, matches);
+
+    matches = Tools.checkBitext(
+        "This is not actual.", 
+        "To nie jest aktualne.", 
+        srcTool, trgTool, 
+        rules, false, StringTools.XmlPrintMode.NORMAL_XML);        
+    output = new String(this.out.toByteArray());
+    assertTrue(output.contains("Rule ID: ACTUAL"));
+    assertEquals(1, matches);
+  }
+}

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
The Go Parallel Website, sponsored by Intel - in partnership with Geeknet, 
is your hub for all things parallel software development, from weekly thought 
leadership blogs to news, videos, case studies, tutorials, tech docs, 
whitepapers, evaluation guides, and opinion stories. Check out the most 
recent posts - join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Languagetool-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/languagetool-commits

Reply via email to