- edited description
The Code constructors are inconsistent in what they produce
Issue #739
closed
Add the following code to
okapi/core/src/test/java/net/sf/okapi/common/resource/CodeTest.java
static String quoteString(String text) {
if (text == null)
return "null";
return "\"" + text + "\""; // Quick and dirty, normally would need escaping
}
static void dumpCode(Code c, String description) {
StringBuffer result = new StringBuffer();
result.append("{");
result.append(String.format(" id:%d", c.getId()));
result.append(String.format(" originalId:%s", quoteString(c.originalId)));
result.append(String.format(" data:%s", quoteString(c.data == null ? "NULL" : c.data.toString())));
result.append(String.format(" displayText:%s", quoteString(c.displayText)));
result.append(String.format(" flag:%d", c.flag));
result.append(String.format(" mergedData:%s", quoteString(c.mergedData)));
result.append(String.format(" outerData:%s", quoteString(c.outerData == null ? "NULL" : c.outerData.toString())));
result.append(String.format(" tagType:%s", c.tagType));
result.append(String.format(" type:%s", quoteString(c.type)));
result.append(" }");
result.append(" // " + description);
System.out.println(result);
}
@Test
public void testConstructors() {
dumpCode(new Code(), "new Code()");
dumpCode(new Code("type"), "new Code('type')");
dumpCode(new Code(TagType.PLACEHOLDER, "type"), "new Code(PLACEHOLDER, 'type')");
dumpCode(new Code(TagType.PLACEHOLDER, "type", "data"), "new Code(PLACEHOLDER, 'type', 'data')");
Code code;
String textWithXRef = "With with [#$ ref marker";
code = new Code(TagType.PLACEHOLDER, "type", textWithXRef);
dumpCode(code, "new Code(PLACEHOLDER, 'type', textWithXRef)");
code = new Code(TagType.PLACEHOLDER, "type");
code.setData(textWithXRef);
dumpCode(code, "new Code(PLACEHOLDER, 'type') + code.setData(textWithXRef)");
}
The results are
{ id:0 originalId:null data:"" displayText:null flag:0 mergedData:null outerData:"" tagType:null type:null } // new Code()
{ id:-1 originalId:null data:"" displayText:null flag:0 mergedData:null outerData:"NULL" tagType:null type:"type" } // new Code('type')
{ id:-1 originalId:null data:"" displayText:null flag:0 mergedData:null outerData:"NULL" tagType:PLACEHOLDER type:"type" } // new Code(PLACEHOLDER, 'type')
{ id:-1 originalId:null data:"data" displayText:null flag:0 mergedData:null outerData:"NULL" tagType:PLACEHOLDER type:"type" } // new Code(PLACEHOLDER, 'type', 'data')
{ id:-1 originalId:null data:"With with [#$ ref marker" displayText:null flag:0 mergedData:null outerData:"NULL" tagType:PLACEHOLDER type:"type" } // new Code(PLACEHOLDER, 'type', textWithXRef)
{ id:-1 originalId:null data:"With with [#$ ref marker" displayText:null flag:1 mergedData:null outerData:"NULL" tagType:PLACEHOLDER type:"type" } // new Code(PLACEHOLDER, 'type') + code.setData(textWithXRef)
Description:
- When using
new Code()
the id is 0, for all the other constructors is -1 - When calling the
new Code(tagType, type, data)
constructor the flag is not set if the text contains cross-reference. So the flags can be different betweennew Code(tagType, type, data)
andcode = new Code(tagType, type); code.setData(data);
.
Comments (9)
-
reporter -
reporter - edited description
-
reporter - edited description
-
reporter - edited description
-
reporter - edited description
-
reporter - edited description
-
reporter - edited description
-
reporter - changed status to resolved
-
reporter - changed status to closed
- Log in to comment