-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
397 additions
and
2 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,74 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace UnitTest.Base.Utils | ||
{ | ||
public static class TextUtil | ||
{ | ||
public static string HereDoc(string value) | ||
{ | ||
// like PHP's flexible_heredoc_nowdoc_syntaxes, | ||
// The indentation of the closing tag dictates | ||
// the amount of whitespace to strip from each line | ||
var lines = Regex.Split(value, "\r\n|\r|\n", RegexOptions.Multiline); | ||
|
||
// count last line indent | ||
int lastIdtCnt = TextUtil.CountIndent(lines.Last()); | ||
// count full indent | ||
int someIdtCnt = lines | ||
.Where(line => !String.IsNullOrWhiteSpace(line)) | ||
.Select(line => TextUtil.CountIndent(line)) | ||
.Min(); | ||
|
||
var indentCount = Math.Max(lastIdtCnt, someIdtCnt); | ||
|
||
return String.Join( | ||
"\n", | ||
lines | ||
// skip first blank line | ||
.Skip(String.IsNullOrWhiteSpace(lines[0]) ? 1 : 0) | ||
// strip indent | ||
.Select(line => | ||
{ | ||
var realIdx = 0; | ||
var viewIdx = 0; | ||
|
||
while (viewIdx < indentCount && realIdx < line.Length) | ||
{ | ||
var c = line[realIdx]; | ||
if (c == ' ') | ||
{ | ||
realIdx += 1; | ||
viewIdx += 1; | ||
} | ||
else if (c == '\t') | ||
{ | ||
realIdx += 1; | ||
viewIdx = ((viewIdx >> 2) + 1) << 2; | ||
} | ||
else break; | ||
} | ||
|
||
return line.Substring(realIdx); | ||
}) | ||
); | ||
} | ||
|
||
private static int CountIndent(string line) | ||
{ | ||
var count = 0; | ||
foreach (var c in line) | ||
{ | ||
if (c == ' ') count += 1; | ||
else if (c == '\t') | ||
{ | ||
// In default in vs, tab is treated as four-spaces. | ||
count = ((count >> 2) + 1) << 2; | ||
} | ||
else break; | ||
} | ||
return count; | ||
} | ||
} | ||
} |
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
141 changes: 141 additions & 0 deletions
141
.../UnitTest.Md/Out/UnitTestMd.Transform_givenContainer_generatesExpectedResult.approved.txt
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,141 @@ | ||
<?xml version="1.0" encoding="utf-16"?> | ||
<StackPanel xmlns:c="clr-namespace:ColorTextBlock.Avalonia;assembly=ColorTextBlock.Avalonia" xmlns:m="clr-namespace:Markdown.Avalonia.Controls;assembly=Markdown.Avalonia" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns="https://github.com/avaloniaui"> | ||
<Border Classes="CodeBlock,NoContainer" xmlns=""> | ||
<Border.Child> | ||
<ScrollViewer Classes="CodeBlock"> | ||
<ScrollViewer.Content> | ||
<TextBlock Text="::::
:::cs
public void Main(){
 Console.WriteLine(":Hello World:");
}
:::
::::

" Classes="CodeBlock" /> | ||
</ScrollViewer.Content> | ||
</ScrollViewer> | ||
</Border.Child> | ||
</Border> | ||
<Border Classes="CodeBlock,NoContainer" xmlns=""> | ||
<Border.Child> | ||
<ScrollViewer Classes="CodeBlock"> | ||
<ScrollViewer.Content> | ||
<TextBlock Text=":::
public void Main(){
 Console.WriteLine(":Hello World:");
}
:::

" Classes="CodeBlock" /> | ||
</ScrollViewer.Content> | ||
</ScrollViewer> | ||
</Border.Child> | ||
</Border> | ||
<Border Classes="Blockquote" xmlns=""> | ||
<Border.Child> | ||
<StackPanel Classes="Blockquote"> | ||
<Border Classes="CodeBlock,NoContainer"> | ||
<Border.Child> | ||
<ScrollViewer Classes="CodeBlock"> | ||
<ScrollViewer.Content> | ||
<TextBlock Text=":::
public void Main(){
 Console.WriteLine(":Hello World:");
}
:::
" Classes="CodeBlock" /> | ||
</ScrollViewer.Content> | ||
</ScrollViewer> | ||
</Border.Child> | ||
</Border> | ||
</StackPanel> | ||
</Border.Child> | ||
</Border> | ||
<Border Classes="CodeBlock,NoContainer" xmlns=""> | ||
<Border.Child> | ||
<ScrollViewer Classes="CodeBlock"> | ||
<ScrollViewer.Content> | ||
<TextBlock Text=" :::
 public void Main(){
 Console.WriteLine(":Hello World:");
 }
 :::


