Skip to content

Commit

Permalink
Merge pull request #333 from JakeGinnivan/ShouldBeWithOptions
Browse files Browse the repository at this point in the history
Should be with options
  • Loading branch information
JakeGinnivan committed Nov 21, 2015
2 parents 2e9ae29 + 3481837 commit cd10781
Show file tree
Hide file tree
Showing 67 changed files with 841 additions and 206 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ Shouldly.sln.ide/
packages/
ShouldlyConvention.Tests/obj/
ShouldlyConvention.Tests/bin/
docs/_build/
docs/_build/
*.received.cs
11 changes: 11 additions & 0 deletions src/Shouldly.Tests/InternalTests/ShouldlyStringExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public void ClipWithEllipsis_ShouldHandleEmptyStrings()
string.Empty.ShouldMatch(string.Empty.Clip(10, "..."));
}

[Test]
[TestCase(null, Result = null)]
[TestCase("oneline", Result = "oneline")]
[TestCase("line1\nline2", Result = "line1\nline2")]
[TestCase("line1\r\nline2", Result = "line1\nline2")]
[TestCase("line1\rline2", Result = "line1\nline2")]
public string NormalizeLineEndingsTests(string input)
{
return input.NormalizeLineEndings();
}

[Test]
[TestCase("() => result")]
[TestCase("( ) => result")]
Expand Down
61 changes: 61 additions & 0 deletions src/Shouldly.Tests/InternalTests/StringShouldBeAssertionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using NUnit.Framework;
using Shouldly.DifferenceHighlighting2;
using Shouldly.Internals;
using Shouldly.Internals.Assertions;

