Changeset 11057 in josm


Ignore:
Timestamp:
2016-09-27T09:25:46+02:00 (3 years ago)
Author:
simon04
Message:

Template engine: fix string representations

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/template_engine/Condition.java

    r9079 r11057  
    4141    public String toString() {
    4242        StringBuilder sb = new StringBuilder();
    43         sb.append("?{");
     43        sb.append("?{ ");
    4444        for (TemplateEntry entry: entries) {
    4545            if (entry instanceof SearchExpressionCondition) {
     
    4848                sb.append('\'').append(entry).append('\'');
    4949            }
    50             sb.append('|');
     50            sb.append(" | ");
    5151        }
     52        sb.setLength(sb.length() - 3);
     53        sb.append(" }");
    5254        return sb.toString();
    5355    }
  • trunk/src/org/openstreetmap/josm/tools/template_engine/Variable.java

    r8846 r11057  
    5656    @Override
    5757    public String toString() {
    58         return '{' + variableName + '}';
     58        return '{' + (special ? SPECIAL_VARIABLE_PREFIX : "") + variableName + '}';
    5959    }
    6060
  • trunk/test/unit/org/openstreetmap/josm/tools/template_engine/TemplateParserTest.java

    r10846 r11057  
    174174        entry.appendText(sb, dataProvider);
    175175        Assert.assertEquals("name=waypointName, number=10", sb.toString());
     176        Assert.assertEquals("{special:everything}", entry.toString());
    176177    }
    177178
     
    333334        Assert.assertEquals("child2", sb.toString());
    334335    }
     336
     337    @Test
     338    public void testToStringCanBeParsedAgain() throws Exception {
     339        final String s1 = "?{ '{name} ({desc})' | '{name} ({cmt})' | '{name}' | '{desc}' | '{cmt}' }";
     340        final String s2 = new TemplateParser(s1).parse().toString();
     341        final String s3 = new TemplateParser(s2).parse().toString();
     342        Assert.assertEquals(s1, s2);
     343        Assert.assertEquals(s2, s3);
     344    }
    335345}
Note: See TracChangeset for help on using the changeset viewer.