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));
}
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);
}
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));
}
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")));
}
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));
}
Aggregations