Browse Source

Fix BamlTestRunner

pull/728/merge
Siegfried Pammer 9 years ago
parent
commit
4df6c53419
  1. 29
      ICSharpCode.Decompiler/Tests/Helpers/CodeAssert.cs
  2. 19
      ILSpy.BamlDecompiler/Tests/BamlTestRunner.cs
  3. 2
      ILSpy.BamlDecompiler/Tests/Cases/Issue445.xaml

29
ICSharpCode.Decompiler/Tests/Helpers/CodeAssert.cs

@ -6,27 +6,30 @@ using NUnit.Framework; @@ -6,27 +6,30 @@ using NUnit.Framework;
namespace ICSharpCode.Decompiler.Tests.Helpers
{
public class CodeAssert
public static class CodeAssert
{
public static void FilesAreEqual(string fileName1, string fileName2)
{
AreEqual(File.ReadAllText(fileName1), File.ReadAllText(fileName2));
}
public static void AreEqual(string input1, string input2)
{
var diff = new StringWriter();
if (!Compare(input1, input2, diff)) {
if (!CodeComparer.Compare(input1, input2, diff, CodeComparer.NormalizeLine)) {
Assert.Fail(diff.ToString());
}
}
}
static bool Compare(string input1, string input2, StringWriter diff)
public static class CodeComparer
{
public static bool Compare(string input1, string input2, StringWriter diff, Func<string, string> normalizeLine)
{
var differ = new AlignedDiff<string>(
NormalizeAndSplitCode(input1),
NormalizeAndSplitCode(input2),
new CodeLineEqualityComparer(),
new CodeLineEqualityComparer(normalizeLine),
new StringSimilarityComparer(),
new StringAlignmentFilter());
@ -71,12 +74,18 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -71,12 +74,18 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
class CodeLineEqualityComparer : IEqualityComparer<string>
{
private IEqualityComparer<string> baseComparer = EqualityComparer<string>.Default;
private Func<string, string> normalizeLine;
public CodeLineEqualityComparer(Func<string, string> normalizeLine)
{
this.normalizeLine = normalizeLine;
}
public bool Equals(string x, string y)
{
return baseComparer.Equals(
NormalizeLine(x),
NormalizeLine(y)
normalizeLine(x),
normalizeLine(y)
);
}
@ -86,13 +95,13 @@ namespace ICSharpCode.Decompiler.Tests.Helpers @@ -86,13 +95,13 @@ namespace ICSharpCode.Decompiler.Tests.Helpers
}
}
private static string NormalizeLine(string line)
public static string NormalizeLine(string line)
{
line = line.Trim();
var index = line.IndexOf("//");
var index = line.IndexOf("//", StringComparison.Ordinal);
if (index >= 0) {
return line.Substring(0, index);
} else if (line.StartsWith("#")) {
} else if (line.StartsWith("#", StringComparison.Ordinal)) {
return string.Empty;
} else {
return line;

19
ILSpy.BamlDecompiler/Tests/BamlTestRunner.cs

@ -64,7 +64,7 @@ namespace ILSpy.BamlDecompiler.Tests @@ -64,7 +64,7 @@ namespace ILSpy.BamlDecompiler.Tests
{
RunTest("cases/dictionary1");
}
[Test]
public void MarkupExtension()
{
@ -110,9 +110,22 @@ namespace ILSpy.BamlDecompiler.Tests @@ -110,9 +110,22 @@ namespace ILSpy.BamlDecompiler.Tests
Assert.IsNotNull(bamlStream);
XDocument document = BamlResourceEntryNode.LoadIntoDocument(resolver, assembly, bamlStream);
CodeAssert.AreEqual(File.ReadAllText(sourcePath), document.ToString());
XamlIsEqual(File.ReadAllText(sourcePath), document.ToString());
}
void XamlIsEqual(string input1, string input2)
{
var diff = new StringWriter();
if (!CodeComparer.Compare(input1, input2, diff, NormalizeLine)) {
Assert.Fail(diff.ToString());
}
}
string NormalizeLine(string line)
{
return line.Trim();
}
Stream LoadBaml(Resource res, string name)
{
EmbeddedResource er = res as EmbeddedResource;

2
ILSpy.BamlDecompiler/Tests/Cases/Issue445.xaml

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
<UserControl x:Class="BamlTest.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d">
<UserControl x:Class="BamlTest.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Resources>
<Style x:Key="baseStyle" TargetType="{x:Type Control}" />
</UserControl.Resources>

Loading…
Cancel
Save