Skip to content

Commit

Permalink
Rename PrintParams.ensureAligned to ensureFirstLineIsAligned
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Dec 25, 2021
1 parent a1d8e7d commit be296cd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Diffract/DiffPrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open System.IO

let toStreamImpl (w: TextWriter) param (d: Diff) =
let originalParam = param
let param = if originalParam.ensureAligned then { originalParam with ensureAligned = false } else originalParam
let param = if originalParam.ensureFirstLineIsAligned then { originalParam with ensureFirstLineIsAligned = false } else originalParam

let addPathField path field = if path = "" then field else (path + "." + field)
let addPathIndex path index = path + "[" + index + "]"
Expand Down Expand Up @@ -60,7 +60,7 @@ let toStreamImpl (w: TextWriter) param (d: Diff) =
for item in common do
loop indent (addPathIndex path item.Name) item.Diff

match originalParam.ensureAligned, d with
match originalParam.ensureFirstLineIsAligned, d with
| true, Diff.Value (x1, x2) ->
w.WriteLine()
printValue "" "" x1 x2
Expand Down
4 changes: 2 additions & 2 deletions src/Diffract/Diffract.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ type Diffract private () =
x1Name = "Expect"
x2Name = "Actual"
neutralName = "Value"
ensureAligned = false
ensureFirstLineIsAligned = false
}

static let assertPrintParams : PrintParams =
{ simplePrintParams with ensureAligned = true }
{ simplePrintParams with ensureFirstLineIsAligned = true }

static let orIfNull (def: 'a) (value: 'a) : 'a when 'a : not struct =
if obj.ReferenceEquals(value, null) then def else value
Expand Down
2 changes: 1 addition & 1 deletion src/Diffract/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ and PrintParams =
/// Ensure that Expect and Actual remain aligned even if there is text before the first line
/// by prepending a newline if the diff is a single Value.
/// Default: true for Assert(), false for Write() and ToString().
ensureAligned: bool
ensureFirstLineIsAligned: bool
}

/// A custom computed diff that.
Expand Down
4 changes: 2 additions & 2 deletions tests/Diffract.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let ``Example error message`` () =
ex.Message)

[<Fact>]
let ``Ensure aligned`` () =
let ``Ensure first line is aligned`` () =
let ex = Assert.Throws<AssertionFailedException>(fun () -> Diffract.Assert(12, 13))
Assert.Equal("\nExpect = 12\nActual = 13\n", ex.Message)
Assert.Equal("Expect = 12\nActual = 13\n", Diffract.ToString(12, 13))
Expand Down Expand Up @@ -126,7 +126,7 @@ module ``Custom differ with custom diff output`` =
None
else
Diff.MakeCustom(fun writer param indent path recur ->
if param.ensureAligned then writer.WriteLine()
if param.ensureFirstLineIsAligned then writer.WriteLine()
let indentLike str = String.replicate (String.length str) " "
let dpath = if path = "" then "" else path + " "
writer.WriteLine($"{indent}{dpath}{param.x1Name} __is__ {x1.x}")
Expand Down

0 comments on commit be296cd

Please sign in to comment.