Skip to content

Commit

Permalink
Testing String.concat, make sure the new three paths are covered
Browse files Browse the repository at this point in the history
  • Loading branch information
abelbraaksma committed Jun 18, 2020
1 parent d7c95e0 commit 9c6ba3f
Showing 1 changed file with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,26 @@ type StringModule() =

[<Test>]
member this.Concat() =
let e1 = String.concat null ["foo"]
Assert.AreEqual("foo", e1)

let e2 = String.concat "" []
Assert.AreEqual("", e2)

let e3 = String.concat "foo" []
Assert.AreEqual("", e3)

let e4 = String.concat "" [null]
Assert.AreEqual("", e4)

let e5 = String.concat "" [""]
Assert.AreEqual("", e5)

let e6 = String.concat "foo" ["bar"]
Assert.AreEqual("bar", e6)

let e7 = String.concat "foo" ["bav";"baz"]
Assert.AreEqual("bavfoobaz", e7)

let e8 = String.concat "foo" [null;"baz";null;"bar"]
Assert.AreEqual("foobazfoofoobar", e8)

/// This tests the three paths of String.concat w.r.t. array, list, seq
let execTest f expected arg =
let r1 = f (List.toSeq arg)
Assert.AreEqual(expected, r1)

let r2 = f (List.toArray arg)
Assert.AreEqual(expected, r2)

let r3 = f arg
Assert.AreEqual(expected, r3)

do execTest (String.concat null) "foo" ["foo"]
do execTest (String.concat "") "" []
do execTest (String.concat "foo") "" []
do execTest (String.concat "") "" [null]
do execTest (String.concat "") "" [""]
do execTest (String.concat "foo") "bar" ["bar"]
do execTest (String.concat "foo") "bavfoobaz" ["bav"; "baz"]
do execTest (String.concat "foo") "foobazfoofoobar" [null;"baz";null;"bar"]

CheckThrowsArgumentNullException(fun () -> String.concat "foo" null |> ignore)

[<Test>]
Expand Down

0 comments on commit 9c6ba3f

Please sign in to comment.