Search in sources :

Example 16 with ParseResults

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()));
}
Also used : KeyValuePair(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.KeyValuePair) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults)

Example 17 with ParseResults

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());
}
Also used : Problem(org.springframework.ide.vscode.java.properties.parser.Problem) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults) Test(org.junit.Test)

Example 18 with ParseResults

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());
}
Also used : KeyValuePair(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.KeyValuePair) Node(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults) Test(org.junit.Test)

Example 19 with ParseResults

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());
}
Also used : Node(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node) Value(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults) Test(org.junit.Test)

Example 20 with ParseResults

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());
}
Also used : Node(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node) Value(org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value) ParseResults(org.springframework.ide.vscode.java.properties.parser.ParseResults) Test(org.junit.Test)

Aggregations

ParseResults (org.springframework.ide.vscode.java.properties.parser.ParseResults)21 Test (org.junit.Test)14 Node (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Node)9 KeyValuePair (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.KeyValuePair)5 Value (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Value)5 Problem (org.springframework.ide.vscode.java.properties.parser.Problem)3 Key (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Key)3 ArrayList (java.util.ArrayList)2 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)2 Comment (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.Comment)2 EmptyLine (org.springframework.ide.vscode.java.properties.parser.PropertiesAst.EmptyLine)2 File (java.io.File)1 URI (java.net.URI)1 BitSet (java.util.BitSet)1 ANTLRErrorListener (org.antlr.v4.runtime.ANTLRErrorListener)1 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 RecognitionException (org.antlr.v4.runtime.RecognitionException)1 ATNConfigSet (org.antlr.v4.runtime.atn.ATNConfigSet)1 DFA (org.antlr.v4.runtime.dfa.DFA)1