public Task TableInInclude()
    {
        List <Snippet> availableSnippets = new();
        var            content           = @"
some text

include: theKey

some other text
";
        List <string>  lines             = new()
        {
            @"| Number of Parameters | Variations per Parameter | Total Combinations | Pairwise Combinations |
| -------------------- | ----------------------- | ------------------ | --------------------- |
|2|5|25|25|"
        };

        return(SnippetVerifier.Verify(
                   DocumentConvention.SourceTransform,
                   content,
                   availableSnippets,
                   includes: new[]
        {
            Include.Build("theKey", lines, "thePath")
        }));
    }
    public Task WithMultiLineSnippet()
    {
        var           content = @"
before

include: theKey

after
";
        List <string> lines   = new() { "theValue1" };

        return(SnippetVerifier.Verify(
                   DocumentConvention.SourceTransform,
                   content,
                   snippets: new List <Snippet>
        {
            Snippet.Build(
                language: "cs",
                startLine: 1,
                endLine: 2,
                value: @"the
long
Snippet",
                key: "theKey",
                path: "thePath")
        }));
    }
    public Task Simple()
    {
        List <Snippet> availableSnippets = new()
        {
            SnippetBuild("cs", "snippet1"),
            SnippetBuild("cs", "snippet2")
        };
        var content = @"
snippet: snippet1

some text

snippet: snippet2

some other text

snippet: FileToUseAsSnippet.txt

some other text

snippet: /FileToUseAsSnippet.txt
";

        return(SnippetVerifier.Verify(
                   DocumentConvention.SourceTransform,
                   content,
                   availableSnippets,
                   new List <string>
        {
            Path.Combine(GitRepoDirectoryFinder.FindForFilePath(), "src/Tests/FileToUseAsSnippet.txt")
        }));
    }
    public Task SnippetInInclude()
    {
        List <Snippet> availableSnippets = new()
        {
            SnippetBuild("cs", "snippet1")
        };
        var           content = @"
some text

include: theKey

some other text
";
        List <string> lines   = new() { "snippet: snippet1" };

        return(SnippetVerifier.Verify(
                   DocumentConvention.SourceTransform,
                   content,
                   availableSnippets,
                   includes: new[]
        {
            Include.Build("theKey", lines, "thePath")
        }));
    }

    [Fact]
    public async Task MixedNewlinesInFile()
    {
        var file = "FileWithMixedNewLines.txt";

        File.Delete(file);
        await File.WriteAllTextAsync(file, "a\rb\nc\r\nd");

        List <Snippet> availableSnippets = new();
        var            content           = @"
some other text

snippet: FileWithMixedNewLines.txt
";
        var            result            = await SnippetVerifier.Verify(
            DocumentConvention.SourceTransform,
            content,
            availableSnippets,
            new List <string>
        {
            file
        });

        Assert.DoesNotContain("\r\n", result);
        Assert.DoesNotContain("\r", result);
    }
    public Task Missing_endToc()
    {
        var content = @"
<!-- toc -->
Bad
";

        return(SnippetVerifier.VerifyThrows(DocumentConvention.InPlaceOverwrite, content));
    }
    public Task Whitespace_snippet_key()
    {
        var content = @"
snippet:    

";

        return(SnippetVerifier.VerifyThrows(DocumentConvention.InPlaceOverwrite, content));
    }
    public Task MissingInclude()
    {
        var content = @"
before

include: theKey

after
";

        return(SnippetVerifier.Verify(DocumentConvention.SourceTransform, content));
    }
    public Task Missing_endInclude()
    {
        var content = @"
BAD <!-- include: theKey. path: /thePath -->
";

        return(SnippetVerifier.VerifyThrows <MarkdownProcessingException>(
                   DocumentConvention.InPlaceOverwrite,
                   content,
                   includes: new[]
        {
            Include.Build("theKey", Array.Empty <string>(), "c:/root/thePath")
        }));
    }
