-
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from plaid/dc-maybe-to-nullable
maybe: add S.maybeToNullable
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
var throws = require('assert').throws; | ||
|
||
var eq = require('./utils').eq; | ||
var errorEq = require('./utils').errorEq; | ||
var S = require('..'); | ||
|
||
|
||
describe('maybeToNullable', function() { | ||
|
||
it('is a unary function', function() { | ||
eq(typeof S.maybeToNullable, 'function'); | ||
eq(S.maybeToNullable.length, 1); | ||
}); | ||
|
||
it('type checks its arguments', function() { | ||
throws(function() { S.maybeToNullable(/XXX/); }, | ||
errorEq(TypeError, | ||
'Invalid value\n' + | ||
'\n' + | ||
'maybeToNullable :: Maybe a -> Nullable a\n' + | ||
' ^^^^^^^\n' + | ||
' 1\n' + | ||
'\n' + | ||
'1) /XXX/ :: RegExp\n' + | ||
'\n' + | ||
'The value at position 1 is not a member of ‘Maybe a’.\n')); | ||
}); | ||
|
||
it('can be applied to a Nothing', function() { | ||
eq(S.maybeToNullable(S.Nothing()), null); | ||
}); | ||
|
||
it('can be applied to a Just', function() { | ||
eq(S.maybeToNullable(S.Just(42)), 42); | ||
}); | ||
|
||
}); |