Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Савенко Дмитрий #228

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion MarkdownSpec.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ __Непарные_ символы в рамках одного абзаца н

превратится в:

\<h1>Заголовок \<strong>с \<em>разными\</em> символами\</strong>\</h1>
\<h1>Заголовок \<strong>с \<em>разными\</em> символами\</strong>\</h1>



# Ссылка

Текст, оформленный в виде [текст ссылки](URL), должен превращаться в HTML-тег <a> вот так:
[пример ссылки](https://example.com)

превратится в:
<a href="https://example.com">пример ссылки</a>
25 changes: 25 additions & 0 deletions cs/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
191 changes: 191 additions & 0 deletions cs/MarkDownTest/MarkDownConverterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
using FluentAssertions;
using Markdown;
using Markdown.interfaces;
using NUnit.Framework;

namespace MarkDownTest;

public class MarkdownConverterTests
{
private IMarkdownConverter _converter;

[SetUp]
public void Setup()
{
_converter = new MarkdownConverter();
}

[Test]
public void Convert_TextOnly_ShouldReturnPlainText()
{
var tokens = new List<Token>
{
Token.CreateText("Hello, World!", 0)
};

var result = _converter.Convert(tokens);

result.Should().Be("Hello, World!");
}

[Test]
public void Convert_StrongText_ShouldReturnStrongHtml()
{
var tokens = new List<Token>
{
Token.CreateStrong(true, 0),
Token.CreateText("bold", 2),
Token.CreateStrong(false, 6)
};

var result = _converter.Convert(tokens);

result.Should().Be("<strong>bold</strong>");
}

[Test]
public void Convert_ItalicText_ShouldReturnItalicHtml()
{
var tokens = new List<Token>
{
Token.CreateItalic(true, 0),
Token.CreateText("italic", 1),
Token.CreateItalic(false, 7)
};

var result = _converter.Convert(tokens);

result.Should().Be("<em>italic</em>");
}

[Test]
public void Convert_StrongAndItalicNested_ShouldReturnNestedHtml()
{
var tokens = new List<Token>
{
Token.CreateStrong(true, 0),
Token.CreateText("bold ", 2),
Token.CreateItalic(true, 7),
Token.CreateText("italic", 8),
Token.CreateItalic(false, 14),
Token.CreateText(" bold", 15),
Token.CreateStrong(false, 20)
};

var result = _converter.Convert(tokens);

result.Should().Be("<strong>bold <em>italic</em> bold</strong>");
}

[Test]
public void Convert_Header_ShouldReturnHeaderHtml()
{
var tokens = new List<Token>
{
Token.CreateHeader(2, 0),
Token.CreateText("Header Text", 2),
new Token("", TokenType.Header, TagState.Close, 13, 2)
};

var result = _converter.Convert(tokens);

result.Should().Be("<h2>Header Text</h2>");
}

[Test]
public void Convert_HeaderWithFormatting_ShouldReturnFormattedHeaderHtml()
{
var tokens = new List<Token>
{
Token.CreateHeader(1, 0),
Token.CreateText("Welcome to ", 1),
Token.CreateItalic(true, 12),
Token.CreateText("Markdown", 13),
Token.CreateItalic(false, 21),
new Token("", TokenType.Header, TagState.Close, 22, 1)
};

var result = _converter.Convert(tokens);

result.Should().Be("<h1>Welcome to <em>Markdown</em></h1>");
}

[Test]
public void Convert_IncorrectClosingTag_ShouldAddAsText()
{
var tokens = new List<Token>
{
Token.CreateStrong(true, 0),
Token.CreateText("bold ", 2),
Token.CreateItalic(true, 7),
Token.CreateText("italic", 8),
Token.CreateStrong(false, 14),
Token.CreateText(" text_", 16)
};

var result = _converter.Convert(tokens);


result.Should().Be("<strong>bold <em>italic__ text_</em></strong>");
}

[Test]
public void Convert_UnmatchedClosingTag_ShouldAddAsText()
{
var tokens = new List<Token>
{
Token.CreateItalic(false, 0),
Token.CreateText("text_", 1)
};

var result = _converter.Convert(tokens);

result.Should().Be("_text_");
}

[Test]
public void Convert_UnclosedTags_ShouldCloseRemainingTags()
{
var tokens = new List<Token>
{
Token.CreateStrong(true, 0),
Token.CreateText("bold", 2)
};

var result = _converter.Convert(tokens);

result.Should().Be("<strong>bold</strong>");
}

[Test]
public void Convert_Link_ShouldReturnLinkHtml()
{
var tokens = new List<Token>
{
Token.CreateLink("пример ссылки", "https://example.com", 0)
};

var result = _converter.Convert(tokens);

result.Should().Be("<a href=\"https://example.com\">пример ссылки</a>");
}


[Test]
public void Convert_StrongTextWithLink_ShouldReturnCorrectHtml()
{
var tokens = new List<Token>
{
Token.CreateStrong(true, 0),
Token.CreateText("Посетите ", 2),
Token.CreateLink("сайт", "https://example.com", 11),
Token.CreateStrong(false, 31)
};

var result = _converter.Convert(tokens);

result.Should().Be("<strong>Посетите <a href=\"https://example.com\">сайт</a></strong>");
}


}
25 changes: 25 additions & 0 deletions cs/MarkDownTest/MarkDownTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<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="FluentAssertions" Version="7.0.0-alpha.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="NUnit" Version="3.13.3"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1"/>
<PackageReference Include="NUnit.Analyzers" Version="3.6.1"/>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Markdown\Markdown.csproj" />
</ItemGroup>

</Project>
Loading