Skip to content

Commit

Permalink
[expect] adding stringStarts and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
haf committed Oct 28, 2016
1 parent 67c8d94 commit f560318
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .semver
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
:major: 1
:minor: 0
:patch: 11
:patch: 12
:special: ''
:metadata: ''
13 changes: 11 additions & 2 deletions Expecto/Expect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,18 @@ let sequenceEqual (actual : _ seq) (expected : _ seq) format =
format i (ei.Current)
i <- i + 1

/// Ensures that the subject string contains the given substring. Otherwise
/// fails with the passed message.
/// Expect the string `subject` to contain `substring` as part of itself.
/// If it does not, then fail with `format` and `subject` and `substring`
/// as part of the error message.
let stringContains (subject : string) (substring : string) format =
if not (subject.Contains(substring)) then
Tests.failtestf "%s. Expected subject string '%s' to contain substring '%s'."
format subject substring

/// Expect the string `subject` to start with `prefix`. If it does not
/// then fail with `format` as an error message together with a description
/// of `subject` and `prefix`.
let stringStarts (subject : string) (prefix : string) format =
if not (subject.StartsWith prefix) then
Tests.failtestf "%s. Expected subject string '%s' to start with '%s'."
format subject prefix
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ This module is your main entry-point when asserting.
- `isFalse`
- `isTrue`
- `sequenceEqual`
- `stringContains`
- `stringContains` – Expect the string `subject` to contain `substring` as part
of itself. If it does not, then fail with `format` and `subject` and
`substring` as part of the error message.
- `stringStarts` – Expect the string `subject` to start with `prefix` and if it
does not then fail with `format` as an error message together with a
description of `subject` and `prefix`.
- `contains : 'a seq -> 'a -> string -> unit`

## `main argv` – how to run console apps
Expand Down

0 comments on commit f560318

Please sign in to comment.