Search in sources :

Example 6 with SRootNode

use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode in project sts4 by spring-projects.

the class YamlStructureParserTest method testFindInSequence.

@Test
public void testFindInSequence() throws Exception {
    MockYamlEditor editor = new MockYamlEditor("foo:\n" + "- alchemy\n" + "- bistro\n" + "bar:\n" + "- - - nice: text\n" + "zor:\n" + "  - - - very: good\n" + "end: END");
    SRootNode root = editor.parseStructure();
    assertFind(editor, root, "foo:", 0, 0);
    assertFind(editor, root, "- alchemy", 0, 0, 0);
    assertFind(editor, root, "- bistro", 0, 0, 1);
    assertFind(editor, root, "bar:", 0, 1);
    assertFindStart(editor, root, "- - - nice: text", 0, 1, 0);
    assertFindStart(editor, root, " - - nice: text", 0, 1, 0);
    assertFindStart(editor, root, "- - nice: text", 0, 1, 0, 0);
    assertFindStart(editor, root, " - nice: text", 0, 1, 0, 0);
    assertFindStart(editor, root, "- nice: text", 0, 1, 0, 0, 0);
    assertFindStart(editor, root, " nice: text", 0, 1, 0, 0, 0);
    assertFind(editor, root, "nice: text", 0, 1, 0, 0, 0, 0);
    assertFind(editor, root, "zor:", 0, 2);
    assertFindStart(editor, root, "  - - - very: good", 0, 2);
    assertFindStart(editor, root, " - - - very: good", 0, 2);
    assertFindStart(editor, root, "- - - very: good", 0, 2, 0);
    assertFindStart(editor, root, " - - very: good", 0, 2, 0);
    assertFindStart(editor, root, "- - very: good", 0, 2, 0, 0);
    assertFindStart(editor, root, " - very: good", 0, 2, 0, 0);
    assertFindStart(editor, root, "- very: good", 0, 2, 0, 0, 0);
    assertFindStart(editor, root, " very: good", 0, 2, 0, 0, 0);
    assertFind(editor, root, "very: good", 0, 2, 0, 0, 0, 0);
}
Also used : SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) Test(org.junit.Test)

Example 7 with SRootNode

use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode in project sts4 by spring-projects.

the class YamlStructureParserTest method testFind.

@Test
public void testFind() throws Exception {
    MockYamlEditor editor = new MockYamlEditor("world:\n" + "  europe:\n" + "    france:\n" + "      cheese\n" + "    belgium:\n" + // At same level as key, technically this is a syntax error but we tolerate it
    "    beer\n" + "  canada:\n" + "    montreal: poutine\n" + "    vancouver:\n" + "      salmon\n" + "moon:\n" + "  moonbase-alfa:\n" + "    moonstone\n");
    SRootNode root = editor.parseStructure();
    assertFind(editor, root, "world:", 0, 0);
    assertFind(editor, root, "europe:", 0, 0, 0);
    assertFind(editor, root, "france:", 0, 0, 0, 0);
    assertFind(editor, root, "cheese", 0, 0, 0, 0, 0);
    assertFind(editor, root, "belgium:", 0, 0, 0, 1);
    assertFind(editor, root, "beer", 0, 0, 0, 1, 0);
    assertFind(editor, root, "canada:", 0, 0, 1);
    assertFind(editor, root, "montreal: poutine", 0, 0, 1, 0);
    assertFind(editor, root, "vancouver:", 0, 0, 1, 1);
    assertFind(editor, root, "salmon", 0, 0, 1, 1, 0);
    assertFind(editor, root, "moon:", 0, 1);
    assertFind(editor, root, "moonbase-alfa:", 0, 1, 0);
    assertFind(editor, root, "moonstone", 0, 1, 0, 0);
    assertFindStart(editor, root, " europe:", 0, 0);
}
Also used : SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) Test(org.junit.Test)

Example 8 with SRootNode

use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode in project sts4 by spring-projects.

the class YamlStructureParserTest method testTraverse.

@Test
public void testTraverse() throws Exception {
    MockYamlEditor editor = new MockYamlEditor("world:\n" + "  europe:\n" + "    france:\n" + "      cheese\n" + "    belgium:\n" + // At same level as key, technically this is a syntax error but we tolerate it
    "    beer\n" + "  canada:\n" + "    montreal: poutine\n" + "    vancouver:\n" + "      salmon\n" + "moon:\n" + "  moonbase-alfa:\n" + "    moonstone\n");
    SRootNode root = editor.parseStructure();
    YamlPath pathToFrance = pathWith(0, "world", "europe", "france");
    assertEquals("KEY(4): france:\n" + "  RAW(6): cheese\n", pathToFrance.traverse((SNode) root).toString());
    assertNull(pathWith(0, "world", "europe", "bogus").traverse((SNode) root));
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) SNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode) Test(org.junit.Test)

Example 9 with SRootNode

use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode in project sts4 by spring-projects.

the class YamlStructureParserTest method testTraverseSeq.

@Test
public void testTraverseSeq() throws Exception {
    MockYamlEditor editor = new MockYamlEditor("foo:\n" + "- - - - a\n" + "    - c\n" + "- e");
    SRootNode root = editor.parseStructure();
    YamlPath path;
    path = pathWith(0, "foo", 0, 0, 0, 0);
    assertEquals("SEQ(6): - a\n", path.traverse((SNode) root).toString());
    path = pathWith(0, "foo", -1);
    assertNull(path.traverse((SNode) root));
    path = pathWith(0, "foo", 1);
    assertEquals("SEQ(0): - e\n", path.traverse((SNode) root).toString());
    path = pathWith(0, "foo", 2);
    assertNull(path.traverse((SNode) root));
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) SNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode) Test(org.junit.Test)

Example 10 with SRootNode

use of org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode in project sts4 by spring-projects.

the class YamlStructureParserTest method testFindInMultiDoc.

@Test
public void testFindInMultiDoc() throws Exception {
    MockYamlEditor editor = new MockYamlEditor("world:\n" + "  europe:\n" + "    france:\n" + "      cheese\n" + "    belgium:\n" + // At same level as key, technically this is a syntax error but we tolerate it
    "    beer\n" + "---\n" + "  canada:\n" + "    montreal: poutine\n" + "    vancouver:\n" + "      salmon\n" + "---\n" + "moon:\n" + "  moonbase-alfa:\n" + "    moonstone\n" + "...");
    SRootNode root = editor.parseStructure();
    assertFind(editor, root, "world:", 0, 0);
    assertFind(editor, root, "europe:", 0, 0, 0);
    assertFind(editor, root, "france:", 0, 0, 0, 0);
    assertFind(editor, root, "cheese", 0, 0, 0, 0, 0);
    assertFind(editor, root, "belgium:", 0, 0, 0, 1);
    assertFind(editor, root, "beer", 0, 0, 0, 1, 0);
    assertFind(editor, root, "canada:", 1, 0);
    assertFind(editor, root, "montreal: poutine", 1, 0, 0);
    assertFind(editor, root, "vancouver:", 1, 0, 1);
    assertFind(editor, root, "salmon", 1, 0, 1, 0);
    assertFind(editor, root, "moon:", 2, 0);
    assertFind(editor, root, "moonbase-alfa:", 2, 0, 0);
    assertFind(editor, root, "moonstone", 2, 0, 0, 0);
    assertFindStart(editor, root, " canada:", 1);
}
Also used : SRootNode(org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode) Test(org.junit.Test)

Aggregations

SRootNode (org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SRootNode)12 Test (org.junit.Test)10 SNode (org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser.SNode)6 YamlPath (org.springframework.ide.vscode.commons.yaml.path.YamlPath)4 ArrayList (java.util.ArrayList)1 ICompletionProposal (org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal)1 YamlDocument (org.springframework.ide.vscode.commons.yaml.structure.YamlDocument)1