-
Notifications
You must be signed in to change notification settings - Fork 319
Головнев Максим #251
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
base: master
Are you sure you want to change the base?
Головнев Максим #251
Conversation
Планирую такую логику: - Текст на вход приходит в Lexer, где он переводится в List<Token> (список слов, пробелов, значащих символов) - List<Token> приходит в Parser, откуда приходит уже выровненный по структуре и иерархии корень дерева типа Node (дерево позволит нам определять вложенные теги) - Затем из этого дерева генерится html в HtmlGenerator
- Добавил проект с тестами и написал простые тесты на MdLexer.cs - Реализовал логику считывания токенов в MdLexer.cs (слова, #, _)
- Создал класс TokenParserTests.cs
- Дописал типы Node в NodeType - Дописал типы Token в TokenType - Убрал поле text из базовой ноды
- Написал базовую реализацию в декларативном стиле и без некоторой логики, поэтому не все тесты проходят
- добавил класс-раширение для List<MdToken> - более менее декомпозировал метод Parse - не работает условие с одинарными тегами внутри двойных/наоборот
- убрал некорректный тест в ListMdTokenTests.cs - сделал логику чтобы работало условие на вложенность Bold в Italic/наоборот - поправил тесты в TokenParserTests.cs
- написал HtmlGenerator.cs
- Пофиксил некорректное экранирование - Косметические правки
- дописал перфоманс тест
- убрал ref из GetLengthChainOfTokenTypeAfter
- правки по ListMdTokenExtension.cs
- переписал перформанс тест, теперь он не флокает - разбил функциональные тесты - пофиксил баг в IsUnderscoreInWordWithNumbers
| { | ||
| var markdown = GenerateRandomMarkdown(length); | ||
| sw.Start(); | ||
| GC.Collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нуууу такое, конечно. А между сборками мусора будет работать, как попало, да?
- дописал тестов на ранее неработающие сценарии - разбил TokenParser.cs на регионы для читаемости
- переписал тесты под нее
| [TestCase("# H1\n## H2\n### H3", "<h1>H1</h1><br/><h2>H2</h2><br/><h3>H3</h3>")] | ||
| [TestCase("# _text_ __text__", "<h1><em>text</em> <strong>text</strong></h1>")] | ||
| [TestCase(" ## h1", " ## h1")] | ||
| [TestCase("########### h1", "########### h1")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь лучше было использовать ровно семь гридов, чтобы показать границу числа гридов, начиная с которой другое поведение будет, т.е. подчеркнуть edge-case.
| [TestCase("# _text_ __text__", "<h1><em>text</em> <strong>text</strong></h1>")] | ||
| [TestCase(" ## h1", " ## h1")] | ||
| [TestCase("########### h1", "########### h1")] | ||
| [TestCase("#", "<h1></h1>")] // в оригинальном Md также |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В общем случае это не аргумент - "все совпадения случайны" :)
| [Test] | ||
| [TestCase("Text with _underscores_ inside", "Text with <em>underscores</em> inside")] | ||
| [TestCase("__Bold__ _Italic_ __Mixed__", "<strong>Bold</strong> <em>Italic</em> <strong>Mixed</strong>")] | ||
| [TestCase("root1_2_3", "root1_2_3")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | ||
|
|
||
| [Test] | ||
| [TestCase(@"Escaped \_underscore\_", "Escaped _underscore_")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Существует, скажем так, правило хорошего тона - ишуи резолвит тот, кто их завёл.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Существует, скажем так, правило хорошего тона - ишуи резолвит тот, кто их завёл.
понял, просто удобно, проще понимать что сделал/что нет
|
|
||
| [Test] | ||
| [TestCase("TEXT!???", "TEXT!???")] | ||
| [TestCase("_Test_\n## Header ##\n__word__ _word_", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n - эх, проворонил такой повод подушнить :( На будущее - используй лучше Environment.NewLine, в разных системах оно разное значение имеет.
| var markdown = GenerateRandomMarkdown(length); | ||
| sw.Start(); | ||
| Render(markdown); | ||
| GC.Collect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ну уж если хватило сил все замечания исправить, мог бы и эту ерунду поправить :)
| [TestCase(@"\\[text](example.com)", """\<a href="example.com">text</a>""")] | ||
| [TestCase(@"Escaped _underscore\__", "Escaped <em>underscore_</em>")] | ||
| [TestCase(@"[text\\](example.com)", """<a href="example.com">text\</a>""")] | ||
| [TestCase("_underscore _", "_underscore _")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.


Планирую такую логику: