be translated. To avoid key="TEST" sourcetext="this is a myTESTcase for it" translation of partial terms/words. Add check of word boundary before and after sourcetext (incl. take care of current praxis for key to be delimetered by > < + add test casepull/58/head
parent
dbf3d0314e
commit
223071337b
@ -0,0 +1,63 @@
|
||||
package net.yacy.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TranslatorTest {
|
||||
|
||||
/**
|
||||
* Test of translate method, of class Translator.
|
||||
*/
|
||||
@Test
|
||||
public void testTranslate() {
|
||||
// test that translator respects word bondaries ( e.g. key=bug not translate "mybugfix"
|
||||
Translator t = new Translator();
|
||||
final Map<String, String> translationTable = new HashMap<String, String>();
|
||||
translationTable.put("MIST", "Nebel"); // key upper case just to easy identify it in test strings
|
||||
translationTable.put(">MIST", ">Nebel");
|
||||
translationTable.put("BY", "bei");
|
||||
translationTable.put(">BY", ">bei");
|
||||
translationTable.put("BY<", "bei<");
|
||||
translationTable.put(">BY<", ">bei<");
|
||||
|
||||
// source test text, expected not to be translated
|
||||
Set<String> noChange = new HashSet<String>();
|
||||
noChange.add("MISTer wong ");
|
||||
noChange.add("make no MISTake");
|
||||
noChange.add("value=\"MISTake\" ");
|
||||
noChange.add("<b>MISTral</b>");
|
||||
noChange.add("value=\"#[MISTake]#\" ");
|
||||
noChange.add(" optiMIST ");
|
||||
noChange.add("goodBY.");
|
||||
noChange.add(" BYte");
|
||||
noChange.add("<label>BYte</label>");
|
||||
//noChange.add(" BY_BY "); // this translates
|
||||
|
||||
// source test text, to be translated
|
||||
Set<String> doChange = new HashSet<String>();
|
||||
doChange.add("Queen of the MIST ");
|
||||
doChange.add("value=\"#[MIST]#\" ");
|
||||
doChange.add("text#[MIST]#text ");
|
||||
doChange.add("MIST in the forrest");
|
||||
doChange.add("MIST\nin the forrest");
|
||||
doChange.add("<label>BY</label>");
|
||||
|
||||
String result;
|
||||
for (String stringToExamine : noChange) {
|
||||
StringBuilder source = new StringBuilder(stringToExamine);
|
||||
result = t.translate(source, translationTable);
|
||||
assertEquals(result, stringToExamine);
|
||||
}
|
||||
|
||||
for (String stringToExamine : doChange) {
|
||||
StringBuilder source = new StringBuilder(stringToExamine);
|
||||
result = t.translate(source, translationTable);
|
||||
assertNotEquals(result, stringToExamine);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue