Skip to content

Commit

Permalink
Fix YAML structure for escaped keys
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed May 15, 2024
1 parent 0300cde commit 212dacf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class YamlStructureParser {
* Pattern that matches a line starting with a 'simple key'
*/
public static final Pattern SIMPLE_KEY_LINE = Pattern.compile(
"^((\\w(\\.|\\w|-)*)|(\\'(\\.|\\w|-|\\[|\\])*\\')):( .*|$)");
"^((\\w(\\.|\\w|-)*)|(\\'(\\.|\\w|-|\\[|\\]|\\*|/)*\\')):( .*|$)");
//TODO: the parrern above is too selective (e.g. in real yaml one can have
//spaces in simple keys and lots of other characters that this pattern does not
//allow. For now it is good enough because we are only interested in spring property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,39 @@ public class YamlStructureParserTest {

}

@Test public void escapedStringKey_2() throws Exception {
MockYamlEditor editor;

editor = new MockYamlEditor(
"my:\n" +
" map:\n"+
" foobar:\n" +
" name: jeff"
);
assertParseOneDoc(editor,
"DOC(0): ",
" KEY(0): my:",
" KEY(2): map:",
" KEY(4): foobar:",
" KEY(6): name: jeff"
);

editor = new MockYamlEditor(
"my:\n" +
" map:\n"+
" '[**/]':\n" +
" name: jeff"
);
assertParseOneDoc(editor,
"DOC(0): ",
" KEY(0): my:",
" KEY(2): map:",
" KEY(4): '[**/]':",
" KEY(6): name: jeff"
);

}

@Test public void ignoreLeadingYamlCruftBeforeLeadingDocumentSeparator() throws Exception {
String[] stuffToIgnore = {
"#comment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2582,6 +2582,29 @@ void testInnerTypeEnumMapKeyCompletion() throws Exception {
"monday : String", "tuesday : String", "wednesday : String", "thursday : String", "friday : String", "saturday : String", "sunday : String"
);
}

@Test
void testValueCompletionsOnEscapedKey() throws Exception {
useProject(createPredefinedMavenProject("enums-boot-1.3.2-app"));

data("foo.demo", "java.util.Map<java.lang.String,demo.Color>", null, "Map of any string to colors");

assertCompletions(
"foo:\n" +
" demo:\n" +
" '[./**/]': <*>",
//=>
"foo:\n" +
" demo:\n" +
" '[./**/]': blue<*>",
"foo:\n" +
" demo:\n" +
" '[./**/]': green<*>",
"foo:\n" +
" demo:\n" +
" '[./**/]': red<*>"
);
}

@Test
void testEnumMapKeyCompletion() throws Exception {
Expand Down

0 comments on commit 212dacf

Please sign in to comment.