Skip to content

Commit

Permalink
Add expect.string_to_not_end_with (#13)
Browse files Browse the repository at this point in the history
This PR implements the negated counterpart of the `string_to_end_with`
assertion.

---------

Co-authored-by: Marshall Bowers <[email protected]>
  • Loading branch information
Patrik Kühl and maxdeviant authored Jul 31, 2024
1 parent 5572f32 commit 65cc9f7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added `expect/string_to_not_start_with` for asserting that a string does not start with another string.
- Added `expect/string_to_not_end_with` for asserting that a string does not end with another string.

## [0.4.0] - 2024-06-14

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: 1.1.5
title: expect/string_to_not_end_with given matching string
---
Expected "Ants in my Eyes Johnson" to not end with "son"

- Expected
+ Received

- son
+ Ants in my Eyes Johnson
19 changes: 19 additions & 0 deletions src/startest/expect.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,25 @@ pub fn string_to_end_with(actual: String, expected: String) -> Nil {
}
}

/// Asserts that the given string does not end with the expected string.
pub fn string_to_not_end_with(actual: String, expected: String) -> Nil {
case string.ends_with(actual, expected) {
False -> Nil
True ->
AssertionError(
string.concat([
"Expected ",
string.inspect(actual),
" to not end with ",
string.inspect(expected),
]),
actual,
expected,
)
|> assertion_error.raise
}
}

/// Asserts that the given list contains the expected element.
pub fn list_to_contain(actual: List(a), expected: a) -> Nil {
case list.contains(actual, expected) {
Expand Down
22 changes: 22 additions & 0 deletions test/startest/expect_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,28 @@ pub fn string_to_end_with_tests() {
])
}

pub fn string_to_not_end_with_tests() {
describe("startest/expect", [
describe("string_to_not_end_with", [
describe("given a string that does not end with the expected pattern", [
it_passes(fn() {
"Purpose Robot"
|> expect.string_to_not_end_with("bottle")
}),
]),
describe("given a string that ends with the expected pattern", [
it_fails_matching_snapshot(
"expect/string_to_not_end_with given matching string",
fn() {
"Ants in my Eyes Johnson"
|> expect.string_to_not_end_with("son")
},
),
]),
]),
])
}

pub fn list_to_contain_tests() {
describe("startest/expect", [
describe("list_to_contain", [
Expand Down

0 comments on commit 65cc9f7

Please sign in to comment.