Skip to content

Commit

Permalink
add test for containerblock
Browse files Browse the repository at this point in the history
  • Loading branch information
whistyun committed Nov 11, 2021
1 parent fa36aa3 commit 7482360
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 2 deletions.
74 changes: 74 additions & 0 deletions tests/UnitTest.Base/Utils/TextUtil.cs
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;
}
}
}
18 changes: 16 additions & 2 deletions tests/UnitTest.Base/Utils/Util.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Avalonia.Controls;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -16,7 +18,7 @@ public static string[] GetTextNames()

return caller.GetManifestResourceNames()
.Where(nm => nm.StartsWith(resourceKey))
.Select(nm=>nm.Substring(resourceKey.Length))
.Select(nm => nm.Substring(resourceKey.Length))
.ToArray();
}

Expand Down Expand Up @@ -89,5 +91,17 @@ public static string GetRuntimeName()

return "dotnet";
}

public static IEnumerable<T> FindControlsByClassName<T>(IControl ctrl, string classNm) where T : IControl
{
if (ctrl.Classes.Contains(classNm))
yield return (T)ctrl;

if (ctrl is Panel panel)
{
foreach (var rs in panel.Children.SelectMany(p => FindControlsByClassName<T>(p, classNm)))
yield return rs;
}
}
}
}
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="::::&#xA;:::cs&#xA;public void Main(){&#xA; Console.WriteLine(&quot;:Hello World:&quot;);&#xA;}&#xA;:::&#xA;::::&#xA;&#xA;" Classes="CodeBlock" />
</ScrollViewer.Content>
</ScrollViewer>
</Border.Child>
</Border>
<Border Classes="CodeBlock,NoContainer" xmlns="">
<Border.Child>
<ScrollViewer Classes="CodeBlock">
<ScrollViewer.Content>
<TextBlock Text=":::&#xA;public void Main(){&#xA; Console.WriteLine(&quot;:Hello World:&quot;);&#xA;}&#xA;:::&#xA;&#xA;" 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=":::&#xA;public void Main(){&#xA; Console.WriteLine(&quot;:Hello World:&quot;);&#xA;}&#xA;:::&#xA;" 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=" :::&#xA; public void Main(){&#xA; Console.WriteLine(&quot;:Hello World:&quot;);&#xA; }&#xA; :::&#xA;&#xA;&#xA;" Classes="CodeBlock" />
</ScrollViewer.Content>
</ScrollViewer>
</Border.Child>
</Border>
<Border Classes="CodeBlock" xmlns="">
<Border.Child>
<ScrollViewer Classes="CodeBlock">
<ScrollViewer.Content>
<TextBlock Text=":::cs&#xA;public void Main(){&#xA; Console.WriteLine(&quot;:Hello World:&quot;);&#xA;}&#xA;:::" 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=":::&#xA;public void Main(){&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;}&#xA;:::&#xA;" 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=":::&#xA;public void Main(){&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;}&#xA;:::&#xA;" 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=":::&#xA;public void Main(){&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;}&#xA;:::&#xA;" 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&#xA;&#xA;* list1&#xA;* list2&#xA;&#xA;```cs&#xA;#define FooBar&#xA;```&#xA;:::&#xA;&#xA;&#xA;" Classes="CodeBlock" />
</ScrollViewer.Content>
</ScrollViewer>
</Border.Child>
</Border>
</StackPanel>
93 changes: 93 additions & 0 deletions tests/UnitTest.Md/Texts/ContainerBlock.md
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
```
:::
1 change: 1 addition & 0 deletions tests/UnitTest.Md/UnitTest.Md.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<ItemGroup>
<None Remove="Texts\Codes.md" />
<None Remove="Texts\ContainerBlock.md" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 7482360

Please sign in to comment.