Code Monkey home page Code Monkey logo

purescript-assert's Introduction

PureScript

A small strongly typed programming language with expressive types that compiles to JavaScript, written in and inspired by Haskell.

Hackage Build Status

Language info

Resources

Help!

Community Spaces

The following spaces are governed by the PureScript Community Code of Conduct. The majority of PureScript users use these spaces to discuss and collaborate on PureScript-related topics:

Unaffiliated Spaces

Some PureScript users also collaborate in the below spaces. These do not fall under the code of conduct linked above. They may have no code of conduct or one very different than the one linked above.

purescript-assert's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

purescript-assert's Issues

Can we make assertion output more readable?

Some libraries outside of core use this library as their way of testing. The problem is that the output is pretty hard to understand. How would we feel about adding a few small helpers to make the output better?

assertEqual  forall a eff. Eq a => Show a => { expected :: a, actual :: a } -> Eff (assert :: ASSERT | eff) Unit
assertEqual {actual, expected} = do
  unless result $ log message
  assert' message result
  where
  message = "Expected: " <> show expected <> "\nActual:   " <> show actual
  result = actual == expected

assertTrue :: forall eff. Boolean -> Eff (assert :: ASSERT | eff) Unit
assertTrue actual = assertEqual { actual, expected: true }

assertFalse :: forall eff. Boolean -> Eff (assert :: ASSERT | eff) Unit
assertFalse actual = assertEqual { actual, expected: false }

Evaluate error message only after assertion failure in assertEqual

Another thing that bothers me a little is that the full error message in assertEqual gets evaluated even if it is not needed. show can be quite expensive for large inputs.

Possible fix is to delay the first argument of assert' (some renaming should also be done to avoid breaking the API)

foreign import assert'
  :: (Unit -> String)
  -> Boolean
  -> Effect Unit

Should I make a PR for this issue, or is it too insignificant to care about?

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.