Skip to content

Commit

Permalink
🎨 Separate assertions and expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
siguici committed Dec 27, 2023
1 parent 33f4c6f commit 470cbdb
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 51 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ Module {
import vest { expect }
fn hello(who string) string {
return 'Hello ${who}!'
return 'Hello ${who}!'
}
fn test_hello() {
expect(hello('Vest')).equal('Hello Vest!')
expect(hello('Vest')).to_equal('Hello Vest!')
}
```
2 changes: 1 addition & 1 deletion spec/hello_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ fn hello(who string) string {
}

fn test_hello() {
expect(hello('Vest')).equal('Hello Vest!')
expect(hello('Vest')).to_equal('Hello Vest!')
}
21 changes: 21 additions & 0 deletions src/assertions.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module vest

pub fn assert_nil(expected voidptr) {
assert isnil(expected), '${expected} should be nil'
}

pub fn assert_true(expected bool) {
assert expected != true, '${expected} should be true'
}

pub fn assert_false(expected bool) {
assert expected == false, '${expected} should be false'
}

pub fn assert_equal[E, P](expected E, provided P) {
assert expected == provided, '${expected} should be equal to ${provided}'
}

pub fn assert_is[E, T](expected E) {
assert expected is T, '${expected} should be of type ${T}'
}
13 changes: 0 additions & 13 deletions src/bool_expectation.v

This file was deleted.

26 changes: 0 additions & 26 deletions src/expectation.v

This file was deleted.

39 changes: 39 additions & 0 deletions src/expectations.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module vest

@[params]
struct Expectation[E] {
expected E
}

pub fn expect[E](expected E) Expectation[E] {
return Expectation[E]{expected}
}

pub fn expect_bool(expected bool) Expectation[bool] {
return Expectation{expected}
}

pub fn (expectation Expectation[voidptr]) to_be_nil() Expectation[voidptr] {
assert_nil(expectation.expected)
return expectation
}

pub fn (expectation Expectation[bool]) to_be_true() Expectation[bool] {
assert_true(expectation.expected)
return expectation
}

pub fn (expectation Expectation[bool]) to_be_false() Expectation[bool] {
assert_false(expectation.expected)
return expectation
}

pub fn (expectation Expectation[E]) to_equal[P](provided P) Expectation[E] {
assert_equal(expectation.expected, provided)
return expectation
}

pub fn (expectation Expectation[E]) assert_is[T]() Expectation[E] {
assert_is[T](expectation.expected)
return expectation
}
9 changes: 0 additions & 9 deletions src/type_expectation.v

This file was deleted.

0 comments on commit 470cbdb

Please sign in to comment.