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

Шевырин Никита #229

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
883f607
created project Markdown
alexadralt Nov 23, 2024
c1f6b4d
initial design
alexadralt Nov 24, 2024
09601ae
initial design
alexadralt Nov 30, 2024
f27204e
added ArgumentExceptionHelpers
alexadralt Nov 30, 2024
bc62038
implemented abstract syntax tree
alexadralt Nov 30, 2024
f0d106e
did some syntax tree testing
alexadralt Nov 30, 2024
106f113
tokenizer WIP
alexadralt Dec 2, 2024
8de5081
addded tests for Md
alexadralt Dec 2, 2024
6e53af2
deleted tree tests
alexadralt Dec 2, 2024
b67b916
added usage example
alexadralt Dec 2, 2024
ae81615
implementation WIP 1
alexadralt Nov 30, 2024
9005981
renamed IMdTest to IMdTests
alexadralt Dec 4, 2024
1ef1aa0
renamed files for refactoring
alexadralt Dec 6, 2024
887266f
refactored the whole thing
alexadralt Dec 7, 2024
5be7d46
added nesting syntax rule
alexadralt Dec 7, 2024
90e83aa
refactored nesting rule
alexadralt Dec 8, 2024
f106f80
added new syntax rules and fixed potential bugs
alexadralt Dec 8, 2024
8b6a4d8
added descriptions to tests
alexadralt Dec 8, 2024
8efaaf3
deleted files with old version of existing code
alexadralt Dec 8, 2024
8549226
removed old files
alexadralt Dec 8, 2024
b5df139
merged version 1.0
alexadralt Dec 8, 2024
f298b01
deleted old files
alexadralt Dec 8, 2024
9f42573
added factory method for Md
alexadralt Dec 11, 2024
75251ad
refactored MdTokenizer
alexadralt Dec 11, 2024
262d9a2
refactored syntax rules
alexadralt Dec 11, 2024
f7be964
moved private fields declarations
alexadralt Dec 14, 2024
96b2796
moved performance tests to a different project and added more test cases
alexadralt Dec 14, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

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

</Project>
55 changes: 55 additions & 0 deletions Markdown/Markdown.PerformanceTests/MdPerformanceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Text;
using FluentAssertions;
using NUnit.Framework;

namespace Markdown.PerformanceTests;

[TestFixture]
public class MdPerformanceTests
{
private IRenderer _mdRenderer;
private PerformanceMeasurer _measurer;

[SetUp]
public void SetUp()
{
_mdRenderer = DefaultMdFactory.CreateMd();
_measurer = new PerformanceMeasurer(Console.WriteLine);
}

[Test]
[TestCase("Hello _world_!\n", 18000)]
[TestCase("# _Hello_\n __world__!\n", 9000)]
[TestCase("This __text _contains_ nested__ markdown\n", 10000)]
[TestCase("This is _an example __of inversed__ nested_ markdown\n", 8000)]
[TestCase("Text_12_3\n", 15000)]
[TestCase("Text __that_12_3__ is in bold\n", 10000)]
[TestCase("_begin_ning\n", 20000)]
[TestCase("end_ing_\n", 20000)]
[TestCase("mi__ddl__e\n", 15000)]
[TestCase("This sh_ould not cha_nge\n", 10000)]
[TestCase("This sh__o_uld_ wo__rk like this\n", 9000)]
[TestCase("__Unpaired_ markdown\n", 20000)]
[TestCase("Another _unpaired markdown__\n", 18000)]
[TestCase("Intersecting _markdown __should_ work__ like this\n", 10000)]
[TestCase("This should ____ remain the same\n", 15000)]
[TestCase(@"This should \_not turn\_ into tags", 20000)]
[TestCase(@"This should \remain the\ same", 20000)]
public void PerformanceTest(string testInput, int stringRepetitions)
{
var str = ArrangePerformanceTest(testInput, stringRepetitions);
Console.WriteLine($"Total length: {str.Length}");

_measurer.MeasureAverageTime(() => _mdRenderer.Render(str), 10)
.Should()
.BeLessOrEqualTo(1000);
}

private string ArrangePerformanceTest(string input, int copyCount)
{
var sb = new StringBuilder();
for (var i = 0; i < copyCount; i++)
sb.Append(input);
return sb.ToString();
}
}
20 changes: 20 additions & 0 deletions Markdown/Markdown.Tests/Markdown.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

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

