Skip to content

Commit 4d15697

Browse files
committed
Add String.mapi tests for all new unrolling corner cases, and some general ones
1 parent 3744f53 commit 4d15697

File tree

1 file changed

+22
-4
lines changed
  • tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections

1 file changed

+22
-4
lines changed

tests/FSharp.Core.UnitTests/FSharp.Core/Microsoft.FSharp.Collections/StringModule.fs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,29 @@ type StringModule() =
7979

8080
[<Test>]
8181
member this.MapI() =
82-
let e1 = String.mapi (fun i c -> char(int c + i)) "foo"
83-
Assert.AreEqual("fpq", e1)
82+
let e1 = String.mapi (fun _ c -> c) "12345"
83+
Assert.AreEqual("12345", e1)
8484

85-
let e2 = String.mapi (fun i c -> c) null
86-
Assert.AreEqual("", e2)
85+
let e2 = String.mapi (fun _ c -> c + char 1) "1"
86+
Assert.AreEqual("2", e2)
87+
88+
let e3 = String.mapi (fun _ c -> c + char 1) "AB"
89+
Assert.AreEqual("BC", e3)
90+
91+
let e4 = String.mapi (fun i c -> char(int c + i)) "foo"
92+
Assert.AreEqual("fpq", e4)
93+
94+
let e5 = String.mapi (fun _ c -> c) null
95+
Assert.AreEqual("", e5)
96+
97+
let e6 = String.mapi (fun _ c -> c) String.Empty
98+
Assert.AreEqual("", e6)
99+
100+
let e7 = String.mapi (fun _ _ -> failwith "should not fail") null
101+
Assert.AreEqual("", e7)
102+
103+
let e8 = String.mapi (fun i _ -> if i = 1 then failwith "should not fail" else char i) "X"
104+
Assert.AreEqual("\u0000", e8)
87105

88106
[<Test>]
89107
member this.Filter() =

0 commit comments

Comments
 (0)