Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt committed Jul 21, 2023
1 parent 0372508 commit 35fc9cd
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/Docusaurus.Tests/DocusaurusTestHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using DotMarkdown.Linq;
using static DotMarkdown.Tests.TestHelpers;

namespace DotMarkdown.Tests;

internal static class DocusaurusTestHelpers
{
public static MFencedCodeBlock CreateCodeBlock()
{
return new MFencedCodeBlock(CodeBlockText(), CodeBlockInfo());
}
}
21 changes: 21 additions & 0 deletions src/Docusaurus.Tests/DotMarkdown.Docusaurus.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>DotMarkdown.Docusaurus.Tests</AssemblyName>
<RootNamespace>DotMarkdown.Docusaurus.Tests</RootNamespace>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.1" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Tests\DotMarkdown.Tests.csproj" />
</ItemGroup>

</Project>
80 changes: 80 additions & 0 deletions src/Docusaurus.Tests/MDocusaurusCodeBlockTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using DotMarkdown.Linq;
using Xunit;
using static DotMarkdown.Tests.TestHelpers;

namespace DotMarkdown.Tests;

public static class MDocusaurusCodeBlockTests
{
[Fact]
public static void MFencedCodeBlock_Equals()
{
MFencedCodeBlock block = CreateCodeBlock();

Assert.True(block.Equals((object)block));
}

[Fact]
public static void MFencedCodeBlock_NotEquals()
{
MFencedCodeBlock block = CreateCodeBlock();
MFencedCodeBlock block2 = block.Modify();

Assert.False(block.Equals((object)block2));
}

[Fact]
public static void MFencedCodeBlock_GetHashCode_Equal()
{
MFencedCodeBlock block = CreateCodeBlock();

Assert.Equal(block.GetHashCode(), block.GetHashCode());
}

[Fact]
public static void MFencedCodeBlock_GetHashCode_NotEqual()
{
MFencedCodeBlock block = CreateCodeBlock();
MFencedCodeBlock block2 = block.Modify();

Assert.NotEqual(block.GetHashCode(), block2.GetHashCode());
}

[Fact]
public static void MFencedCodeBlock_OperatorEquals()
{
MFencedCodeBlock block = CreateCodeBlock();
MFencedCodeBlock block2 = block;

Assert.True(block == block2);
}

[Fact]
public static void MFencedCodeBlock_OperatorNotEquals()
{
MFencedCodeBlock block = CreateCodeBlock();
MFencedCodeBlock block2 = block.Modify();

Assert.True(block != block2);
}

[Fact]
public static void MFencedCodeBlock_Constructor_AssignText()
{
string text = CodeBlockText();
var block = new MFencedCodeBlock(text: text, info: CodeBlockInfo());

Assert.Equal(text, block.Text);
}

[Fact]
public static void MFencedCodeBlock_Constructor_AssignInfo()
{
string info = CodeBlockInfo();
var block = new MFencedCodeBlock(text: CodeBlockText(), info: info);

Assert.Equal(info, block.Info);
}
}
98 changes: 98 additions & 0 deletions src/Docusaurus.Tests/MarkdownWriterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using DotMarkdown.Linq;
using Xunit;
using static DotMarkdown.Linq.MFactory;
using static DotMarkdown.Tests.MarkdownSamples;
using static DotMarkdown.Tests.TestHelpers;

#pragma warning disable CS1718

namespace DotMarkdown.Tests;

