From f602e3fda87fe60dcb645762d759806989f32961 Mon Sep 17 00:00:00 2001 From: GillouLT Date: Tue, 28 May 2024 08:19:06 +0100 Subject: [PATCH] [fr] adding a java test for match-merging --- .../org/languagetool/JLanguageToolTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/languagetool-language-modules/fr/src/test/java/org/languagetool/JLanguageToolTest.java b/languagetool-language-modules/fr/src/test/java/org/languagetool/JLanguageToolTest.java index d95dd8e09a04..a40af140f966 100644 --- a/languagetool-language-modules/fr/src/test/java/org/languagetool/JLanguageToolTest.java +++ b/languagetool-language-modules/fr/src/test/java/org/languagetool/JLanguageToolTest.java @@ -101,4 +101,28 @@ public void testQuotes() throws IOException { assertEquals(true, processedMatches.get(0).getRule().getTags().contains(Tag.picky)); assertEquals("AI_FR_GGEC_QUOTES", processedMatches.get(0).getSpecificRuleId()); } + @Test + public void testMergingOfGrammarCorrections() throws IOException { + Language lang = new French(); + JLanguageTool lt = new JLanguageTool(lang); + AnalyzedSentence analyzedSentence = lt.getAnalyzedSentence("Ce sont de spectateur"); + + // Mocking two adjacent grammar issues + RuleMatch ruleMatch1 = new RuleMatch(new FakeRule("AI_FR_GGEC_DES"), analyzedSentence, 9, 11, "Erreur de nombre"); + ruleMatch1.setSuggestedReplacement("des"); + RuleMatch ruleMatch2 = new RuleMatch(new FakeRule("AI_FR_GGEC_SPECTATEURS"), analyzedSentence, 12, 21, "Erreur de forme plurielle"); + ruleMatch2.setSuggestedReplacement("spectateurs"); + + List ruleMatches = new ArrayList<>(); + ruleMatches.add(ruleMatch1); + ruleMatches.add(ruleMatch2); + + // Process the rule matches + List processedMatches = lang.mergeSuggestions(ruleMatches, null, null); + + // Asserts + assertEquals("des spectateurs", processedMatches.get(0).getSuggestedReplacements().get(0)); + assertEquals("AI_FR_MERGED_MATCH", processedMatches.get(0).getSpecificRuleId()); + } + }