Skip to content

Commit

Permalink
Asserts: Case insensitive "contains" string check (#361)
Browse files Browse the repository at this point in the history
To compare 2 strings, "contains" function is checking in a case
sensitive way. Developers might need to have a case insensitive
contains to allow them to have more robust test cases.
  • Loading branch information
milkeg authored and lefthandedgoat committed Apr 11, 2017
1 parent 1553863 commit 723cf69
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/content/assertions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ Assert that one string contains another.
*)
contains "Log" (read "#logout")

(**
containsInsensitive
--------
Assert that one string contains (case insensitive) another.
*)
containsInsensitive "Log" (read "#logout")

(**
notContains
--------
Expand Down
7 changes: 7 additions & 0 deletions src/canopy/canopy.fs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,13 @@ let contains (value1 : string) (value2 : string) =
if (value2.Contains(value1) <> true) then
raise (CanopyContainsFailedException(sprintf "contains check failed. %s does not contain %s" value2 value1))

(* documented/assertions *)
let containsInsensitive (value1 : string) (value2 : string) =
let rules = StringComparison.InvariantCultureIgnoreCase
let contains = value2.IndexOf(value1, rules)
if contains < 0 then
raise (CanopyContainsFailedException(sprintf "contains insensitive check failed. %s does not contain %s" value2 value1))

(* documented/assertions *)
let notContains (value1 : string) (value2 : string) =
if (value2.Contains(value1) = true) then
Expand Down

0 comments on commit 723cf69

Please sign in to comment.