Skip to content

Commit

Permalink
Fixed unit tests by using UNIX line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Jun 30, 2015
1 parent c8eb186 commit 5967da4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
27 changes: 16 additions & 11 deletions UnitTests/EncoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ public void TestBase64Decode ()
public void TestBase64Encode ()
{
using (var original = new MemoryStream ()) {
using (var file = File.OpenRead ("../../TestData/encoders/photo.b64"))
file.CopyTo (original, 4096);
using (var file = File.OpenRead ("../../TestData/encoders/photo.b64")) {
using (var filtered = new FilteredStream (original)) {
filtered.Add (new Dos2UnixFilter ());
file.CopyTo (filtered, 4096);
filtered.Flush ();
}
}

using (var encoded = new MemoryStream ()) {
using (var filtered = new FilteredStream (encoded)) {
filtered.Add (EncoderFilter.Create (ContentEncoding.Base64));
filtered.Add (FormatOptions.Default.CreateNewLineFilter ());

using (var file = File.OpenRead ("../../TestData/encoders/photo.jpg"))
file.CopyTo (filtered, 4096);
Expand Down Expand Up @@ -129,20 +133,22 @@ public void TestUUDecode ()
public void TestUUEncode ()
{
using (var original = new MemoryStream ()) {
using (var file = File.OpenRead ("../../TestData/encoders/photo.uu"))
file.CopyTo (original, 4096);
using (var file = File.OpenRead ("../../TestData/encoders/photo.uu")) {
using (var filtered = new FilteredStream (original)) {
filtered.Add (new Dos2UnixFilter ());
file.CopyTo (filtered, 4096);
filtered.Flush ();
}
}

using (var encoded = new MemoryStream ()) {
var begin = Encoding.ASCII.GetBytes ("begin 644 photo.jpg");
var eol = FormatOptions.Default.NewLineBytes;
var end = Encoding.ASCII.GetBytes ("end");
var begin = Encoding.ASCII.GetBytes ("begin 644 photo.jpg\n");
var end = Encoding.ASCII.GetBytes ("end\n");

encoded.Write (begin, 0, begin.Length);
encoded.Write (eol, 0, eol.Length);

using (var filtered = new FilteredStream (encoded)) {
filtered.Add (EncoderFilter.Create (ContentEncoding.UUEncode));
filtered.Add (FormatOptions.Default.CreateNewLineFilter ());

using (var file = File.OpenRead ("../../TestData/encoders/photo.jpg"))
file.CopyTo (filtered, 4096);
Expand All @@ -151,7 +157,6 @@ public void TestUUEncode ()
}

encoded.Write (end, 0, end.Length);
encoded.Write (eol, 0, eol.Length);

var buf0 = original.GetBuffer ();
var buf1 = encoded.GetBuffer ();
Expand Down
12 changes: 6 additions & 6 deletions UnitTests/HtmlTokenizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class HtmlTokenizerTests
static void VerifyHtmlTokenizerOutput (string path)
{
var tokens = Path.ChangeExtension (path, ".tokens");
var expected = File.Exists (tokens) ? File.ReadAllText (tokens) : string.Empty;
var expected = File.Exists (tokens) ? File.ReadAllText (tokens).Replace ("\r", "") : string.Empty;
var actual = new StringBuilder ();

using (var textReader = File.OpenText (path)) {
Expand All @@ -67,7 +67,7 @@ static void VerifyHtmlTokenizerOutput (string path)
default: actual.Append (text.Data[i]); break;
}
}
actual.AppendLine ();
actual.Append ('\n');
break;
case HtmlTokenKind.Tag:
var tag = (HtmlTagToken) token;
Expand All @@ -82,12 +82,12 @@ static void VerifyHtmlTokenizerOutput (string path)
}

actual.Append (tag.IsEmptyElement ? "/>" : ">");

actual.AppendLine ();
actual.Append ('\n');
break;
case HtmlTokenKind.Comment:
var comment = (HtmlCommentToken) token;
actual.AppendLine (comment.Comment);
actual.Append (comment.Comment);
actual.Append ('\n');
break;
case HtmlTokenKind.DocType:
var doctype = (HtmlDocTypeToken) token;
Expand All @@ -109,7 +109,7 @@ static void VerifyHtmlTokenizerOutput (string path)
}

actual.Append (">");
actual.AppendLine ();
actual.Append ('\n');
break;
default:
Assert.Fail ("Unhandled token type: {0}", token.Kind);
Expand Down

0 comments on commit 5967da4

Please sign in to comment.