-
-
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
Showing
3 changed files
with
158 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,58 @@ | ||
'use strict'; | ||
|
||
var throws = require('assert').throws; | ||
|
||
var eq = require('./utils').eq; | ||
var errorEq = require('./utils').errorEq; | ||
var S = require('..'); | ||
|
||
|
||
describe('keys', function() { | ||
|
||
it('is a unary function', function() { | ||
eq(typeof S.keys, 'function'); | ||
eq(S.keys.length, 1); | ||
}); | ||
|
||
it('type checks its arguments', function() { | ||
throws(function() { S.keys('xxx'); }, | ||
errorEq(TypeError, | ||
'Invalid value\n' + | ||
'\n' + | ||
'keys :: StrMap a -> Array String\n' + | ||
' ^^^^^^^^\n' + | ||
' 1\n' + | ||
'\n' + | ||
'1) "xxx" :: String\n' + | ||
'\n' + | ||
'The value at position 1 is not a member of ‘StrMap a’.\n')); | ||
|
||
throws(function() { S.keys({a: '1', b: 2, c: '3'}); }, | ||
errorEq(TypeError, | ||
'Type-variable constraint violation\n' + | ||
'\n' + | ||
'keys :: StrMap a -> Array String\n' + | ||
' ^\n' + | ||
' 1\n' + | ||
'\n' + | ||
'1) "1" :: String\n' + | ||
' 2 :: Number, FiniteNumber, NonZeroFiniteNumber, Integer, ValidNumber\n' + | ||
' "3" :: String\n' + | ||
'\n' + | ||
'Since there is no type of which all the above values are members, the type-variable constraint has been violated.\n')); | ||
}); | ||
|
||
it("returns an array of the given object's own keys", function() { | ||
eq(S.keys({a: 1, b: 2, c: 3}).sort(), ['a', 'b', 'c']); | ||
}); | ||
|
||
it('does not include prototype properties', function() { | ||
var proto = {a: 1, b: 2}; | ||
var obj = Object.create(proto); | ||
obj.c = 3; | ||
obj.d = 4; | ||
|
||
eq(S.keys(obj).sort(), ['c', 'd']); | ||
}); | ||
|
||
}); |
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,58 @@ | ||
'use strict'; | ||
|
||
var throws = require('assert').throws; | ||
|
||
var eq = require('./utils').eq; | ||
var errorEq = require('./utils').errorEq; | ||
var S = require('..'); | ||
|
||
|
||
describe('values', function() { | ||
|
||
it('is a unary function', function() { | ||
eq(typeof S.values, 'function'); | ||
eq(S.values.length, 1); | ||
}); | ||
|
||
it('type checks its arguments', function() { | ||
throws(function() { S.values('xxx'); }, | ||
errorEq(TypeError, | ||
'Invalid value\n' + | ||
'\n' + | ||
'values :: StrMap a -> Array a\n' + | ||
' ^^^^^^^^\n' + | ||
' 1\n' + | ||
'\n' + | ||
'1) "xxx" :: String\n' + | ||
'\n' + | ||
'The value at position 1 is not a member of ‘StrMap a’.\n')); | ||
|
||
throws(function() { S.values({a: '1', b: 2, c: '3'}); }, | ||
errorEq(TypeError, | ||
'Type-variable constraint violation\n' + | ||
'\n' + | ||
'values :: StrMap a -> Array a\n' + | ||
' ^\n' + | ||
' 1\n' + | ||
'\n' + | ||
'1) "1" :: String\n' + | ||
' 2 :: Number, FiniteNumber, NonZeroFiniteNumber, Integer, ValidNumber\n' + | ||
' "3" :: String\n' + | ||
'\n' + | ||
'Since there is no type of which all the above values are members, the type-variable constraint has been violated.\n')); | ||
}); | ||
|
||
it("returns an array of the given object's own values", function() { | ||
eq(S.values({a: 1, b: 2, c: 3}).sort(), [1, 2, 3]); | ||
}); | ||
|
||
it('does not include prototype values', function() { | ||
var proto = {a: 1, b: 2}; | ||
var obj = Object.create(proto); | ||
obj.c = 3; | ||
obj.d = 4; | ||
|
||
eq(S.values(obj).sort(), [3, 4]); | ||
}); | ||
|
||
}); |