Coder Social home page Coder Social logo

wren-assert's Introduction

wren-assert

Minimalistic assertion library for unit testing in Wren.

Installation

Copy Assert.wren and LICENSE to your project.

Usage

The Assert class is inspired by Node.js's assert module, so the methods are similar. When an assert fails, it will issue a Fiber.abort().

Example

import "./Assert" for Assert

Assert.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

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 to run the tests...

wren_cli tests.wren

License

MIT

wren-assert's People

Contributors

joshgoebel avatar robloach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

joshgoebel

wren-assert's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.