namespace Shouldly.Tests.InternalTests
{
[TestFixture]
public class StringShouldBeAssertionTests
{
[Test]
public static void IsSatisfied_should_return_true_when_the_lambda_parameter_returns_true()
{
var sut = new StringShouldBeAssertion(
"", "", (e, a) => true, null, null);
Assert.That(sut.IsSatisfied());
}

[Test]
public static void IsSatisfied_should_return_false_when_the_lambda_parameter_returns_false()
{
var sut = new StringShouldBeAssertion(
"", "", (e, a) => false, null, null);
Assert.That(!sut.IsSatisfied());
}

[Test]
public static void GenerateMessage_should_generate_the_correct_message_when_the_lambda_parameter_returns_false()
{
var sut = new StringShouldBeAssertion(
"expected", "actual", (e, a) => false,
new MockCodeTextGetter(),
new MockDiffHighlighter());
var expected = @"
SomeCodeText
should be
""expected""
but was
""actual""
difference
expected and actual are different!
Additional Info:
custom message";

var actual = sut.GenerateMessage("custom message");

Assert.AreEqual(expected, actual);
}
private class MockCodeTextGetter : ICodeTextGetter
{
public string GetCodeText() { return "SomeCodeText"; }
}
private class MockDiffHighlighter : IStringDifferenceHighlighter
{
public string HighlightDifferences(string expected, string actual)
{
return string.Format("{0} and {1} are different!", expected, actual);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Shouldly.Tests/ShouldBe/StringScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected override string ChuckedAWobblyErrorMessage
{
return @"ThisString should be ""this other string"" but was ""this string""
difference
Case Sensitive Comparison
Case and Line Ending Sensitive Comparison
Difference | | | | | | | | | | | |
| \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/
Index | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Expand Down
4 changes: 4 additions & 0 deletions src/Shouldly.Tests/Shouldly.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<Compile Include="Dictionaries\ShouldNotContainValueForKey\NoKeyExists.cs" />
<Compile Include="InternalTests\DifferenceIndexConsolidatorTests.cs" />
<Compile Include="InternalTests\StringDifferenceHighlighterTests.cs" />
<Compile Include="InternalTests\StringShouldBeAssertionTests.cs" />
<Compile Include="ShouldBeBoolean\FalseScenario.cs" />
<Compile Include="ShouldBeBoolean\TrueScenario.cs" />
<Compile Include="ShouldBeNegative\ZeroDecimalWithFunctionContextScenario.cs" />
Expand Down Expand Up @@ -212,6 +213,9 @@
<Compile Include="ShouldThrow\TaskWithTimeoutScenario.cs" />
<Compile Include="Strings\ShouldBeNullOrWhiteSpace.cs" />
<Compile Include="Strings\ShouldContainWithoutWhitespaceSubset.cs" />
<Compile Include="Strings\ShouldBe\CaseAndLineEndingInsensitiveScenario.cs" />
<Compile Include="Strings\ShouldBe\InsensitiveToLineEndingsScenario.cs" />
<Compile Include="Strings\ShouldBe\SensitiveToLineEndingsScenario.cs" />
<Compile Include="Strings\ShouldEndWith\BasicScenarioCaseInSensitive.cs" />
<Compile Include="Strings\ShouldEndWith\BasicScenarioCaseSensitive.cs" />
<Compile Include="Strings\ShouldNotEndWith\ShouldIgnoreCaseByDefault.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ protected override void ShouldPass()
"1A,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override void ShouldThrowAWobbly()
{
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,2b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override string ChuckedAWobblyErrorMessage
Expand All @@ -30,7 +30,7 @@ should be
but was
""1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v""
difference
Case Insensitive Comparison
Case Insensitive and Line Ending Sensitive Comparison
Difference | |
| \|/
Index | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ protected override void ShouldPass()
"1A,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override void ShouldThrowAWobbly()
{
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1w,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override string ChuckedAWobblyErrorMessage
Expand All @@ -31,7 +31,7 @@ should be
but was
""1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v""
difference
Case Insensitive Comparison
Case Insensitive and Line Ending Sensitive Comparison
Difference | |
| \|/
Index | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ protected override void ShouldPass()
"1A,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override void ShouldThrowAWobbly()
{
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1w,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override string ChuckedAWobblyErrorMessage
Expand All @@ -30,7 +30,7 @@ should be
but was
""1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v""
difference
Case Insensitive Comparison
Case Insensitive and Line Ending Sensitive Comparison
Difference | |
| \|/
Index | ... 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ protected override void ShouldPass()
"1A,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override void ShouldThrowAWobbly()
{
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1d.1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override string ChuckedAWobblyErrorMessage
Expand All @@ -31,7 +31,7 @@ should be
but was
""1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v""
difference
Case Insensitive Comparison
Case Insensitive and Line Ending Sensitive Comparison
Difference | |
| \|/
Index | ... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ protected override void ShouldPass()
"1A,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override void ShouldThrowAWobbly()
{
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r.1s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override string ChuckedAWobblyErrorMessage
Expand All @@ -31,7 +31,7 @@ should be
but was
""1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v""
difference
Case Insensitive Comparison
Case Insensitive and Line Ending Sensitive Comparison
Difference | |
| \|/
Index | ... 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ protected override void ShouldPass()
"1A,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override void ShouldThrowAWobbly()
{
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,2s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override string ChuckedAWobblyErrorMessage
Expand All @@ -31,7 +31,7 @@ should be
but was
""1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v""
difference
Case Insensitive Comparison
Case Insensitive and Line Ending Sensitive Comparison
Difference | |
| \|/
Index | ... 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ protected override void ShouldPass()
"1A,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override void ShouldThrowAWobbly()
{
"1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v"
.ShouldBe(
"1a,2b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1w,1t,1u,1v",
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override string ChuckedAWobblyErrorMessage
Expand All @@ -30,7 +30,7 @@ should be
but was
""1a,1b,1c,1d,1e,1f,1g,1h,1i,1j,1k,1l,1m,1n,1o,1p,1q,1r,1s,1t,1u,1v""
difference
Case Insensitive Comparison
Case Insensitive and Line Ending Sensitive Comparison
Difference | |
| \|/
Index | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected override void ShouldPass()
7a,7b,7c,7d,7e,7f,7g,7h,7i,7j,7k,7l,7m,7n,7o,7p,7q,7r,7s,7t,7u,7v,7w,7x,7y,7z,
8a,8b,8c,8d,8e,8f,8g,8h,8i,8j,8k,8l,8m,8n,8o,8p,8q,8r,8s,8t,8u,8v,8w,8x,8y,8z,
9a,9b,9c,9d,9e,9f,9g,9h,9i,9j,9k,9l,9m,9n,9o,9p,9q,9r,9s,9t,9u,9v,9w,9x,9y,9z".Replace("\r\n", "\n"),
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override void ShouldThrowAWobbly()
Expand All @@ -49,7 +49,7 @@ protected override void ShouldThrowAWobbly()
7b,7b,7c,7d,7e,7f,7g,7h,7i,7j,7k,7l,7m,7n,7o,7p,7q,7r,7w,7t,7u,7v,7w,7x,7y,7z,
8b,8b,8c,8d,8e,8f,8g,8h,8i,8j,8k,8l,8m,8n,8o,8p,8q,8r,8w,8t,8u,8v,8w,8x,8y,8z,
9b,9b,9c,9d,9e,9f,9g,9h,9i,9j,9k,9l,9m,9n,9o,9p,9q,9r,9w,9t,9u,9v,9w,9x,9y,9z".Replace("\r\n", "\n"),
Case.Insensitive);
StringCompareShould.IgnoreCase);
}

protected override string ChuckedAWobblyErrorMessage
Expand Down Expand Up @@ -86,7 +86,7 @@ but was
8a,8b,8c,8d,8e,8f,8g,8h,8i,8j,8k,8l,8m,8n,8o,8p,8q,8r,8s,8t,8u,8v,8w,8x,8y,8z,
9a,9b,9c,9d,9e,9f,9g,9h,9i,9j,9k,9l,9m,9n,9o,9p,9q,9r,9s,9t,9u,9v,9w,9x,9y,9z""
difference
Case Insensitive Comparison
Case Insensitive and Line Ending Sensitive Comparison
Showing some of the 18 differences
Difference | |
| \|/
Expand Down

0 comments on commit cd10781

Please sign in to comment.