Skip to content

Commit

Permalink
Fix tests on linux. Use raw string literals.
Browse files Browse the repository at this point in the history
  • Loading branch information
rstarkov committed Dec 21, 2023
1 parent 3037417 commit 3997a07
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions Tests/RTSmtpClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net.Mail;
using System.Text.RegularExpressions;
using Xunit;

namespace RT.Emailer.Tests;
Expand All @@ -13,42 +14,59 @@ public void TestEncodeHeader()
@"Subject: Test subject");
test(
RTSmtpClient.EncodeHeader("Subject", "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor."),
@"Subject: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aenean commodo ligula eget dolor.");
crlf(
"""
Subject: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aenean commodo ligula eget dolor.
"""));
test(
RTSmtpClient.EncodeHeader("Subject", "Далеко-далеко за словесными горами в стране гласных и согласных живут рыбные тексты. Вдали от всех живут они в буквенных домах на берегу Семантика большого языкового океана."),
@"Subject: =?UTF-8?B?0JTQsNC70LXQutC+LdC00LDQu9C10LrQviDQt9CwINGB0LvQvtCy?=
=?UTF-8?B?0LXRgdC90YvQvNC4INCz0L7RgNCw0LzQuCDQsiDRgdGC0YDQsNC90LUg0LM=?=
=?UTF-8?B?0LvQsNGB0L3Ri9GFINC4INGB0L7Qs9C70LDRgdC90YvRhSDQttC40LLRg9GC?=
=?UTF-8?B?INGA0YvQsdC90YvQtSDRgtC10LrRgdGC0YsuINCS0LTQsNC70Lgg0L7RgiA=?=
=?UTF-8?B?0LLRgdC10YUg0LbQuNCy0YPRgiDQvtC90Lgg0LIg0LHRg9C60LLQtdC90L0=?=
=?UTF-8?B?0YvRhSDQtNC+0LzQsNGFINC90LAg0LHQtdGA0LXQs9GDINCh0LXQvNCw0L0=?=
=?UTF-8?B?0YLQuNC60LAg0LHQvtC70YzRiNC+0LPQviDRj9C30YvQutC+0LLQvtCz0L4g?=
=?UTF-8?B?0L7QutC10LDQvdCwLg==?=");
crlf(
"""
Subject: =?UTF-8?B?0JTQsNC70LXQutC+LdC00LDQu9C10LrQviDQt9CwINGB0LvQvtCy?=
=?UTF-8?B?0LXRgdC90YvQvNC4INCz0L7RgNCw0LzQuCDQsiDRgdGC0YDQsNC90LUg0LM=?=
=?UTF-8?B?0LvQsNGB0L3Ri9GFINC4INGB0L7Qs9C70LDRgdC90YvRhSDQttC40LLRg9GC?=
=?UTF-8?B?INGA0YvQsdC90YvQtSDRgtC10LrRgdGC0YsuINCS0LTQsNC70Lgg0L7RgiA=?=
=?UTF-8?B?0LLRgdC10YUg0LbQuNCy0YPRgiDQvtC90Lgg0LIg0LHRg9C60LLQtdC90L0=?=
=?UTF-8?B?0YvRhSDQtNC+0LzQsNGFINC90LAg0LHQtdGA0LXQs9GDINCh0LXQvNCw0L0=?=
=?UTF-8?B?0YLQuNC60LAg0LHQvtC70YzRiNC+0LPQviDRj9C30YvQutC+0LLQvtCz0L4g?=
=?UTF-8?B?0L7QutC10LDQvdCwLg==?=
"""));
test(
RTSmtpClient.EncodeHeader("Subject", "sjfwoijfdalwfdwiufdhawldkjhkawuydgakwjdfygakwjdfybawkdufyghawkjdfgawkfuygawkjdfygawkjdybfawkuydgawkudyg awdfgkawuydgawdfawdfygliuhawdlufhawlydfglawyeghdliuhewgdliuhadgifaliugawdfliyguawdlfygawdflygawdlfguy sd"),
@"Subject:
sjfwoijfdalwfdwiufdhawldkjhkawuydgakwjdfygakwjdfybawkdufyghawkjdfgawkfuygawkjdfygawkjdybfawkuydgawkudyg
awdfgkawuydgawdfawdfygliuhawdlufhawlydfglawyeghdliuhewgdliuhadgifaliugawdfliyguawdlfygawdflygawdlfguy
sd");
crlf(
"""
Subject:
sjfwoijfdalwfdwiufdhawldkjhkawuydgakwjdfygakwjdfybawkdufyghawkjdfgawkfuygawkjdfygawkjdybfawkuydgawkudyg
awdfgkawuydgawdfawdfygliuhawdlufhawlydfglawyeghdliuhewgdliuhadgifaliugawdfliyguawdlfygawdflygawdlfguy
sd
"""));

test(
RTSmtpClient.EncodeHeader("From", new MailAddress("[email protected]")),
"From: [email protected]");
test(
RTSmtpClient.EncodeHeader("From", new MailAddress("[email protected]"), new MailAddress("[email protected]"), new MailAddress("[email protected]"), new MailAddress("[email protected]"), new MailAddress("[email protected]"), new MailAddress("[email protected]")),
@"From: [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected]");
crlf(
"""
From: [email protected], [email protected], [email protected],
[email protected], [email protected], [email protected]
"""));
test(
RTSmtpClient.EncodeHeader("From", new MailAddress("Test <[email protected]>"), new MailAddress("\"Τεστ Σμιθ\" <[email protected]>"), new MailAddress("[email protected]"), new MailAddress("[email protected]"), new MailAddress("\"Грегор Замза обнаружил что он у себя в постели\" <[email protected]>"), new MailAddress("[email protected]")),
@"From: ""Test"" <[email protected]>, ""=?UTF-8?B?zqTOtc+Dz4QgzqPOvM65zrg=?=""
<[email protected]>, [email protected], [email protected], ""=?UTF-8?B?0JM=?=
=?UTF-8?B?0YDQtdCz0L7RgCDQl9Cw0LzQt9CwINC+0LHQvdCw0YDRg9C20LjQuyDRh9GC?=
=?UTF-8?B?0L4g0L7QvSDRgyDRgdC10LHRjyDQsiDQv9C+0YHRgtC10LvQuA==?=""
<[email protected]>, [email protected]");
crlf(
"""
From: "Test" <[email protected]>, "=?UTF-8?B?zqTOtc+Dz4QgzqPOvM65zrg=?="
<[email protected]>, [email protected], [email protected], "=?UTF-8?B?0JM=?=
=?UTF-8?B?0YDQtdCz0L7RgCDQl9Cw0LzQt9CwINC+0LHQvdCw0YDRg9C20LjQuyDRh9GC?=
=?UTF-8?B?0L4g0L7QvSDRgyDRgdC10LHRjyDQsiDQv9C+0YHRgtC10LvQuA==?="
<[email protected]>, [email protected]
"""));
}

private static string crlf(string s) => Regex.Replace(s, @"\r?\n", "\r\n");

private void test(string actual, string expected)
{
Assert.Equal(expected, actual);
Expand Down

0 comments on commit 3997a07

Please sign in to comment.