use of org.springframework.ide.vscode.java.properties.parser.ParseResults 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.ParseResults in project sts4 by spring-projects.
the class PropertiesAntlrParserTest method testSyntaxError.
@Test
public void testSyntaxError() throws Exception {
String text = "abrakadabra";
ParseResults results = parser.parse(text);
assertEquals(1, results.syntaxErrors.size());
assertTrue(results.problems.isEmpty());
// One property line recorded. With key and empty value
assertEquals(1, results.ast.getAllNodes().size());
Problem syntaxError = results.syntaxErrors.get(0);
assertEquals(0, syntaxError.getOffset());
assertEquals(text.length(), syntaxError.getLength());
}
use of org.springframework.ide.vscode.java.properties.parser.ParseResults 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());
}
use of org.springframework.ide.vscode.java.properties.parser.ParseResults in project sts4 by spring-projects.
the class PropertiesAstTest method positionValue.
@Test
public void positionValue() throws Exception {
ParseResults results = parser.parse("# Comment\n" + "key = value\n");
Node node = results.ast.findNode(17);
assertTrue(node instanceof Value);
assertTrue(node.getOffset() <= 17 && 17 <= node.getOffset() + node.getLength());
node = results.ast.findNode(22);
assertTrue(node instanceof Value);
assertTrue(node.getOffset() <= 22 && 22 <= node.getOffset() + node.getLength());
node = results.ast.findNode(16);
assertTrue(node instanceof Value);
assertTrue(node.getOffset() <= 16 && 16 <= node.getOffset() + node.getLength());
}
use of org.springframework.ide.vscode.java.properties.parser.ParseResults in project sts4 by spring-projects.
the class PropertiesAstTest method positionEmptyValue.
@Test
public void positionEmptyValue() throws Exception {
ParseResults results = parser.parse("# Comment\n" + "key =");
Node node = results.ast.findNode(16);
assertTrue(node instanceof Value);
assertTrue(node.getOffset() <= 16 && 16 <= node.getOffset() + node.getLength());
}
Aggregations