Skip to content

Commit 7ca403a

Browse files
committed
Added string format
1 parent 13e99f4 commit 7ca403a

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ more. Some bindings have already been added:
2323
Prerequisite for compiling F# to Python using Fable:
2424

2525
```sh
26-
> dotnet tool install --global fable-py --version 4.0.0-alpha-004
27-
> dotnet add package Fable.Core.Experimental --version 4.0.0-alpha-005
26+
> dotnet tool install --global fable-py --version 4.0.0-alpha-005
27+
> dotnet add package Fable.Core.Experimental --version 4.0.0-alpha-006
2828
```
2929

3030
To use the `Fable.Python` library in your Fable project:

paket.dependencies

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# https://fsprojects.github.io/Paket/nuget-dependencies.html
12

23
source https://api.nuget.org/v3/index.json
34
storage: none

src/stdlib/String.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Fable.Python.String
2+
3+
open System
4+
open Fable.Core
5+
6+
// fsharplint:disable MemberNames
7+
8+
type System.String with
9+
[<Emit("$0.format($1...)")>]
10+
member self.format([<ParamArray>] args: Object[]) = nativeOnly

test/Fable.Python.Test.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<Compile Include="TestAst.fs" />
1616
<Compile Include="TestBuiltins.fs" />
1717
<Compile Include="TestJson.fs" />
18+
<Compile Include="TestString.fs" />
1819
<Compile Include="Main.fs" />
1920
</ItemGroup>
2021
<Import Project="..\.paket\Paket.Restore.targets" />

test/TestString.fs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Fable.Python.Tests.String
2+
3+
open Util.Testing
4+
open Fable.Python.String
5+
6+
[<Fact>]
7+
let ``test string format works`` () =
8+
let result = "The sum of 1 + 2 is {0}".format(1+2)
9+
result |> equal "The sum of 1 + 2 is 3"
10+
11+
[<Fact>]
12+
let ``test string format 2 works`` () =
13+
let result = "The sum of {0} + 2 is {1}".format(1, 1+2)
14+
result |> equal "The sum of 1 + 2 is 3"

0 commit comments

Comments
 (0)