-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add 32 unit test related to parse from markdown to html functionality - setup .yml file for github actions
- Loading branch information
1 parent
0b495a2
commit 01c9290
Showing
7 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: .NetTests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup .NET | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: 6.0.x | ||
|
||
- name: Install dependencies | ||
run: dotnet restore | ||
|
||
- name: Build | ||
run: dotnet build --no-restore | ||
|
||
- name: Test | ||
run: dotnet test --no-build --verbosity normal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Вовки загнали собаку, `_` оточили, **хочуть зжерти**. Собака просить не вбивати її, натомість обіцяє допомагати заганяти овець та іншу худобу. | ||
|
||
Вовки ** подумали і залишили собаку в зграї. Два роки вона їм допомагала, всьому вчила, показувала місця, полювала разом з ними... | ||
Настала особливо _голодна_зима_, `полювання*нев_далі`, _вовки_ голодні, зневірені. Що робити? Вирішили все-таки зжерти собаку. Зжерли. Кісточки поховали. | ||
|
||
|
||
|
||
|
||
|
||
``` | ||
Поставили надгробок. `Думають`, як підписати, від кого? **Від друзів?** Так начебто які ж вони друзі, раз зжерли... _Від_ворогів?_ Так 2 роки разом пліч-о-пліч | ||
``` | ||
жили, полювали, ніхто в образі не був... Подумали і написали `Від колег`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<p>Вовки загнали собаку, <tt>_</tt> оточили, <b>хочуть зжерти</b>. Собака просить не вбивати її, натомість обіцяє допомагати заганяти овець та іншу худобу.</p> | ||
<p>Вовки ** подумали і залишили собаку в зграї. Два роки вона їм допомагала, всьому вчила, показувала місця, полювала разом з ними... | ||
Настала особливо <i>голодна_зима</i>, <tt>полювання*нев_далі</tt>, <i>вовки</i> голодні, зневірені. Що робити? Вирішили все-таки зжерти собаку. Зжерли. Кісточки поховали.</p> | ||
<p><pre> | ||
Поставили надгробок. `Думають`, як підписати, від кого? **Від друзів?** Так начебто які ж вони друзі, раз зжерли... _Від_ворогів?_ Так 2 роки разом пліч-о-пліч | ||
</pre> | ||
жили, полювали, ніхто в образі не був... Подумали і написали <tt>Від колег</tt>.</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using FluentAssertions; | ||
using MarkdownParser; | ||
|
||
namespace MarkdownParserTests.ConvertionToHtmlTests | ||
{ | ||
public class ConvertionToHtmlTests | ||
{ | ||
[Theory] | ||
// Paragraph | ||
[InlineData("Hello world", "<p>Hello world</p>")] | ||
[InlineData("Hello world\n\nI am Lucifer", "<p>Hello world</p>\n<p>I am Lucifer</p>")] | ||
[InlineData("Hello world\n\n\n\n\n\n\n\n\nI am Lucifer", "<p>Hello world</p>\n<p>I am Lucifer</p>")] | ||
[InlineData("Hello world\nI am Lucifer", "<p>Hello world\nI am Lucifer</p>")] | ||
// Bold | ||
[InlineData("Hello **world**", "<p>Hello <b>world</b></p>")] | ||
[InlineData("Hello **_** world", "<p>Hello <b>_</b> world</p>")] | ||
[InlineData("Hello ** world", "<p>Hello ** world</p>")] | ||
[InlineData("Hello world. I am **Luci**fer**", "<p>Hello world. I am <b>Luci**fer</b></p>")] | ||
[InlineData("**Hello world**. I am Lucifer", "<p><b>Hello world</b>. I am Lucifer</p>")] | ||
// Italic | ||
[InlineData("Hello _world_", "<p>Hello <i>world</i></p>")] | ||
[InlineData("Hello _ world", "<p>Hello _ world</p>")] | ||
[InlineData("Hello _**_ world", "<p>Hello <i>**</i> world</p>")] | ||
[InlineData("Hello world. I am _Lu**ci_fer_", "<p>Hello world. I am <i>Lu**ci_fer</i></p>")] | ||
[InlineData("_Hello world_: I am Lucifer", "<p><i>Hello world</i>: I am Lucifer</p>")] | ||
// Monospace | ||
[InlineData("Hello `world`", "<p>Hello <tt>world</tt></p>")] | ||
[InlineData("Hello ` world", "<p>Hello ` world</p>")] | ||
[InlineData("Hello `**` world", "<p>Hello <tt>**</tt> world</p>")] | ||
[InlineData("Hello world. I am `Lu**ci`fer`", "<p>Hello world. I am <tt>Lu**ci`fer</tt></p>")] | ||
[InlineData("`Hello world`; I am Lucifer", "<p><tt>Hello world</tt>; I am Lucifer</p>")] | ||
// Preformatted text | ||
[InlineData("```\r\nHello world\r\n```", "<p><pre>\r\nHello world\r\n</pre></p>")] | ||
[InlineData("```\r\nHello _world_. _**_ I **am** `Lucifer`\r\n```", "<p><pre>\r\nHello _world_. _**_ I **am** `Lucifer`\r\n</pre></p>")] | ||
[InlineData("Hello\n\n\n```\r\nworld\n\n\n\nworld\r\n```", "<p>Hello</p>\n<p><pre>\r\nworld\n\n\n\nworld\r\n</pre></p>")] | ||
public void ConvertToHtml_WorksFine_IfMarkdownConvertedToHtmlCorrectly(string markdown, string expectedHtml) | ||
{ | ||
string actualHtml = markdown.ConvertToHtml(); | ||
|
||
actualHtml.Should().Be(expectedHtml); | ||
} | ||
|
||
[Theory] | ||
// Bold | ||
[InlineData("Hello **world ", "**world")] | ||
[InlineData("Hello ****world ", "****world")] | ||
[InlineData("Hello **** world ", "****")] | ||
// Italic | ||
[InlineData("Hello world_ ", "world_")] | ||
[InlineData("Hello _world ", "_world")] | ||
[InlineData("Hello __ world ", "__")] | ||
// Monospace | ||
[InlineData("Hello `world ", "`world")] | ||
[InlineData("Hello `` world ", "``")] | ||
public void ConvertToHtml_ThrowsInvalidOperationException_IfIncorrectNestedMarkup(string markdown, string expectedExceptionMessage) | ||
{ | ||
Assert.Throws<InvalidOperationException>(() => markdown.ConvertToHtml()). | ||
Message.Should().Be($"Not finished markup: {expectedExceptionMessage}"); | ||
} | ||
|
||
[Theory] | ||
[InlineData("**Hello _some_ world** ", "<b>Hello _some_ world</b>")] | ||
[InlineData("_Hello `some` world_ ", "<i>Hello `some` world</i>")] | ||
public void ConvertToHtml_ThrowsInvalidOperationException_IfNotFinishedMarkup(string markdown, string expectedExceptionMessage) | ||
{ | ||
Assert.Throws<InvalidOperationException>(() => markdown.ConvertToHtml()). | ||
Message.Should().Be($"Incorrect nested markup: {expectedExceptionMessage}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="xunit" Version="2.5.3" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\MarkdownParser.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
</Project> |