https://github.com/robloach/wren-assert
Minimalistic assertion library for unit testing in Wren.
https://github.com/robloach/wren-assert
wren wren-language
Last synced: about 2 months ago
JSON representation
Minimalistic assertion library for unit testing in Wren.
- Host: GitHub
- URL: https://github.com/robloach/wren-assert
- Owner: RobLoach
- License: mit
- Created: 2020-10-18T23:03:28.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-06-10T21:01:33.000Z (almost 4 years ago)
- Last Synced: 2025-03-30T18:02:09.209Z (about 2 months ago)
- Topics: wren, wren-language
- Language: Makefile
- Homepage:
- Size: 21.5 KB
- Stars: 9
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wren-assert
Minimalistic assertion library for unit testing in [Wren](https://wren.io).
## Installation
Copy [`Assert.wren`](Assert.wren) and [`LICENSE`](LICENSE) to your project.
## Usage
The `Assert` class is inspired by [Node.js's `assert` module](https://nodejs.org/api/assert.html), so the methods are similar. When an assert fails, it will issue a [`Fiber.abort()`](https://wren.io/modules/core/fiber.html#fiber.abort(message)).
### Example
``` js
import "./Assert" for AssertAssert.equal(5, 5)
Assert.equal(5, 5, "Expected 5 to equal 5")
Assert[5, 5]
Assert[5, 5, "Expected 5 to equal 5"]Assert.notEqual(5, 10)
Assert.notEqual(5, 10, "Expected 5 to not equal 10")Assert.ok(true)
Assert.ok(true, "True should be truthy")
Assert[true]Assert.notOk(false)
Assert.notOk(false, "False should be falsey")Assert.aborts(Fn.new {
Fiber.abort("This function is expected to abort.")
})Assert.doesNotAbort(Fn.new {
System.print("This function does not abort, as expected.")
})Assert.typeOf(5, Num)
Assert.typeOf(5, Num, "Expected the number to be a Num.")Assert.notTypeOf("Hello World!", Num)
Assert.notTypeOf("Hello World!", Num, "Expected the String to not be a Num.")Assert.countOf([1, 2, 3], 3)
Assert.countOf([1, 2, 3], 3, "Expect a list count of 3.")Assert.deepEqual([1, 2, 3], [1, 2, 3])
Assert.deepEqual([1, 2, 3], [1, 2, 3], "Expected the two lists to be the same.")Assert.exists(5)
Assert.exists(5, "Expected 5 to not be null")Assert.notExists(null)
Assert.notExists(null, "Expected null to be null")Assert.contains([1, 2, 3], 2)
Assert.contains([1, 2, 3], 2, "Expected two to be in the sequence")Assert.disabled = true // Disables assertion checks
```### API
``` js
Assert.equal(actual, expected, [message])
Assert[actual, expected, [message]]
Assert.notEqual(actual, expected, [message])
Assert.ok(value, [message])
Assert[value]
Assert.notOk(value, [message])
Assert.aborts(fn, [message])
Assert.doesNotAbort(fn, [message])
Assert.typeOf(object, type, [message])
Assert.notTypeOf(object, type, [message])
Assert.countOf(list, count, [message])
Assert.deepEqual(actual, expected, [message])
Assert.exists(value, [message])
Assert.notExists(value, [message])
Assert.contains(haystack, needle, [message])
Assert.disabled = true // Disables assertion checks
```## Development
Use [wren-cli](https://github.com/wren-lang/wren-cli) to run the tests...
```
wren_cli tests.wren
```## License
[MIT](License)