Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vbfox committed Sep 5, 2024
1 parent dad9542 commit 50b70b2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/BlackFox.MasterOfFoo.Tests/InternalRepresentationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ open System.Text
open BlackFox.MasterOfFoo
open System.Text.RegularExpressions

type MyFormatable() =
interface System.IFormattable with
member __.ToString(format: string, _formatProvider: System.IFormatProvider) =
$"MyFormatable(%s{format})"

override _.ToString() = "MyFormatable"

type MyToStringSaysHi() =
override _.ToString() =
"Hi"
Expand Down Expand Up @@ -226,6 +233,26 @@ Finalize
"""
}

test "IFormattable hole only" {
testEqual
(testprintf $"{MyFormatable():HelloWorld}")
"""
Init
Write value: MyFormatable, type: FromFormatSpecifier, valueType: System.Object, spec: 'P', Precision=-, Width=-, Flags=None, dotnetFormat: 'HelloWorld', starWidth: , starPrecision: , AsPrintF: MyFormatable(HelloWorld);
Finalize
"""
}

test "IFormattable + unusual characters hole only" {
testEqual
(testprintf $"{MyFormatable():``Hello World``}")
"""
Init
Write value: MyFormatable, type: FromFormatSpecifier, valueType: System.Object, spec: 'P', Precision=-, Width=-, Flags=None, dotnetFormat: 'Hello World', starWidth: , starPrecision: , AsPrintF: MyFormatable(Hello World);
Finalize
"""
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Complex case mixing holes and text

Expand Down
10 changes: 9 additions & 1 deletion src/BlackFox.MasterOfFoo.Tests/Test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,15 @@ let tests = [
Expect.equal
(coreprintf $"{MyFormatable():HelloWorld}")
(testprintf $"{MyFormatable():HelloWorld}")
"{MyFormatable:HelloWorld}"
"{MyFormatable():HelloWorld}"
}

test "custom untyped interpolation .NET format unusual characters" {
// Using double backticks to escape the format string if it contains spaces for example
Expect.equal
(coreprintf $"{MyFormatable():``Hello World``}")
(testprintf $"{MyFormatable():``Hello World``}")
"{MyFormatable():``Hello World``}"
}
]

Expand Down

0 comments on commit 50b70b2

Please sign in to comment.