String[] rules = syntaxHighlightingRules.split(ENTITY_SEPARATOR);
for (String rule : rules) {
String[] ruleFields = rule.split(FIELD_SEPARATOR);
- insertAndPreserveOrder(new OpeningHtmlTag(Integer.parseInt(ruleFields[0]), ruleFields[2]), openingTagsEntries);
- insertAndPreserveOrder(Integer.parseInt(ruleFields[1]), closingTagsOffsets);
+ int startOffset = Integer.parseInt(ruleFields[0]);
+ int endOffset = Integer.parseInt(ruleFields[1]);
+ if (startOffset < endOffset) {
+ insertAndPreserveOrder(new OpeningHtmlTag(startOffset, ruleFields[2]), openingTagsEntries);
+ insertAndPreserveOrder(endOffset, closingTagsOffsets);
+ }
}
}
assertThat(sourceDecorator.getDecoratedSourceAsHtml(sourceLine, highlighting, symbols)).isEqualTo("<span class=\"k\">package</span> <span class=\"sym-42 sym\">org.polop</span>;");
}
+ @Test
+ public void should_handle_highlighting_too_long() {
+ String sourceLine = "abc";
+ String highlighting = "0,5,c";
+ String symbols = "";
+ assertThat(sourceDecorator.getDecoratedSourceAsHtml(sourceLine, highlighting, symbols)).isEqualTo("<span class=\"c\">abc</span>");
+ }
+
@Test
public void should_ignore_missing_highlighting() {
String sourceLine = " if (toto < 42) {";
@Test
public void should_ignore_empty_source() {
- assertThat(sourceDecorator.getDecoratedSourceAsHtml("", (String) null, (String) null)).isEqualTo("");
+ assertThat(sourceDecorator.getDecoratedSourceAsHtml("", "0,1,cppd", "")).isEqualTo("");
}
+
+ @Test
+ public void should_ignore_empty_rule() {
+ String sourceLine = "@Deprecated";
+ String highlighting = "0,0,a;0,11,a";
+ String symbols = "1,11,1";
+ assertThat(sourceDecorator.getDecoratedSourceAsHtml(sourceLine, highlighting, symbols)).isEqualTo("<span class=\"a\">@<span class=\"sym-1 sym\">Deprecated</span></span>");
+ }
+
}