Esempio n. 10
0
    public Task Simple_Overwrite()
    {
        var availableSnippets = new List <Snippet>
        {
            SnippetBuild("cs", "snippet1"),
            SnippetBuild("cs", "snippet2"
                         )
        };
        var content = @"
<!-- snippet: snippet1 -->
```cs
BAD
```
<!-- endSnippet -->

some text

<!-- snippet: snippet2 -->
```cs
BAD
```
<!-- endSnippet -->

some other text

<!-- snippet: FileToUseAsSnippet.txt -->
```txt
BAD
```
<!-- endSnippet -->

some other text

<!-- snippet: /FileToUseAsSnippet.txt -->
```txt
BAD
```
<!-- endSnippet -->
";

        return(SnippetVerifier.Verify(
                   DocumentConvention.InPlaceOverwrite,
                   content,
                   availableSnippets,
                   new List <string>
        {
            Path.Combine(GitRepoDirectoryFinder.FindForFilePath(), "src/Tests/FileToUseAsSnippet.txt")
        }));
    }
    public Task TocRetainedIfNoHeadingsInFile()
    {
        var content = @"
# Title

toc

This document has no headings.

An empty toc section should be generated, in case
any headings are added in future.
";

        return(SnippetVerifier.Verify(DocumentConvention.SourceTransform, content));
    }
    public Task SkipHeadingBeforeToc()
    {
        var content = @"
## Heading 1

toc

Text1

## Heading 2

Text2
";

        return(SnippetVerifier.Verify(DocumentConvention.SourceTransform, content));
    }
    public Task Toc()
    {
        var content = @"
# Title

toc

## Heading 1

Text1

## Heading 2

Text2
";

        return(SnippetVerifier.Verify(DocumentConvention.SourceTransform, content));
    }
    public Task Toc_Overwrite()
    {
        var content = @"
# Title

<!-- toc -->
Bad<!-- endToc -->

## Heading 1

Text1

## Heading 2

Text2
";

        return(SnippetVerifier.Verify(DocumentConvention.InPlaceOverwrite, content));
    }
    public Task WithSingleSnippet()
    {
        var           content = @"
before

include: theKey

after
";
        List <string> lines   = new() { "theValue1" };

        return(SnippetVerifier.Verify(
                   DocumentConvention.SourceTransform,
                   content,
                   snippets: new List <Snippet>
        {
            SnippetBuild("cs", "theKey")
        }));
    }
    public Task WithSingleInclude()
    {
        var           content = @"
before

include: theKey

after
";
        List <string> lines   = new() { "theValue1" };

        return(SnippetVerifier.Verify(
                   DocumentConvention.SourceTransform,
                   content,
                   includes: new[]
        {
            Include.Build("theKey", lines, "c:/root/thePath")
        }));
    }
    public Task WithSingleInclude_Overwrite()
    {
        var           content = @"
before

BAD <!-- singleLineInclude: theKey. path: /thePath -->

after
";
        List <string> lines   = new() { "theValue1" };

        return(SnippetVerifier.Verify(
                   DocumentConvention.InPlaceOverwrite,
                   content,
                   includes: new[]
        {
            Include.Build("theKey", lines, "c:/root/thePath")
        }));
    }
    public void Simple()
    {
        var availableSnippets = new List <Snippet>
        {
            SnippetBuild(
                language: "cs",
                key: "snippet1",
                package: "package1",
                version: CreateVersionRange(5)
                ),
            SnippetBuild(
                language: "cs",
                key: "snippet1",
                package: "package1",
                version: CreateVersionRange(4)
                ),
            SnippetBuild(
                language: "cs",
                key: "snippet2",
                package: "package1",
                version: CreateVersionRange(3)
                ),
            SnippetBuild(
                language: "cs",
                key: "snippet2",
                package: "package1",
                version: CreateVersionRange(4)),
        };
        var markdownContent = @"
snippet: snippet1

some text

snippet: snippet2

some other text

";

        SnippetVerifier.Verify(markdownContent, availableSnippets);
    }
Esempio n. 19
0
    public Task WithEmptyMultipleInclude()
    {
        var content = @"
before

include: theKey

after
";
        var lines   = new List <string> {
            "", "", ""
        };

        return(SnippetVerifier.Verify(
                   DocumentConvention.SourceTransform,
                   content,
                   includes: new[]
        {
            Include.Build("theKey", lines, "c:/root/thePath")
        }));
    }
    public Task WithEmptyMultiLineInclude_Overwrite()
    {
        var           content = @"
before

 <!-- include: theKey. path: /thePath -->

 <!-- endInclude -->

after
";
        List <string> lines   = new() { "one", "two" };

        return(SnippetVerifier.Verify(
                   DocumentConvention.InPlaceOverwrite,
                   content,
                   includes: new[]
        {
            Include.Build("theKey", lines, "c:/root/thePath")
        }));
    }
    public void Simple()
    {
        var availableSnippets = new List <Snippet>
        {
            SnippetBuild(
                language: "cs",
                key: "snippet1"
                ),
            SnippetBuild(
                language: "cs",
                key: "snippet2"
                )
        };
        var markdownContent = @"
snippet: snippet1

some text

snippet: snippet2

some other text

snippet: FileToUseAsSnippet.txt

some other text

snippet: /FileToUseAsSnippet.txt

";

        SnippetVerifier.Verify(
            markdownContent,
            availableSnippets,
            new List <string>
        {
            Path.Combine(GitRepoDirectoryFinder.FindForFilePath(), "src/Tests/FileToUseAsSnippet.txt")
        });
    }
    public Task SnippetInIncludeLast()
    {
        List <Snippet> availableSnippets = new()
        {
            SnippetBuild("cs", "snippet1")
        };
        var           content = @"
some text

include: theKey

some other text
";
        List <string> lines   = new() { "line1", "snippet: snippet1" };

        return(SnippetVerifier.Verify(
                   DocumentConvention.SourceTransform,
                   content,
                   availableSnippets,
                   includes: new[]
        {
            Include.Build("theKey", lines, "thePath")
        }));
    }

    static Snippet SnippetBuild(string language, string key)
    {
        return(Snippet.Build(
                   language: language,
                   startLine: 1,
                   endLine: 2,
                   value: "Snippet",
                   key: key,
                   path: "thePath"));
    }
}