Somewhat better handling of escaped '[...]' keys in yaml
This commit is contained in:
@@ -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|-|\\[|\\])*\\')):( .*|$)");
|
||||
//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
|
||||
|
||||
@@ -33,6 +33,39 @@ import org.springframework.ide.vscode.commons.yaml.structure.YamlStructureParser
|
||||
|
||||
public class YamlStructureParserTest {
|
||||
|
||||
@Test public void escapedStringKey() 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"+
|
||||
" '[foo.bar]':\n" +
|
||||
" name: jeff"
|
||||
);
|
||||
assertParseOneDoc(editor,
|
||||
"DOC(0): ",
|
||||
" KEY(0): my:",
|
||||
" KEY(2): map:",
|
||||
" KEY(4): '[foo.bar]':",
|
||||
" KEY(6): name: jeff"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Test public void ignoreLeadingYamlCruftBeforeLeadingDocumentSeparator() throws Exception {
|
||||
String[] stuffToIgnore = {
|
||||
"#comment",
|
||||
|
||||
@@ -90,6 +90,46 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@Test public void test_GH_534() throws Exception {
|
||||
//See: https://www.pivotaltracker.com/n/projects/1346850/stories/174872660
|
||||
IJavaProject p = createPredefinedMavenProject("map-of-pojo");
|
||||
useProject(p);
|
||||
data("my.props", "java.util.Properties", null, "Properties in java.util.Properties");
|
||||
data("my.arr", "java.lang.String[]", null, "Array");
|
||||
|
||||
Editor editor = newEditor(
|
||||
"my:\n" +
|
||||
" arr:\n" +
|
||||
" index: something\n" +
|
||||
" props:\n" +
|
||||
" '[foo.bar]': something\n" +
|
||||
" map:\n" +
|
||||
" '[foo.bar]':\n" +
|
||||
" name: Freddy\n" +
|
||||
" age: the-age\n" +
|
||||
" bad: 123"
|
||||
);
|
||||
editor.assertProblems(
|
||||
"index|'int'",
|
||||
"the-age|'int'",
|
||||
"bad|Person"
|
||||
);
|
||||
|
||||
//Also check if completion engine understands the convention
|
||||
editor = newEditor(
|
||||
"my:\n" +
|
||||
" map:\n"+
|
||||
" '[foo.bar]':\n" +
|
||||
" <*>"
|
||||
);
|
||||
editor.assertContextualCompletions("<*>",
|
||||
// ==>
|
||||
"age: <*>",
|
||||
"name: <*>"
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void handleAsKey() throws Exception {
|
||||
//See: https://www.pivotaltracker.com/story/show/174954118
|
||||
useProject(createPredefinedMavenProject("justauth-example"));
|
||||
|
||||
Reference in New Issue
Block a user