Skip to content

Commit

Permalink
fix: fixes python test wrt culture info
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrattli authored and alfonsogarciacaro committed Jul 19, 2022
1 parent ee4c670 commit 067e8c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"fantomas-tool": {
"version": "4.6.0",
"version": "4.7.9",
"commands": [
"fantomas"
]
Expand Down
5 changes: 5 additions & 0 deletions src/fable-library-py/fable_library/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ def _(cont: Callable[..., Any]):


def format(string: str, *args: Any) -> str:
if not string and args:
# Called with culture info
string = args[0]
args = args[1:]

def match(m: Match[str]) -> str:
idx, padLength, format, precision_, pattern = list(m.groups())
rep = args[int(idx)]
Expand Down
2 changes: 2 additions & 0 deletions src/fable-library/System.Text.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace System.Text
open System

type StringBuilder(value: string, capacity: int) =
let buf = ResizeArray<string>(capacity)
Expand All @@ -16,6 +17,7 @@ type StringBuilder(value: string, capacity: int) =
member x.Append(cs: char[]) = buf.Add(System.String(cs)); x
member x.Append(s: StringBuilder) = buf.Add(s.ToString()); x
member x.AppendFormat(fmt: string, o: obj) = buf.Add(System.String.Format(fmt, o)); x
member x.AppendFormat(provider: IFormatProvider, fmt: string, o: obj) = buf.Add(System.String.Format(provider, fmt, o)); x
member x.AppendLine() = buf.Add(System.Environment.NewLine); x
member x.AppendLine(s: string) = buf.Add(s); buf.Add(System.Environment.NewLine); x
override __.ToString() = System.String.Concat(buf)
Expand Down
10 changes: 6 additions & 4 deletions tests/Python/TestString.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Fable.Tests.String

open System
open System.Globalization

open Util.Testing

#nowarn "44" // This construct is deprecated. Uri.EscapeUriString can corrupt the Uri string in some cases. (code 44)
Expand Down Expand Up @@ -148,9 +150,9 @@ let ``test sprintf integers with sign and padding works`` () =

[<Fact>]
let ``test String.Format combining padding and zeroes pattern works`` () =
String.Format("{0:++0.00++}", -5000.5657) |> equal "-++5000.57++"
String.Format("{0:000.00}foo", 5) |> equal "005.00foo"
String.Format("{0,-8:000.00}foo", 12.456) |> equal "012.46 foo"
String.Format(CultureInfo.InvariantCulture, "{0:++0.00++}", -5000.5657) |> equal "-++5000.57++"
String.Format(CultureInfo.InvariantCulture, "{0:000.00}foo", 5) |> equal "005.00foo"
String.Format(CultureInfo.InvariantCulture, "{0,-8:000.00}foo", 12.456) |> equal "012.46 foo"

[<Fact>]
let ``test StringBuilder works`` () =
Expand Down Expand Up @@ -193,7 +195,7 @@ let ``test StringBuilder.Append works with various overloads`` () =
.Append("bcd".ToCharArray())
.Append('/')
.Append(true)
.Append(5.2)
.AppendFormat(CultureInfo.InvariantCulture, "{0}", 5.2)
.Append(34)
equal "aaabcd/true5.234" (builder.ToString().ToLower())

Expand Down

0 comments on commit 067e8c9

Please sign in to comment.