-
-
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.
- Loading branch information
1 parent
2fb179d
commit c66ba2a
Showing
4 changed files
with
87 additions
and
28 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
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('eitherToMaybe', function() { | ||
|
||
it('is a unary function', function() { | ||
eq(typeof S.eitherToMaybe, 'function'); | ||
eq(S.eitherToMaybe.length, 1); | ||
}); | ||
|
||
it('type checks its arguments', function() { | ||
throws(function() { S.eitherToMaybe('left'); }, | ||
errorEq(TypeError, | ||
'Invalid value\n' + | ||
'\n' + | ||
'eitherToMaybe :: Either a b -> Maybe b\n' + | ||
' ^^^^^^^^^^\n' + | ||
' 1\n' + | ||
'\n' + | ||
'1) "left" :: String\n' + | ||
'\n' + | ||
'The value at position 1 is not a member of ‘Either a b’.\n')); | ||
}); | ||
|
||
it('returns a Nothing when applied to a Left', function() { | ||
eq(S.eitherToMaybe(S.Left('Cannot divide by zero')), S.Nothing()); | ||
}); | ||
|
||
it('returns a Just when applied to a Right', function() { | ||
eq(S.eitherToMaybe(S.Right(42)), S.Just(42)); | ||
}); | ||
|
||
}); |
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