Skip to content

Commit

Permalink
Update TypeClass.test to respect constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed Apr 20, 2021
1 parent 9bcb45c commit d7419f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
28 changes: 20 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@
return [];
}

// Array$prototype$equals :: Array a ~> Array a -> Boolean
// Array$prototype$equals :: Setoid a => Array a ~> Array a -> Boolean
function Array$prototype$equals(other) {
if (other.length !== this.length) return false;
for (var idx = 0; idx < this.length; idx += 1) {
Expand All @@ -777,7 +777,7 @@
return true;
}

// Array$prototype$lte :: Array a ~> Array a -> Boolean
// Array$prototype$lte :: Ord a => Array a ~> Array a -> Boolean
function Array$prototype$lte(other) {
for (var idx = 0; true; idx += 1) {
if (idx === this.length) return true;
Expand Down Expand Up @@ -883,15 +883,15 @@
return {};
}

// Object$prototype$equals :: StrMap a ~> StrMap a -> Boolean
// Object$prototype$equals :: Setoid a => StrMap a ~> StrMap a -> Boolean
function Object$prototype$equals(other) {
var self = this;
var keys = sortedKeys (this);
return equals (keys, sortedKeys (other)) &&
keys.every (function(k) { return equals (self[k], other[k]); });
}

// Object$prototype$lte :: StrMap a ~> StrMap a -> Boolean
// Object$prototype$lte :: Ord a => StrMap a ~> StrMap a -> Boolean
function Object$prototype$lte(other) {
var theseKeys = sortedKeys (this);
var otherKeys = sortedKeys (other);
Expand Down Expand Up @@ -1050,8 +1050,12 @@
case 'String#fantasy-land/equals': return String$prototype$equals;
case 'String#fantasy-land/lte': return String$prototype$lte;
case 'String#fantasy-land/concat': return String$prototype$concat;
case 'Array#fantasy-land/equals': return Array$prototype$equals;
case 'Array#fantasy-land/lte': return Array$prototype$lte;
case 'Array#fantasy-land/equals': return (
value.every (Setoid.test) ? Array$prototype$equals : null
);
case 'Array#fantasy-land/lte': return (
value.every (Ord.test) ? Array$prototype$lte : null
);
case 'Array#fantasy-land/concat': return Array$prototype$concat;
case 'Array#fantasy-land/filter': return Array$prototype$filter;
case 'Array#fantasy-land/map': return Array$prototype$map;
Expand All @@ -1064,8 +1068,16 @@
case 'Arguments#fantasy-land/equals': return Arguments$prototype$equals;
case 'Arguments#fantasy-land/lte': return Arguments$prototype$lte;
case 'Error#fantasy-land/equals': return Error$prototype$equals;
case 'Object#fantasy-land/equals': return Object$prototype$equals;
case 'Object#fantasy-land/lte': return Object$prototype$lte;
case 'Object#fantasy-land/equals': return (
(Object.values (value)).every (Setoid.test) ?
Object$prototype$equals :
null
);
case 'Object#fantasy-land/lte': return (
(Object.values (value)).every (Ord.test) ?
Object$prototype$lte :
null
);
case 'Object#fantasy-land/concat': return Object$prototype$concat;
case 'Object#fantasy-land/filter': return Object$prototype$filter;
case 'Object#fantasy-land/map': return Object$prototype$map;
Expand Down
4 changes: 4 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ test ('Setoid', function() {
eq (Z.Setoid.test ([]), true);
eq (Z.Setoid.test ({}), true);
eq (Z.Setoid.test ({'@@type': 'my-package/Quux@1'}), false);
eq (Z.Setoid.test ([{'@@type': 'my-package/Quux@1'}]), false);
eq (Z.Setoid.test ({foo: {'@@type': 'my-package/Quux@1'}}), false);
});

test ('Ord', function() {
Expand All @@ -333,6 +335,8 @@ test ('Ord', function() {
eq (Z.Ord.test ([]), true);
eq (Z.Ord.test ({}), true);
eq (Z.Ord.test (Math.abs), false);
eq (Z.Ord.test ([Math.abs]), false);
eq (Z.Ord.test ({foo: Math.abs}), false);
});

test ('Semigroupoid', function() {
Expand Down

0 comments on commit d7419f6

Please sign in to comment.