" Classes="CodeBlock" /> | ||
</ScrollViewer.Content> | ||
</ScrollViewer> | ||
</Border.Child> | ||
</Border> | ||
<Border Classes="CodeBlock" xmlns=""> | ||
<Border.Child> | ||
<ScrollViewer Classes="CodeBlock"> | ||
<ScrollViewer.Content> | ||
<TextBlock Text=":::cs
public void Main(){
 Console.WriteLine(":Hello World:");
}
:::" Classes="CodeBlock" /> | ||
</ScrollViewer.Content> | ||
</ScrollViewer> | ||
</Border.Child> | ||
</Border> | ||
<Grid Classes="List" xmlns=""> | ||
<c:CTextBlock Classes="ListMarker" Grid.Column="0" Grid.Row="0"> | ||
<c:CRun Text="•" /> | ||
</c:CTextBlock> | ||
<StackPanel Grid.Column="1" Grid.Row="0"> | ||
<Border Classes="CodeBlock,NoContainer"> | ||
<Border.Child> | ||
<ScrollViewer Classes="CodeBlock"> | ||
<ScrollViewer.Content> | ||
<TextBlock Text=":::
public void Main(){









}
:::
" Classes="CodeBlock" /> | ||
</ScrollViewer.Content> | ||
</ScrollViewer> | ||
</Border.Child> | ||
</Border> | ||
</StackPanel> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
<ColumnDefinition /> | ||
</Grid.ColumnDefinitions> | ||
<Grid.RowDefinitions> | ||
<RowDefinition /> | ||
</Grid.RowDefinitions> | ||
</Grid> | ||
<m:Rule BoldLineWidth="2" Classes="Bold" /> | ||
<Grid Classes="List" xmlns=""> | ||
<c:CTextBlock Classes="ListMarker" Grid.Column="0" Grid.Row="0"> | ||
<c:CRun Text="▪" /> | ||
</c:CTextBlock> | ||
<StackPanel Grid.Column="1" Grid.Row="0"> | ||
<c:CTextBlock Classes="Paragraph"> | ||
<c:CRun Text="one" /> | ||
</c:CTextBlock> | ||
<Border Classes="CodeBlock,NoContainer"> | ||
<Border.Child> | ||
<ScrollViewer Classes="CodeBlock"> | ||
<ScrollViewer.Content> | ||
<TextBlock Text=":::
public void Main(){









}
:::
" Classes="CodeBlock" /> | ||
</ScrollViewer.Content> | ||
</ScrollViewer> | ||
</Border.Child> | ||
</Border> | ||
</StackPanel> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
<ColumnDefinition /> | ||
</Grid.ColumnDefinitions> | ||
<Grid.RowDefinitions> | ||
<RowDefinition /> | ||
</Grid.RowDefinitions> | ||
</Grid> | ||
<m:Rule BoldLineWidth="2" Classes="TwoLines" /> | ||
<Grid Classes="List" xmlns=""> | ||
<c:CTextBlock Classes="ListMarker" Grid.Column="0" Grid.Row="0"> | ||
<c:CRun Text="1." /> | ||
</c:CTextBlock> | ||
<StackPanel Grid.Column="1" Grid.Row="0"> | ||
<c:CTextBlock Classes="Paragraph"> | ||
<c:CRun Text="one" /> | ||
</c:CTextBlock> | ||
<Border Classes="CodeBlock,NoContainer"> | ||
<Border.Child> | ||
<ScrollViewer Classes="CodeBlock"> | ||
<ScrollViewer.Content> | ||
<TextBlock Text=":::
public void Main(){









}
:::
" Classes="CodeBlock" /> | ||
</ScrollViewer.Content> | ||
</ScrollViewer> | ||
</Border.Child> | ||
</Border> | ||
</StackPanel> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
<ColumnDefinition /> | ||
</Grid.ColumnDefinitions> | ||
<Grid.RowDefinitions> | ||
<RowDefinition /> | ||
</Grid.RowDefinitions> | ||
</Grid> | ||
<m:Rule BoldLineWidth="2" Classes="TwoLines" /> | ||
<Border Classes="CodeBlock,NoContainer" xmlns=""> | ||
<Border.Child> | ||
<ScrollViewer Classes="CodeBlock"> | ||
<ScrollViewer.Content> | ||
<TextBlock Text="::: md

* list1
* list2

```cs
#define FooBar
```
:::


" Classes="CodeBlock" /> | ||
</ScrollViewer.Content> | ||
</ScrollViewer> | ||
</Border.Child> | ||
</Border> | ||
</StackPanel> |
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,93 @@ | ||
:::: | ||
:::cs | ||
public void Main(){ | ||
Console.WriteLine(":Hello World:"); | ||
} | ||
::: | ||
:::: | ||
|
||
::: | ||
public void Main(){ | ||
Console.WriteLine(":Hello World:"); | ||
} | ||
::: | ||
|
||
> ::: | ||
> public void Main(){ | ||
> Console.WriteLine(":Hello World:"); | ||
> } | ||
> ::: | ||
::: | ||
public void Main(){ | ||
Console.WriteLine(":Hello World:"); | ||
} | ||
::: | ||
|
||
|
||
:::cs | ||
public void Main(){ | ||
Console.WriteLine(":Hello World:"); | ||
} | ||
::: | ||
|
||
* ::: | ||
public void Main(){ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
::: | ||
|
||
* * * | ||
|
||
+ one | ||
::: | ||
public void Main(){ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
::: | ||
|
||
= = = | ||
|
||
1. one | ||
|
||
::: | ||
public void Main(){ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
::: | ||
|
||
=== | ||
|
||
::: md | ||
|
||
* list1 | ||
* list2 | ||
|
||
```cs | ||
#define FooBar | ||
``` | ||
::: |
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
Oops, something went wrong.