use of org.springframework.ide.vscode.java.properties.parser.PropertiesAst.KeyValuePair in project sts4 by spring-projects.
the class PropertiesAntlrParserTest method testMultipleSyntaxErrors.
@Test
public void testMultipleSyntaxErrors() throws Exception {
String text = "abrakadabra\nkey:value\nsdcsdc";
ParseResults results = parser.parse(text);
assertEquals(2, results.syntaxErrors.size());
assertTrue(results.problems.isEmpty());
// One property line recorded. With key and empty value
assertEquals(3, results.ast.getAllNodes().size());
List<KeyValuePair> lines = results.ast.getNodes(KeyValuePair.class);
assertEquals(3, lines.size());
// Test valid part
KeyValuePair validLine = lines.get(1);
assertNotNull(validLine.getKey());
assertNotNull(validLine.getValue());
assertEquals("key", text.substring(validLine.getKey().getOffset(), validLine.getKey().getOffset() + validLine.getKey().getLength()));
assertEquals("value", text.substring(validLine.getValue().getOffset(), validLine.getValue().getOffset() + validLine.getValue().getLength()));
// Test errors
Problem syntaxError1 = results.syntaxErrors.get(0);
assertEquals(0, syntaxError1.getOffset());
assertEquals(11, syntaxError1.getLength());
Problem syntaxError2 = results.syntaxErrors.get(1);
assertEquals(22, syntaxError2.getOffset());
assertEquals(6, syntaxError2.getLength());
}
use of org.springframework.ide.vscode.java.properties.parser.PropertiesAst.KeyValuePair in project sts4 by spring-projects.
the class PropertiesAntlrParserTest method testPropertyLine.
private void testPropertyLine(String text, String expectedKey, String expectedEncodedKey, String expectedValue, String expectedEncodedValue) {
ParseResults results = parser.parse(text);
assertTrue(results.syntaxErrors.isEmpty());
assertTrue(results.problems.isEmpty());
assertEquals(1, results.ast.getAllNodes().size());
List<KeyValuePair> propertyLines = results.ast.getNodes(KeyValuePair.class);
assertEquals(1, propertyLines.size());
KeyValuePair line = propertyLines.get(0);
assertNotNull(line.getKey());
assertNotNull(line.getValue());
assertEquals(expectedKey, line.getKey().decode());
assertEquals(expectedValue, line.getValue().decode());
assertEquals(expectedEncodedKey, text.substring(line.getKey().getOffset(), line.getKey().getOffset() + line.getKey().getLength()));
assertEquals(expectedEncodedValue, text.substring(line.getValue().getOffset(), line.getValue().getOffset() + line.getValue().getLength()));
}
use of org.springframework.ide.vscode.java.properties.parser.PropertiesAst.KeyValuePair in project sts4 by spring-projects.
the class PropertiesAstTest method positionPair.
@Test
public void positionPair() throws Exception {
ParseResults results = parser.parse("# Comment\n" + "key = value\n" + "\t\n");
Node node = results.ast.findNode(15);
assertTrue(node instanceof KeyValuePair);
assertTrue(node.getOffset() <= 15 && 15 <= node.getOffset() + node.getLength());
}
Aggregations