public void ConvertSpacesToTabsForDeeplyNestedCode() { var input = new SnippetInput { Body = @"public void MethodName() { if (true) { WriteLine(); } }", ConvertToTabs = true, TabLength = 2 }; var generator = new SnippetGenerator(); var snippet = generator.GetSnippet(input); var lines = Regex.Split(snippet, @"\r?\n"); Assert.EndsWith("\"public void MethodName()\",", lines[3]); Assert.EndsWith("\"{\",", lines[4]); Assert.EndsWith("\"\\t\\tif (true)\",", lines[5]); Assert.EndsWith("\"\\t\\t{\",", lines[6]); Assert.EndsWith("\"\\t\\t\\t\\tWriteLine();\",", lines[7]); Assert.EndsWith("\"\\t\\t}\",", lines[8]); Assert.EndsWith("\"}\"", lines[9]); }
public void GeneratePropertySnippet() { var input = new SnippetInput { Name = "Property", Prefix = "prop", Description = "An automatically implemented property.", HasDescription = true, Body = "public ${1:int} ${2:MyProperty} { get; set; }$0" }; var generator = new SnippetGenerator(); var snippet = generator.GetSnippet(input); var lines = Regex.Split(snippet, @"\r?\n"); Assert.Equal("\"Property\": {", lines[0]); Assert.Equal(" \"prefix\": \"prop\",", lines[1]); Assert.Equal(" \"body\": [", lines[2]); Assert.Equal(" \"public ${1:int} ${2:MyProperty} { get; set; }$0\"", lines[3]); Assert.Equal(" ],", lines[4]); Assert.Equal(" \"description\": \"An automatically implemented property.\"", lines[5]); Assert.Equal("}", lines[6]); }
public void GenerateMultilineSnippet() { var input = new SnippetInput { Name = "Property", Prefix = "prop", Body = "public ${1:int} ${2:MyProperty} { get; set; }$0" + Environment.NewLine + "// Second Line" }; var generator = new SnippetGenerator(); var snippet = generator.GetSnippet(input); var lines = Regex.Split(snippet, @"\r?\n"); Assert.Equal("\"Property\": {", lines[0]); Assert.Equal(" \"prefix\": \"prop\",", lines[1]); Assert.Equal(" \"body\": [", lines[2]); Assert.Equal(" \"public ${1:int} ${2:MyProperty} { get; set; }$0\",", lines[3]); Assert.Equal(" \"// Second Line\"", lines[4]); Assert.Equal(" ]", lines[5]); Assert.Equal("}", lines[6]); }
public void ConvertSpacesToTabs() { var input = new SnippetInput { Name = "Property", Prefix = "prop", Body = " public ${1:int} ${2:MyProperty} { get; set; }$0", ConvertToTabs = true, TabLength = 4 }; var generator = new SnippetGenerator(); var snippet = generator.GetSnippet(input); var lines = Regex.Split(snippet, @"\r?\n"); Assert.Equal("\"Property\": {", lines[0]); Assert.Equal(" \"prefix\": \"prop\",", lines[1]); Assert.Equal(" \"body\": [", lines[2]); Assert.Equal(" \"\\tpublic ${1:int} ${2:MyProperty} { get; set; }$0\"", lines[3]); Assert.Equal(" ]", lines[4]); Assert.Equal("}", lines[5]); }
public void OnGet() => SnippetOutput = _snippetGenerator.GetSnippet(SnippetInput.Empty);