public void Scenario(string name, string folder, string inputFile, string expectedFile) { var parser = new CodeFileParser(folder); var snippets = parser.Parse(new[] { ".*code[.]cs" }); var result = DocumentFileProcessor.Apply(snippets, inputFile); Assert.Equal(File.ReadAllText(expectedFile), result.Text); }
public void GetCodeSnippets_ProvidingARegex_ChoosesAllFiles() { var directory = @"data\use-regexes\".ToCurrentDirectory(); var parser = new CodeFileParser(directory); var actual = parser.Parse(new[] { "[.]cs" }); Assert.True(actual.Count == 2); }
public void GetCodeSnippets_ProvidingARegexWithFolder_ChoosesOneFile() { var directory = @"data\use-regexes\".ToCurrentDirectory(); var parser = new CodeFileParser(directory); var actual = parser.Parse(new[] { @".*want.*[.]cs" }); Assert.True(actual.Count == 1); }
public void GetCodeSnippets_WithNestedSnippets_ReturnsTwoValues() { var directory = @"data\get-code-snippets\".ToCurrentDirectory(); var parser = new CodeFileParser(directory); var actual = parser.Parse(new[] { ".*nested-code[.]cs" }); Assert.Equal(2, actual.Count); Assert.True(actual.All(c => !string.IsNullOrWhiteSpace(c.Value))); }
public void GetCodeSnippets_ReturnsMultipleResults_AllHaveValues() { var directory = @"data\get-code-snippets\".ToCurrentDirectory(); var parser = new CodeFileParser(directory); var actual = parser.Parse(new[] { ".*code[.]cs" }); Assert.True(actual.Count > 1); Assert.True(actual.All(c => !string.IsNullOrWhiteSpace(c.Value))); }
public void ApplySnippets_UsingFile_MatchesExpectedResult() { var directory = @"data\apply-snippets\".ToCurrentDirectory(); var inputFile = Path.Combine(directory, @"input.md"); var outputFile = Path.Combine(directory, @"output.md"); var parser = new CodeFileParser(directory); var snippets = parser.Parse(new[] { ".*code[.]cs" }); var result = DocumentFileProcessor.Apply(snippets, inputFile); Assert.Equal(File.ReadAllText(outputFile), result.Text); }
public static UpdateResult Update(string codeFolder, string[] extensionsToSearch, string docsFolder) { var stopwatch = new Stopwatch(); stopwatch.Start(); var result = new UpdateResult(); var codeParser = new CodeFileParser(codeFolder); ICollection <CodeSnippet> snippets; using (TimingScope.Start("CodeParser.Parse")) snippets = codeParser.Parse(extensionsToSearch); var incompleteSnippets = snippets.Where(s => string.IsNullOrWhiteSpace(s.Value)).ToArray(); if (incompleteSnippets.Any()) { var messages = ErrorFormatter.FormatIncomplete(incompleteSnippets); result.Errors.AddRange(messages); return(result); } result.Snippets = snippets.Count; var processor = new DocumentFileProcessor(docsFolder); var processResult = processor.Apply(snippets); var snippetsNotUsed = snippets.Except(processResult.SnippetsUsed).ToArray(); var snippetsMissed = processResult.SnippetReferences; if (snippetsMissed.Any()) { var messages = ErrorFormatter.FormatNotFound(snippetsMissed); result.Errors.AddRange(messages); } if (snippetsNotUsed.Any()) { var messages = ErrorFormatter.FormatUnused(snippetsNotUsed); result.Warnings.AddRange(messages); } result.Files = processResult.Count; result.Completed = !result.Errors.Any(); stopwatch.Stop(); result.ElapsedMilliseconds = stopwatch.ElapsedMilliseconds; return(result); }
public static UpdateResult Update(string codeFolder, string[] extensionsToSearch, string docsFolder) { var stopwatch = new Stopwatch(); stopwatch.Start(); var result = new UpdateResult(); var codeParser = new CodeFileParser(codeFolder); ICollection<CodeSnippet> snippets; using(TimingScope.Start("CodeParser.Parse")) snippets = codeParser.Parse(extensionsToSearch); var incompleteSnippets = snippets.Where(s => string.IsNullOrWhiteSpace(s.Value)).ToArray(); if (incompleteSnippets.Any()) { var messages = ErrorFormatter.FormatIncomplete(incompleteSnippets); result.Errors.AddRange(messages); return result; } result.Snippets = snippets.Count; var processor = new DocumentFileProcessor(docsFolder); var processResult = processor.Apply(snippets); var snippetsNotUsed = snippets.Except(processResult.SnippetsUsed).ToArray(); var snippetsMissed = processResult.SnippetReferences; if (snippetsMissed.Any()) { var messages = ErrorFormatter.FormatNotFound(snippetsMissed); result.Errors.AddRange(messages); } if (snippetsNotUsed.Any()) { var messages = ErrorFormatter.FormatUnused(snippetsNotUsed); result.Warnings.AddRange(messages); } result.Files = processResult.Count; result.Completed = !result.Errors.Any(); stopwatch.Stop(); result.ElapsedMilliseconds = stopwatch.ElapsedMilliseconds; return result; }