-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pt] Add BrazilianPortugueseSimpleReplaceRuleTest
- Loading branch information
p-goulart
committed
Jul 25, 2023
1 parent
c47ac24
commit 5ab4fa7
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
.../pt/src/test/java/org/languagetool/rules/pt/BrazilianPortugueseSimpleReplaceRuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.languagetool.rules.pt; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.languagetool.JLanguageTool; | ||
import org.languagetool.TestTools; | ||
import org.languagetool.language.Portuguese; | ||
import org.languagetool.rules.RuleMatch; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class BrazilianPortugueseSimpleReplaceRuleTest { | ||
private BrazilianPortugueseReplaceRule rule; | ||
private JLanguageTool lt; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
rule = new BrazilianPortugueseReplaceRule(TestTools.getMessages("pt"), "/pt/pt-BR/replace.txt"); | ||
lt = new JLanguageTool(new Portuguese()); | ||
} | ||
|
||
@Test | ||
public void testRule() throws IOException { | ||
|
||
// correct sentences: | ||
assertEquals(0, rule.match(lt.getAnalyzedSentence("Fui de ônibus até o açougue italiano.")).length); | ||
|
||
// incorrect sentences: | ||
checkSimpleReplaceRule("Vou de autocarro.", "ônibus"); | ||
checkSimpleReplaceRule("O lançamento de dardo é um desporto.", "esporte"); | ||
checkSimpleReplaceRule("Está no meu ADN!", "DNA"); | ||
|
||
} | ||
|
||
/** | ||
* Check if a specific replace rule applies. | ||
* @param sentence the sentence containing the incorrect/misspelled word. | ||
* @param word the word that is correct (the suggested replacement). | ||
*/ | ||
private void checkSimpleReplaceRule(String sentence, String word) throws IOException { | ||
RuleMatch[] matches = rule.match(lt.getAnalyzedSentence(sentence)); | ||
assertEquals("Invalid matches.length while checking sentence: " | ||
+ sentence, 1, matches.length); | ||
assertEquals("Invalid replacement count while checking sentence: " | ||
+ sentence, 1, matches[0].getSuggestedReplacements().size()); | ||
assertEquals("Invalid suggested replacement while checking sentence: " | ||
+ sentence, word, matches[0].getSuggestedReplacements().get(0)); | ||
} | ||
} |
Please also add the standard copyright header (as used in
LanguageTool.java
and all other files) here