Skip to content

Commit

Permalink
Merge pull request #7 from vbfox/vbfox/B_specifier
Browse files Browse the repository at this point in the history
Support the %B specifier
  • Loading branch information
vbfox authored Sep 6, 2024
2 parents 0f76c10 + 5c69991 commit 243d52c
Show file tree
Hide file tree
Showing 8 changed files with 1,082 additions and 737 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ The details of string interpolation internals are specified in [F# RFC FS-1001 -

They appear as follow in this library:
* Type-checked "printf-style" fills behave exactly as they do in `sprintf` and friends.
* Unchecked ".NET-style" fills appear with a `Specifier.TypeChar` of 'P' and the .NET format string
* Unchecked ".NET-style" fills appear with a `Specifier.TypeChar` of `'P'` and the .NET format string
in `Specifier.InteropHoleDotNetFormat`.

[fs-1001]: https://github.com/fsharp/fslang-design/blob/aca88da13cdb95f4f337d4f7d44cbf9d343704ae/FSharp-5.0/FS-1001-StringInterpolation.md#f-rfc-fs-1001---string-interpolation
Expand Down
4 changes: 4 additions & 0 deletions Release Notes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### New in 2.1.0

* Synchronize with the latest FSharp.Core version and support the `%B` format specifier

### New in 2.0.0

* Include the readme in the NuGet package
Expand Down
10 changes: 10 additions & 0 deletions src/BlackFox.MasterOfFoo.Tests/InternalRepresentationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ Finalize
"""
}

test "int hole only %B" {
testEqual
(testprintf "%B" 42)
"""
Init
Write value: 42, type: FromFormatSpecifier, valueType: System.Int32, spec: 'B', Precision=-, Width=-, Flags=None, starWidth: , starPrecision: , AsPrintF: 101010;
Finalize
"""
}

test "float64 hole only %f" {
testEqual
(testprintf "%f" 42.42)
Expand Down
9 changes: 8 additions & 1 deletion src/BlackFox.MasterOfFoo.Tests/Test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,20 @@ let tests = [
"%s"
}

test "int format" {
test "int format %i" {
Expect.equal
(coreprintf "%i" 5)
(testprintf "%i" 5)
"%i"
}

test "int format %B" {
Expect.equal
(coreprintf "%B" 5)
(testprintf "%B" 5)
"%B"
}

test "int untyped interpolation" {
Expect.equal
(coreprintf $"{5}")
Expand Down
7 changes: 7 additions & 0 deletions src/BlackFox.MasterOfFoo/PrintfEnv.fs
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,10 @@ type PrintfEnv<'State, 'Residue, 'Result>(state: 'State) =
env.Write(PrintableElement("%", PrintableElementType.MadeByEngine))

env.Finalize()

/// This is the new name of Finalize in the new version of FSharp.Core
///
/// We can't rename our method without breaking customers code but changing the name everywhere in printf.fs is
/// also a pain. So as an alternative this internal version, made only to ease porting was introduced.
member internal env.Finish () =
env.Finalize()
167 changes: 93 additions & 74 deletions src/BlackFox.MasterOfFoo/printf.fs

Large diffs are not rendered by default.

175 changes: 95 additions & 80 deletions src/BlackFox.MasterOfFoo/printf_original.fs

Large diffs are not rendered by default.

Loading

0 comments on commit 243d52c

Please sign in to comment.