</Project>
155 changes: 155 additions & 0 deletions Markdown/Markdown.Tests/MdTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using FluentAssertions;
using NUnit.Framework;

namespace Markdown.Tests;

[TestFixture]
[TestOf(typeof(Md))]
public class MdTests
{
private IRenderer _md;

[SetUp]
public void SetUp()
{
_md = DefaultMdFactory.CreateMd();
}

[Test]
[Description("Базовые тесты")]
[TestCase("", "")]
[TestCase("Hello world", "Hello world")]
[TestCase("Hello _world_!", "Hello <em>world</em>!")]
[TestCase("# _Hello_ __world__!", "<h1><em>Hello</em> <strong>world</strong>!</h1>")]
public void Render_ReturnsCorrectMarkdown_ForSimpleCases(
string input,
string expectedOutput)
{
_md.Render(input)
.Should()
.Be(expectedOutput);
}

[Test]
[Description("Тесты на вложенность двойного и одинарного выделения")]
[TestCase("This __text _contains_ nested__ markdown", "This <strong>text <em>contains</em> nested</strong> markdown")]
[TestCase("This is _an example __of inversed__ nested_ markdown", "This is <em>an example __of inversed__ nested</em> markdown")]
public void Render_ReturnsCorrectMarkdown_ForCasesWithNesting(
string input,
string expectedOutput)
{
_md.Render(input)
.Should()
.Be(expectedOutput);
}

[Test]
[Description("Тесты для разметки внутри текста с цифрами")]
[TestCase("Text_12_3", "Text_12_3")]
[TestCase("5__12_3__4", "5__12_3__4")]
[TestCase("Text __that_12_3__ is in bold", "Text <strong>that_12_3</strong> is in bold")]
public void Render_ReturnsCorrectMarkdown_ForTextWithNumbers(
string input,
string expectedOutput)
{
_md.Render(input)
.Should()
.Be(expectedOutput);
}

[Test]
[Description("Тесты для разметки внутри слов")]
[TestCase("_begin_ning", "<em>begin</em>ning")]
[TestCase("mi_ddl_e", "mi<em>ddl</em>e")]
[TestCase("end_ing_", "end<em>ing</em>")]
[TestCase("__begin__ning", "<strong>begin</strong>ning")]
[TestCase("mi__ddl__e", "mi<strong>ddl</strong>e")]
[TestCase("end__ing__", "end<strong>ing</strong>")]
public void Render_ReturnsCorrectMarkdown_ForPartsOfWords(
string input,
string expectedOutput)
{
_md.Render(input)
.Should()
.Be(expectedOutput);
}

[Test]
[Description("Тесты для подчерков, находящихся внутри разных слов")]
[TestCase("This sh_ould not cha_nge", "This sh_ould not cha_nge")]
[TestCase("As w__ell a__s this", "As w__ell a__s this")]
[TestCase("This sh__o_uld_ wo__rk like this", "This sh__o<em>uld</em> wo__rk like this")]
public void Render_ReturnsCorrectMarkdown_ForMarkdownInDifferentWords(
string input,
string expectedOutput)
{
_md.Render(input)
.Should()
.Be(expectedOutput);
}

[Test]
[Description("Тесты для непарных символов разметки")]
[TestCase("__Unpaired_ markdown", "__Unpaired_ markdown")]
[TestCase("Another _unpaired markdown__", "Another _unpaired markdown__")]
public void Render_ReturnsCorrectMarkdown_ForUnpairedMarkdownSymbols(
string input,
string expectedOutput)
{
_md.Render(input)
.Should()
.Be(expectedOutput);
}

[Test]
[Description("Проверяем, что подчерки должны следовать за (стоять перед) непробельным символом")]
[TestCase("This_ should not_ change", "This_ should not_ change")]
[TestCase("This _should _be in_ italics", "This <em>should _be in</em> italics")]
public void Render_ReturnsCorrectMarkdown_ForIncorrectlyPlacedUnderscores(
string input,
string expectedOutput)
{
_md.Render(input)
.Should()
.Be(expectedOutput);
}

[Test]
[Description("Тесты на пересечение двойных и одинарных подчерков")]
[TestCase("Intersecting _markdown __should_ work__ like this", "Intersecting _markdown __should_ work__ like this")]
[TestCase("Another __example of _intersecting__ markdown_", "Another __example of _intersecting__ markdown_")]
public void Render_ReturnsCorrectMarkdown_ForIntersectingMarkdown(
string input,
string expectedOutput)
{
_md.Render(input)
.Should()
.Be(expectedOutput);
}

[Test]
[Description("Тесты на пустую разметку")]
[TestCase("This should ____ remain the same", "This should ____ remain the same")]
[TestCase("This also should __ not change", "This also should __ not change")]
public void Render_ReturnsCorrectMarkdown_ForEmptyMarkdown(
string input,
string expectedOutput)
{
_md.Render(input)
.Should()
.Be(expectedOutput);
}

[Test]
[Description("Тесты на экранирование")]
[TestCase(@"This should \_not turn\_ into tags", "This should _not turn_ into tags")]
[TestCase(@"This should \remain the\ same", @"This should \remain the\ same")]
public void Render_ReturnsCorrectMarkdown_ForEscapeCharacters(
string input,
string expectedOutput)
{
_md.Render(input)
.Should()
.Be(expectedOutput);
}
}
28 changes: 28 additions & 0 deletions Markdown/Markdown.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Markdown", "Markdown\Markdown.csproj", "{B8FD8A48-C2C3-434B-953F-B9AF324E3E95}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Markdown.Tests", "Markdown.Tests\Markdown.Tests.csproj", "{0B1D2315-E457-4F38-92C9-5BC11A8752B6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Markdown.PerformanceTests", "Markdown.PerformanceTests\Markdown.PerformanceTests.csproj", "{C030F3F2-BED4-42E7-830A-63B3A7541B4C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B8FD8A48-C2C3-434B-953F-B9AF324E3E95}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8FD8A48-C2C3-434B-953F-B9AF324E3E95}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8FD8A48-C2C3-434B-953F-B9AF324E3E95}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8FD8A48-C2C3-434B-953F-B9AF324E3E95}.Release|Any CPU.Build.0 = Release|Any CPU
{0B1D2315-E457-4F38-92C9-5BC11A8752B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B1D2315-E457-4F38-92C9-5BC11A8752B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B1D2315-E457-4F38-92C9-5BC11A8752B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B1D2315-E457-4F38-92C9-5BC11A8752B6}.Release|Any CPU.Build.0 = Release|Any CPU
{C030F3F2-BED4-42E7-830A-63B3A7541B4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C030F3F2-BED4-42E7-830A-63B3A7541B4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C030F3F2-BED4-42E7-830A-63B3A7541B4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C030F3F2-BED4-42E7-830A-63B3A7541B4C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Markdown.NodeView;

namespace Markdown.AbstractSyntaxTree;

public record AbstractSyntaxTreeNodeView<TTokenType>(
ReadOnlyMemory<char> Text,
TTokenType TokenType)
: BaseNodeView<TTokenType>;
11 changes: 11 additions & 0 deletions Markdown/Markdown/AbstractSyntaxTree/IAbstractSyntaxTree.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Markdown.NodeView;
using Markdown.SyntaxRules;
using Markdown.Traversable;

namespace Markdown.AbstractSyntaxTree;

public interface IAbstractSyntaxTree<TTokenType> : ITraversable<BaseNodeView<TTokenType>>
{
public IAbstractSyntaxTree<TTokenType> AddRule(ISyntaxRule<TTokenType> rule);
public IAbstractSyntaxTree<TTokenType> ApplyRules();
}
Loading