From f560318e61f9d431c3b4107d3047cd57ce70d20a Mon Sep 17 00:00:00 2001 From: Henrik Feldt Date: Fri, 28 Oct 2016 09:56:37 +0200 Subject: [PATCH] [expect] adding `stringStarts` and docs --- .semver | 2 +- Expecto/Expect.fs | 13 +++++++++++-- README.md | 7 ++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.semver b/.semver index 47731ae5..ddb2a185 100644 --- a/.semver +++ b/.semver @@ -1,6 +1,6 @@ --- :major: 1 :minor: 0 -:patch: 11 +:patch: 12 :special: '' :metadata: '' diff --git a/Expecto/Expect.fs b/Expecto/Expect.fs index cf2f1df8..ff05a104 100644 --- a/Expecto/Expect.fs +++ b/Expecto/Expect.fs @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index 9cd72bf9..3e1ce192 100644 --- a/README.md +++ b/README.md @@ -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