-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0453b2
commit e858e52
Showing
3 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
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
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
56 changes: 56 additions & 0 deletions
56
autograder-core/src/test/java/de/firemage/autograder/core/TestMessageOverriding.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,56 @@ | ||
package de.firemage.autograder.core; | ||
|
||
import de.firemage.autograder.api.AbstractLinter; | ||
import fluent.syntax.parser.FTLParser; | ||
import fluent.syntax.parser.FTLStream; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Locale; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class TestMessageOverriding { | ||
@Test | ||
void testNoMessageOverride() { | ||
var builder = AbstractLinter.builder(Locale.ENGLISH); | ||
var linter = new Linter(builder); | ||
String msg = linter.translateMessage(new LocalizedMessage("status-compiling")); | ||
assertEquals("Compiling", msg); | ||
} | ||
|
||
@Test | ||
void testSingleMessageOverride() { | ||
String fluentFile = "status-compiling = Foo Bar"; | ||
|
||
var builder = | ||
AbstractLinter.builder(Locale.ENGLISH).messagesOverride(FTLParser.parse(FTLStream.of(fluentFile))); | ||
var linter = new Linter(builder); | ||
String msg = linter.translateMessage(new LocalizedMessage("status-compiling")); | ||
assertEquals("Foo Bar", msg); | ||
} | ||
|
||
@Test | ||
void testDoubleMessageOverride() { | ||
String fluentFile1 = "status-compiling = param {$x}"; | ||
String fluentFile2 = "status-compiling = Foo Bar"; | ||
|
||
var builder = AbstractLinter.builder(Locale.ENGLISH) | ||
.messagesOverride(FTLParser.parse(FTLStream.of(fluentFile1))) | ||
.messagesOverride(FTLParser.parse(FTLStream.of(fluentFile2))); | ||
var linter = new Linter(builder); | ||
String msg = linter.translateMessage(new LocalizedMessage("status-compiling", Map.of("x", "xyz"))); | ||
assertEquals("param xyz", msg); | ||
} | ||
|
||
@Test | ||
void testNonOverriddenMessageWithOverrides() { | ||
String fluentFile = "status-compiling = Foo Bar"; | ||
|
||
var builder = | ||
AbstractLinter.builder(Locale.ENGLISH).messagesOverride(FTLParser.parse(FTLStream.of(fluentFile))); | ||
var linter = new Linter(builder); | ||
String msg = linter.translateMessage(new LocalizedMessage("status-model")); | ||
assertEquals("Building the code model", msg); | ||
} | ||
} |