Search in sources :

Example 1 with FakeLanguage

use of org.languagetool.FakeLanguage in project languagetool by languagetool-org.

the class GenericUnpairedBracketsRuleTest method testRuleMatchPositions.

@Test
public void testRuleMatchPositions() throws IOException {
    setUpRule(new FakeLanguage());
    RuleMatch match1 = lt.check("This »is a test.").get(0);
    assertThat(match1.getFromPos(), is(5));
    assertThat(match1.getToPos(), is(6));
    assertThat(match1.getLine(), is(0));
    assertThat(match1.getEndLine(), is(0));
    assertThat(match1.getColumn(), is(5));
    assertThat(match1.getEndColumn(), is(6));
    RuleMatch match2 = lt.check("This.\nSome stuff.\nIt »is a test.").get(0);
    assertThat(match2.getFromPos(), is(21));
    assertThat(match2.getToPos(), is(22));
    // first line is 0
    assertThat(match2.getLine(), is(2));
    assertThat(match2.getEndLine(), is(2));
    assertThat(match2.getColumn(), is(4));
    assertThat(match2.getEndColumn(), is(5));
}
Also used : FakeLanguage(org.languagetool.FakeLanguage) Test(org.junit.Test)

Example 2 with FakeLanguage

use of org.languagetool.FakeLanguage in project languagetool by languagetool-org.

the class DifferentLengthRuleTest method testRule.

@Test
public void testRule() throws IOException {
    DifferentLengthRule rule = new DifferentLengthRule();
    RuleMatch[] matches;
    JLanguageTool trgLangTool = new JLanguageTool(TestTools.getDemoLanguage());
    JLanguageTool srcLangTool = new JLanguageTool(new FakeLanguage());
    rule.setSourceLanguage(TestTools.getDemoLanguage());
    // correct sentences:
    matches = rule.match(srcLangTool.getAnalyzedSentence("This is a test sentence."), trgLangTool.getAnalyzedSentence("To zdanie testowe."));
    assertEquals(0, matches.length);
    matches = rule.match(srcLangTool.getAnalyzedSentence("Click this button."), trgLangTool.getAnalyzedSentence("Kliknij ten przycisk."));
    assertEquals(0, matches.length);
    // incorrect sentences:
    matches = rule.match(srcLangTool.getAnalyzedSentence("Open a file, and check if it is corrupt."), trgLangTool.getAnalyzedSentence("Otwórz plik."));
    assertEquals(1, matches.length);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) FakeLanguage(org.languagetool.FakeLanguage) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 3 with FakeLanguage

use of org.languagetool.FakeLanguage in project languagetool by languagetool-org.

the class RuleMatchAsXmlSerializerTest method testLanguageAttributes.

@Test
public void testLanguageAttributes() throws IOException {
    String xml1 = SERIALIZER.ruleMatchesToXml(Collections.<RuleMatch>emptyList(), "Fake", 5, NORMAL_API, LANG, Collections.<String>emptyList());
    assertTrue(xml1.contains("shortname=\"xx-XX\""));
    assertTrue(xml1.contains("name=\"Testlanguage\""));
    String xml2 = SERIALIZER.ruleMatchesToXml(Collections.<RuleMatch>emptyList(), "Fake", 5, LANG, new FakeLanguage());
    assertTrue(xml2.contains("shortname=\"xx-XX\""));
    assertTrue(xml2.contains("name=\"Testlanguage\""));
    assertTrue(xml2.contains("shortname=\"yy\""));
    assertTrue(xml2.contains("name=\"FakeLanguage\""));
    assertThat(StringUtils.countMatches(xml2, "<matches"), is(1));
    assertThat(StringUtils.countMatches(xml2, "</matches>"), is(1));
}
Also used : FakeLanguage(org.languagetool.FakeLanguage) Test(org.junit.Test)

Example 4 with FakeLanguage

use of org.languagetool.FakeLanguage in project languagetool by languagetool-org.

the class StringToolsTest method testAddSpace.

@Test
public void testAddSpace() {
    Language demoLanguage = TestTools.getDemoLanguage();
    assertEquals(" ", StringTools.addSpace("word", demoLanguage));
    assertEquals("", StringTools.addSpace(",", demoLanguage));
    assertEquals("", StringTools.addSpace(",", demoLanguage));
    assertEquals("", StringTools.addSpace(",", demoLanguage));
    assertEquals("", StringTools.addSpace(".", new FakeLanguage("fr")));
    assertEquals("", StringTools.addSpace(".", new FakeLanguage("de")));
    assertEquals(" ", StringTools.addSpace("!", new FakeLanguage("fr")));
    assertEquals("", StringTools.addSpace("!", new FakeLanguage("de")));
}
Also used : FakeLanguage(org.languagetool.FakeLanguage) Language(org.languagetool.Language) FakeLanguage(org.languagetool.FakeLanguage) Test(org.junit.Test)

Example 5 with FakeLanguage

use of org.languagetool.FakeLanguage in project languagetool by languagetool-org.

the class PatternRuleTest method testSupportsLanguage.

@Test
public void testSupportsLanguage() {
    FakeLanguage fakeLanguage1 = new FakeLanguage("yy");
    FakeLanguage fakeLanguage2 = new FakeLanguage("zz");
    PatternRule patternRule1 = new PatternRule("ID", fakeLanguage1, Collections.<PatternToken>emptyList(), "", "", "");
    assertTrue(patternRule1.supportsLanguage(fakeLanguage1));
    assertFalse(patternRule1.supportsLanguage(fakeLanguage2));
    FakeLanguage fakeLanguage1WithVariant1 = new FakeLanguage("zz", "VAR1");
    FakeLanguage fakeLanguage1WithVariant2 = new FakeLanguage("zz", "VAR2");
    PatternRule patternRuleVariant1 = new PatternRule("ID", fakeLanguage1WithVariant1, Collections.<PatternToken>emptyList(), "", "", "");
    assertTrue(patternRuleVariant1.supportsLanguage(fakeLanguage1WithVariant1));
    assertFalse(patternRuleVariant1.supportsLanguage(fakeLanguage1));
    assertFalse(patternRuleVariant1.supportsLanguage(fakeLanguage2));
    assertFalse(patternRuleVariant1.supportsLanguage(fakeLanguage1WithVariant2));
}
Also used : FakeLanguage(org.languagetool.FakeLanguage) DisambiguationPatternRule(org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 FakeLanguage (org.languagetool.FakeLanguage)10 JLanguageTool (org.languagetool.JLanguageTool)4 RuleMatch (org.languagetool.rules.RuleMatch)3 Language (org.languagetool.Language)1 DisambiguationPatternRule (org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule)1