forked from ionide/KeepAChangelog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create line ending assertion helper for tests
- Loading branch information
Showing
4 changed files
with
42 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Ionide.KeepAChangelog.Tasks.Test.Helpers | ||
|
||
open System.Runtime.CompilerServices | ||
open Faqt | ||
open Faqt.AssertionHelpers | ||
|
||
[<Extension>] | ||
type Assertions = | ||
|
||
/// Asserts that the subject is equal to the specified string when CLRF is replaced with LF in both raw and | ||
/// escaped forms. | ||
[<Extension>] | ||
static member BeLineEndingEquivalent(t: Testable<string>, expected: string, ?because) : And<string> = | ||
use _ = t.Assert() | ||
|
||
if isNull expected then | ||
nullArg (nameof expected) | ||
|
||
if isNull t.Subject then | ||
t.With("Expected", expected).With("But was", t.Subject).Fail(because) | ||
|
||
let expectedNormalised = expected.Replace("\r\n", "\n").Replace("\\r\\n", "\\n") | ||
|
||
let subjectNormalised = t.Subject.Replace("\r\n", "\n").Replace("\\r\\n", "\\n") | ||
|
||
if subjectNormalised <> expectedNormalised then | ||
t | ||
.With("Expected", expectedNormalised) | ||
.With("But was", subjectNormalised) | ||
.Fail(because) | ||
|
||
And(t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters