-
-
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.
classify: change S.is to take a sanctuary-def Type value
- Loading branch information
1 parent
f945b22
commit 584c980
Showing
5 changed files
with
84 additions
and
98 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
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 |
---|---|---|
@@ -1,54 +1,54 @@ | ||
'use strict'; | ||
|
||
var vm = require('vm'); | ||
var $ = require('sanctuary-def'); | ||
|
||
var S = require('..'); | ||
|
||
var Sum = require('./internal/Sum'); | ||
var eq = require('./internal/eq'); | ||
|
||
|
||
test('is', function() { | ||
|
||
eq(typeof S.is, 'function'); | ||
eq(S.is.length, 2); | ||
eq(S.is.toString(), 'is :: TypeRep a -> Any -> Boolean'); | ||
|
||
eq(S.is(Array, []), true); | ||
eq(S.is(Boolean, false), true); | ||
eq(S.is(Date, new Date(0)), true); | ||
eq(S.is(Function, function() {}), true); | ||
eq(S.is(Number, 0), true); | ||
eq(S.is(Object, {}), true); | ||
eq(S.is(RegExp, /(?:)/), true); | ||
eq(S.is(String, ''), true); | ||
eq(S.is(Boolean, new Boolean(false)), true); | ||
eq(S.is(Number, new Number(0)), true); | ||
eq(S.is(String, new String('')), true); | ||
eq(S.is(Array, null), false); | ||
eq(S.is(Array, undefined), false); | ||
eq(S.is(Array, {}), false); | ||
|
||
eq(S.is(S.Maybe, S.Nothing), true); | ||
eq(S.is(S.Maybe, S.Just(9)), true); | ||
eq(S.is(S.Maybe, S.Left(9)), false); | ||
eq(S.is(S.Maybe, S.Right(9)), false); | ||
|
||
eq(S.is(S.Either, S.Nothing), false); | ||
eq(S.is(S.Either, S.Just(9)), false); | ||
eq(S.is(S.Either, S.Left(9)), true); | ||
eq(S.is(S.Either, S.Right(9)), true); | ||
|
||
function FooBar() {} | ||
FooBar['@@type'] = 'foobar/FooBar'; | ||
function Foo() {} | ||
Foo.prototype = new FooBar(); | ||
function Bar() {} | ||
Bar.prototype = new FooBar(); | ||
|
||
eq(S.is(FooBar, new Foo()), true); | ||
eq(S.is(FooBar, new Bar()), true); | ||
|
||
eq(S.is(Array, vm.runInNewContext('[1, 2, 3]')), true); | ||
eq(S.is(vm.runInNewContext('Array'), [1, 2, 3]), true); | ||
eq(S.is.toString(), 'is :: Type -> Any -> Boolean'); | ||
|
||
eq(S.is($.Boolean, true), true); | ||
eq(S.is($.Boolean, false), true); | ||
eq(S.is($.Boolean, new Boolean(true)), false); | ||
eq(S.is($.Boolean, new Boolean(false)), false); | ||
|
||
eq(S.is($.Array($.Integer), null), false); | ||
eq(S.is($.Array($.Integer), undefined), false); | ||
eq(S.is($.Array($.Integer), ['1', '2', '3']), false); | ||
eq(S.is($.Array($.Integer), [1, 2, 3.14]), false); | ||
eq(S.is($.Array($.Integer), [1, 2, 3]), true); | ||
eq(S.is($.Array($.Integer), []), true); | ||
|
||
eq(S.is(S.MaybeType($.Integer), S.Nothing), true); | ||
eq(S.is(S.MaybeType($.Integer), S.Just(0)), true); | ||
eq(S.is(S.MaybeType($.Integer), S.Left(0)), false); | ||
eq(S.is(S.MaybeType($.Integer), S.Right(0)), false); | ||
|
||
eq(S.is(S.EitherType($.String, $.Integer), S.Nothing), false); | ||
eq(S.is(S.EitherType($.String, $.Integer), S.Just(0)), false); | ||
eq(S.is(S.EitherType($.String, $.Integer), S.Left(0)), false); | ||
eq(S.is(S.EitherType($.String, $.Integer), S.Right('')), false); | ||
eq(S.is(S.EitherType($.String, $.Integer), S.Left('')), true); | ||
eq(S.is(S.EitherType($.String, $.Integer), S.Right(0)), true); | ||
|
||
var a = $.TypeVariable('a'); | ||
|
||
eq(S.is($.Array(a), []), true); | ||
eq(S.is($.Array(a), [1, 2, 3]), true); | ||
eq(S.is($.Array(a), ['foo', 'bar', 'baz']), true); | ||
eq(S.is($.Array(a), ['foo', true, 42]), false); | ||
eq(S.is($.Array(a), [Sum(1), Sum(2), Sum(3)]), false); | ||
|
||
eq(S.create({checkTypes: true, env: []}).is($.Array(a), []), true); | ||
eq(S.create({checkTypes: true, env: []}).is($.Array(a), [1, 2, 3]), false); | ||
eq(S.create({checkTypes: true, env: [$.Number]}).is($.Array(a), [1, 2, 3]), true); | ||
eq(S.create({checkTypes: true, env: [Sum.Type]}).is($.Array(a), [Sum(1), Sum(2), Sum(3)]), true); | ||
|
||
}); |
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