public static class MarkdownWriterTests
{
[Theory]
[InlineData("```", null)]
[InlineData("```", CodeFenceStyle.Backtick)]
[InlineData("~~~", CodeFenceStyle.Tilde)]
public static void MarkdownWriter_Write_CodeBlock_CodeFenceStyle(string syntax, CodeFenceStyle? style)
{
MarkdownWriter mw = CreateBuilderWithCodeFenceOptions(style);

MFencedCodeBlock block = FencedCodeBlock(Chars, DefaultText);
block.WriteTo(mw);

Assert.Equal(
syntax + DefaultText + NewLine + Chars + NewLine + syntax + NewLine2,
mw.ToStringAndClear());
}

[Fact]
public static void MarkdownWriter_Write_CodeBlock_CodeBlockOptionsNone()
{
MarkdownWriter mw = CreateBuilderWithCodeBlockOptions(CodeBlockOptions.None);

MFencedCodeBlock block = FencedCodeBlock(Chars, DefaultText);

mw.Write(DefaultText);
mw.Write(block);
mw.Write(block);
mw.Write(DefaultText);

Assert.Equal(
DefaultText + NewLine + CodeBlockMarkdown + CodeBlockMarkdown + DefaultText,
mw.ToStringAndClear());
}

[Fact]
public static void MarkdownWriter_Write_CodeBlock_CodeBlockOptionsEmptyLineBefore()
{
MarkdownWriter mw = CreateBuilderWithCodeBlockOptions(CodeBlockOptions.EmptyLineBefore);

MFencedCodeBlock block = FencedCodeBlock(Chars, DefaultText);

mw.Write(DefaultText);
mw.Write(block);
mw.Write(block);
mw.Write(DefaultText);

Assert.Equal(
DefaultText + NewLine2 + CodeBlockMarkdown + NewLine + CodeBlockMarkdown + DefaultText,
mw.ToStringAndClear());
}

[Fact]
public static void MarkdownWriter_Write_CodeBlock_CodeBlockOptionsEmptyLineAfter()
{
MarkdownWriter mw = CreateBuilderWithCodeBlockOptions(CodeBlockOptions.EmptyLineAfter);

MFencedCodeBlock block = FencedCodeBlock(Chars, DefaultText);

mw.Write(DefaultText);
mw.Write(block);
mw.Write(block);
mw.Write(DefaultText);

Assert.Equal(
DefaultText + NewLine + CodeBlockMarkdown + NewLine + CodeBlockMarkdown + NewLine + DefaultText,
mw.ToStringAndClear());
}

[Fact]
public static void MarkdownWriter_Write_CodeBlock_CodeBlockOptionsEmptyLineBeforeAndAfter()
{
MarkdownWriter mw = CreateBuilderWithCodeBlockOptions(CodeBlockOptions.EmptyLineBeforeAndAfter);

MFencedCodeBlock block = FencedCodeBlock(Chars, DefaultText);

mw.Write(DefaultText);
mw.Write(block);
mw.Write(block);
mw.Write(DefaultText);

Assert.Equal(
DefaultText + NewLine2 + CodeBlockMarkdown + NewLine + CodeBlockMarkdown + NewLine + DefaultText,
mw.ToStringAndClear());
}
}
18 changes: 18 additions & 0 deletions src/DotMarkdown.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotMarkdown.Docusaurus", "DotMarkdown.Docusaurus\DotMarkdown.Docusaurus.csproj", "{F320C85F-BE11-49CF-B49D-1BC0C7E7F6E4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotMarkdown.Docusaurus.Tests", "Docusaurus.Tests\DotMarkdown.Docusaurus.Tests.csproj", "{728534E0-89BB-4CD0-8FCF-DCDC5409A789}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -95,6 +97,22 @@ Global
{F320C85F-BE11-49CF-B49D-1BC0C7E7F6E4}.Release|x64.Build.0 = Release|Any CPU
{F320C85F-BE11-49CF-B49D-1BC0C7E7F6E4}.Release|x86.ActiveCfg = Release|Any CPU
{F320C85F-BE11-49CF-B49D-1BC0C7E7F6E4}.Release|x86.Build.0 = Release|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Debug|Any CPU.Build.0 = Debug|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Debug|ARM.ActiveCfg = Debug|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Debug|ARM.Build.0 = Debug|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Debug|x64.ActiveCfg = Debug|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Debug|x64.Build.0 = Debug|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Debug|x86.ActiveCfg = Debug|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Debug|x86.Build.0 = Debug|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Release|Any CPU.ActiveCfg = Release|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Release|Any CPU.Build.0 = Release|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Release|ARM.ActiveCfg = Release|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Release|ARM.Build.0 = Release|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Release|x64.ActiveCfg = Release|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Release|x64.Build.0 = Release|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Release|x86.ActiveCfg = Release|Any CPU
{728534E0-89BB-4CD0-8FCF-DCDC5409A789}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 3 additions & 1 deletion src/DotMarkdown/DotMarkdown.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ DotMarkdown.Linq.MFactory</Description>
<None Include="docs\NuGetReadme.md" Pack="true" PackagePath="docs\README.md" />
</ItemGroup>


<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>DotMarkdown.Docusaurus, PublicKey=$(DotMarkdownPublicKey)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>DotMarkdown.Tests, PublicKey=$(DotMarkdownPublicKey)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>DotMarkdown.Docusaurus.Tests, PublicKey=$(DotMarkdownPublicKey)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
8 changes: 7 additions & 1 deletion src/Tests/DotMarkdown.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -18,4 +18,10 @@
<ProjectReference Include="..\DotMarkdown\DotMarkdown.csproj" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>DotMarkdown.Docusaurus.Tests, PublicKey=$(DotMarkdownPublicKey)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>

0 comments on commit 35fc9cd

Please sign in to comment.