diff --git a/README.md b/README.md index f568b53..b672cc4 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,9 @@ utilities and middleware for the client. - [Install](#install) - [Use](#use) -- [API](#api) - [new set.Algebra(compares...)](#new-setalgebracompares) - - [compares Object\](#compares-objectstringcomparator) - - [comparator(aValue, bValue, a, b, prop, algebra)](#comparatoravalue-bvalue-a-b-prop-algebra) + - [Compares Object\](#compares-objectstringprop) + - [prop(aValue, bValue, a, b, prop, algebra)](#propavalue-bvalue-a-b-prop-algebra) - [algebra.difference(a, b)](#algebradifferencea-b) - [algebra.equal(a, b)](#algebraequala-b) - [algebra.getSubset(a, b, bData)](#algebragetsubseta-b-bdata) @@ -32,12 +31,12 @@ utilities and middleware for the client. - [algebra.properSubset(a, b)](#algebrapropersubseta-b) - [algebra.subset(a, b)](#algebrasubseta-b) - [algebra.union(a, b)](#algebrauniona-b) -- [can-set.props Object](#can-setcomparators-object) - - [set.props.boolean(property)](#setcomparatorsbooleanproperty) - - [set.props.rangeInclusive(startIndexProperty, endIndexProperty)](#setcomparatorsrangeinclusivestartindexproperty-endindexproperty) - - [set.props.enum(property, propertyValues)](#setcomparatorsenumproperty-propertyvalues) - - [set.props.sort(prop, [sortFunc])](#setcomparatorssortprop-sortfunc) - - [set.props.id(prop)](#setcomparatorsidprop) +- [props Object](#props-object) + - [set.props.boolean(property)](#setpropsbooleanproperty) + - [set.props.rangeInclusive(startIndexProperty, endIndexProperty)](#setpropsrangeinclusivestartindexproperty-endindexproperty) + - [set.props.enum(property, propertyValues)](#setpropsenumproperty-propertyvalues) + - [set.props.sort(prop, [sortFunc])](#setpropssortprop-sortfunc) + - [set.props.id(prop)](#setpropsidprop) - [new set.Translate(clauseType, propertyName)](#new-settranslateclausetype-propertyname) - [Contributing](#contributing) @@ -124,6 +123,7 @@ var getTodos = function(set, cb) { ``` + ## API @@ -142,18 +142,19 @@ var algebra = new set.Algebra( ``` -1. __compares__ {[compares](#compares-objectstringcomparatorcomparatoravalue-bvalue-a-b-prop-algebra)}: +1. __compares__ {[Compares](#compares-objectstringproppropavalue-bvalue-a-b-prop-algebra)}: Each argument is a compares. These - are returned by the functions on [can-set.props](#-object) or can be created + are returned by the functions on [props](#props-object) or can be created manually. -- __returns__ {[can-set.Algebra](#new-setalgebracompares)([compares](#compares-objectstringcomparatorcomparatoravalue-bvalue-a-b-prop-algebra))}: + +- __returns__ {[Algebra](#new-setalgebracompares)([compares](#compares-objectstringproppropavalue-bvalue-a-b-prop-algebra))}: Returns an instance of an algebra. -### compares `{Object\}` +### Compares `{Object\}` -An object of property names and `comparator` functions. +An object of property names and `prop` functions. ```js { // return `true` if the values should be considered the same: @@ -167,10 +168,10 @@ An object of property names and `comparator` functions. -### comparator(aValue, bValue, a, b, prop, algebra) +### prop(aValue, bValue, a, b, prop, algebra) -A comparator function returns algebra values for two values for a given property. +A prop function returns algebra values for two values for a given property. 1. __aValue__ {*}: @@ -183,7 +184,7 @@ A comparator function returns algebra values for two values for a given property The B set in a set difference A and B (A B). - __returns__ {Object|Boolean}: - A comparator function should either return a Boolean which indicates if `aValue` and `bValue` are + A prop function should either return a Boolean which indicates if `aValue` and `bValue` are equal or an `AlgebraResult` object that details information about the union, intersection, and difference of `aValue` and `bValue`. An `AlgebraResult` object has the following values: @@ -230,12 +231,12 @@ algebra2.difference( {completed: true}, {} ) //-> false ``` -1. __a__ {can-set/Set}: +1. __a__ {[Set](#set-object)}: A set. -1. __b__ {can-set/Set}: +1. __b__ {[Set](#set-object)}: A set. -- __returns__ {can-set/Set|Boolean}: +- __returns__ {[Set](#set-object)|Boolean}: If an object is returned, it is difference of sets _A_ and _B_ (_A_ \ _B_). If `true` is returned, that means that _B_ is a subset of _A_, but no set object @@ -254,9 +255,9 @@ algebra2.difference( {completed: true}, {} ) //-> false ``` -1. __a__ {can-set/Set}: +1. __a__ {[Set](#set-object)}: A set. -1. __b__ {can-set/Set}: +1. __b__ {[Set](#set-object)}: A set. - __returns__ {Boolean}: @@ -280,9 +281,9 @@ algebra.getSubset( ``` -1. __a__ {can-set/Set}: +1. __a__ {[Set](#set-object)}: The set whose data will be returned. -1. __b__ {can-set/Set}: +1. __b__ {[Set](#set-object)}: A superset of set `a`. 1. __bData__ {Array\}: The data in set `b`. @@ -309,9 +310,9 @@ algebra.getUnion( ``` -1. __a__ {can-set/Set}: +1. __a__ {[Set](#set-object)}: A set. -1. __b__ {can-set/Set}: +1. __b__ {[Set](#set-object)}: A set. 1. __aItems__ {Array\}: Set `a`'s items. @@ -339,12 +340,12 @@ algebra.index( ``` The default sort property is what is specified by -[can-set.props.id](#setcomparatorsidprop). This means if that if the sort property +[id](#setpropsidprop). This means if that if the sort property is not specified, it will assume the set is sorted by the specified id property. -1. __set__ {can-set/Set}: +1. __set__ {[Set](#set-object)}: The `set` that describes `items`. 1. __items__ {Array\}: An array of data objects. @@ -370,7 +371,7 @@ algebra.count({}) //-> Infinity ``` -1. __set__ {can-set/Set}: +1. __set__ {[Set](#set-object)}: [description] - __returns__ {Number}: @@ -394,7 +395,7 @@ algebra.has( ``` -1. __set__ {can-set/Set}: +1. __set__ {[Set](#set-object)}: A set. 1. __props__ {Object}: An instance's raw data. @@ -415,9 +416,9 @@ algebra.properSubset({}, {}) //-> false ``` -1. __a__ {can-set/Set}: +1. __a__ {[Set](#set-object)}: A set. -1. __b__ {can-set/Set}: +1. __b__ {[Set](#set-object)}: A set. - __returns__ {Boolean}: @@ -435,9 +436,9 @@ algebra.subset({}, {}) //-> true ``` -1. __a__ {can-set/Set}: +1. __a__ {[Set](#set-object)}: A set. -1. __b__ {can-set/Set}: +1. __b__ {[Set](#set-object)}: A set. - __returns__ {Boolean}: @@ -457,22 +458,23 @@ algebra.union( ``` -1. __a__ {can-set/Set}: +1. __a__ {[Set](#set-object)}: A set. -1. __b__ {can-set/Set}: +1. __b__ {[Set](#set-object)}: A set. -- __returns__ {can-set/Set|undefined}: +- __returns__ {[Set](#set-object)|undefined}: If an object is returned, it is the union of _A_ and _B_ (_A_ ∪ _B_). If `undefined` is returned, it means a union can't be created. -## can-set.props `{Object}` +## props `{Object}` -Contains a collection of comparator generating functions. +Contains a collection of prop generating functions. The following functions create `compares` objects that can be mixed together to create a set `Algebra`. ```js +var set = require("can-set"); var algebra = new set.Algebra( { // ignore this property in set algebra @@ -501,28 +503,37 @@ A(undefined) \ B(false) = true It understands that `true` and `false` are complementary sets that combined to `undefined`. Another way to think of this is that if you load `{complete: false}` and `{complete: true}` you've loaded `{}`. +1. __property__ {String}: + The name of the boolean property. +1. __A__ {[Compares](#compares-objectstringproppropavalue-bvalue-a-b-prop-algebra)}: + `Compares` object that can be an argument to [Algebra](#new-setalgebracompares) + ### set.props.rangeInclusive(startIndexProperty, endIndexProperty) -Makes a comparator for two ranged properties that specify a range of items +Makes a prop for two ranged properties that specify a range of items that includes both the startIndex and endIndex. For example, a range of [0,20] loads 21 items. +``` +set.props.rangeInclusive("start","end") +``` + 1. __startIndexProperty__ {String}: The starting property name 1. __endIndexProperty__ {String}: The ending property name -- __returns__ {[compares](#compares-objectstringcomparatorcomparatoravalue-bvalue-a-b-prop-algebra)}: - Returns a comparator +- __returns__ {[Compares](#compares-objectstringproppropavalue-bvalue-a-b-prop-algebra)}: + Returns a prop ### set.props.enum(property, propertyValues) -Makes a comparator for a set of values. +Makes a prop for a set of values. ``` var compare = set.props.enum("type", ["new","accepted","pending","resolved"]) @@ -555,7 +566,7 @@ algebra.index( sortable behavior. The default behavior assumes the sort property value looks like `PROPERTY DIRECTION` (ex: `name desc`). -- __returns__ {[compares](#compares-objectstringcomparatorcomparatoravalue-bvalue-a-b-prop-algebra)}: +- __returns__ {[Compares](#compares-objectstringproppropavalue-bvalue-a-b-prop-algebra)}: Returns a compares that can be used to create a `set.Algebra`. @@ -565,7 +576,7 @@ algebra.index( Defines the property name on items that uniquely identifies them. This is the default sorted property if no -[can-set.props.sort](#setcomparatorssortprop-sortfunc) is provided. +[sort](#setpropssortprop-sortfunc) is provided. ```js var algebra = new set.Algebra(set.props.id("_id")); @@ -584,7 +595,7 @@ algebra.index( 1. __prop__ {String}: The property name that defines the unique property id. -- __returns__ {[compares](#compares-objectstringcomparatorcomparatoravalue-bvalue-a-b-prop-algebra)}: +- __returns__ {[Compares](#compares-objectstringproppropavalue-bvalue-a-b-prop-algebra)}: Returns a compares that can be used to create a `set.Algebra`. @@ -613,15 +624,11 @@ within a nested object. 1. __propertyName__ {String|Object}: The property name which contains the clauses's properties. -- __returns__ {set.compares}: +- __returns__ {[Compares](#compares-objectstringproppropavalue-bvalue-a-b-prop-algebra)}: A set compares object that can do the translation. - - - - ## Contributing To setup your dev environment: diff --git a/docs/apis.json b/docs/apis.json index 475b955..2f407fe 100644 --- a/docs/apis.json +++ b/docs/apis.json @@ -1,7 +1,7 @@ [ {"can-set.Algebra": [ "can-set.compares", - "can-set.comparator", + "can-set.prop", "can-set.Algebra.prototype.difference", "can-set.Algebra.prototype.equal", "can-set.Algebra.prototype.getSubset", diff --git a/docs/can-set.algebra.md b/docs/can-set.algebra.md index cdfa15e..64e4cd8 100644 --- a/docs/can-set.algebra.md +++ b/docs/can-set.algebra.md @@ -22,4 +22,5 @@ var algebra = new set.Algebra( are returned by the functions on [can-set.props] or can be created manually. + @return {can-set.Algebra} Returns an instance of an algebra. diff --git a/docs/can-set.comparator.md b/docs/can-set.comparator.md index 8ecd213..7f0c74f 100644 --- a/docs/can-set.comparator.md +++ b/docs/can-set.comparator.md @@ -1,15 +1,15 @@ -@typedef {function} can-set.comparator Comparator +@typedef {function} can-set.prop Prop @parent can-set.types -@signature `comparator(aValue, bValue, a, b, prop, algebra)` +@signature `prop(aValue, bValue, a, b, prop, algebra)` -A comparator function returns algebra values for two values for a given property. +A prop function returns algebra values for two values for a given property. @param {*} aValue The value of A's property in a set difference A and B (A \ B). @param {*} bValue The value of A's property in a set difference A and B (A \ B). @param {*} a The A set in a set difference A and B (A \ B). @param {*} b The B set in a set difference A and B (A \ B). - @return {Object|Boolean} A comparator function should either return a Boolean which indicates if `aValue` and `bValue` are + @return {Object|Boolean} A prop function should either return a Boolean which indicates if `aValue` and `bValue` are equal or an `AlgebraResult` object that details information about the union, intersection, and difference of `aValue` and `bValue`. An `AlgebraResult` object has the following values: diff --git a/docs/can-set.compares.md b/docs/can-set.compares.md index f9acb37..3be8359 100644 --- a/docs/can-set.compares.md +++ b/docs/can-set.compares.md @@ -1,7 +1,7 @@ -@typedef {Object} can-set.compares Compares +@typedef {Object} can-set.compares Compares @parent can-set.types -@description An object of property names and `comparator` functions. +@description An object of property names and `prop` functions. ```js { @@ -13,4 +13,4 @@ ``` -@option {Object} +@option {Object} diff --git a/docs/can-set.props.md b/docs/can-set.props.md index 30ab263..dc7dc82 100644 --- a/docs/can-set.props.md +++ b/docs/can-set.props.md @@ -1,7 +1,8 @@ @property {{}} can-set.props props @parent can-set.properties -@description Contains a collection of comparator generating functions. + +@description Contains a collection of prop generating functions. The following functions create `compares` objects that can be mixed together to create a set `Algebra`. diff --git a/src/comparators_test.js b/src/comparators_test.js deleted file mode 100644 index 756f1ff..0000000 --- a/src/comparators_test.js +++ /dev/null @@ -1,8 +0,0 @@ -var QUnit = require("steal-qunit"); - -QUnit.module("comparators"); - -require('./comparator_tests/sort_test'); -require('./comparator_tests/rangeInclusive_test'); -require('./comparator_tests/boolean_test'); -require('./comparator_tests/enum_test'); diff --git a/src/compare.js b/src/compare.js index dda0c83..cb33789 100644 --- a/src/compare.js +++ b/src/compare.js @@ -186,7 +186,7 @@ module.exports = compareHelpers = { options.getSubsets.push(compareResult.getSubset); } } - if(compareResult.intersection === h.ignoreType || compareResult.difference === h.ignoreType) { // as in the case of a sort comparator + if(compareResult.intersection === h.ignoreType || compareResult.difference === h.ignoreType) { // as in the case of a sort props return true; } // A \ B subset intersects in both directions diff --git a/src/get.js b/src/get.js index cfd697b..4e3f5f0 100644 --- a/src/get.js +++ b/src/get.js @@ -2,11 +2,11 @@ var compare = require("./compare"); var h = require("./helpers"); var each = require("can-util/js/each/each"); -var filterData = function(data, clause, comparators) { +var filterData = function(data, clause, props) { // reduce response to items in data that meet clause criteria return h.filter.call(data, function(item) { var isSubset = compare.subset(item, clause, undefined, undefined, - undefined, comparators, {}); + undefined, props, {}); return isSubset; }); diff --git a/src/get_test.js b/src/get_test.js index 2250adf..ab1f1bc 100644 --- a/src/get_test.js +++ b/src/get_test.js @@ -1,6 +1,6 @@ var set = require("./set"); var QUnit = require("steal-qunit"); -var comparators = require("./comparators"); +var props = require("./props"); var h = require("./helpers"); QUnit.module("set/src/set-core get methods"); @@ -38,7 +38,7 @@ test("getSubset against non ranged set", function(){ * ] */ var res = set.getSubset({ type: 'critical', start: 1, end: 3 }, {}, items, - comparators.rangeInclusive("start", "end")); + props.rangeInclusive("start", "end")); deepEqual(res && h.map.call(res, getId), [2,4,6]); }); @@ -64,8 +64,8 @@ test("getSubset ordered ascending and paginated", function() { * ] */ var algebra = new set.Algebra( - comparators.sort('sort'), - comparators.rangeInclusive('start','end') + props.sort('sort'), + props.rangeInclusive('start','end') ); var res = set.getSubset( @@ -92,8 +92,8 @@ test("getSubset ordered descending and paginated", function() { * 3. set a is further reduced to the entities at indices 1 through 3 */ var algebra = new set.Algebra( - comparators.sort('sort'), - comparators.rangeInclusive('start','end') + props.sort('sort'), + props.rangeInclusive('start','end') ); var res = set.getSubset( @@ -109,7 +109,7 @@ test("getSubset against paginated set", function(){ {type: 'critical', start: 21, end: 23}, {type: 'critical', start: 20, end: 27}, items, - comparators.rangeInclusive("start","end") ); + props.rangeInclusive("start","end") ); deepEqual(res && h.map.call(res, getId), [2,4,6]); }); @@ -130,10 +130,10 @@ test("getUnion basics", function(){ }); test("getUnion against ranged sets", function(){ - var union = set.getUnion({start: 10, end: 13},{start: 14, end: 17},items.slice(0,4), items.slice(4,8), comparators.rangeInclusive("start","end")); + var union = set.getUnion({start: 10, end: 13},{start: 14, end: 17},items.slice(0,4), items.slice(4,8), props.rangeInclusive("start","end")); deepEqual(union, items); - union = set.getUnion({start: 14, end: 17}, {start: 10, end: 13}, items.slice(4,8),items.slice(0,4), comparators.rangeInclusive("start","end")); + union = set.getUnion({start: 14, end: 17}, {start: 10, end: 13}, items.slice(4,8),items.slice(0,4), props.rangeInclusive("start","end")); deepEqual(union, items, "disjoint after"); }); @@ -143,7 +143,7 @@ test("getUnion against overlapping ranged sets", function(){ {start: 13, end: 17}, items.slice(0,5), items.slice(3,8), - comparators.rangeInclusive("start","end")); + props.rangeInclusive("start","end")); deepEqual(union, items); @@ -152,7 +152,7 @@ test("getUnion against overlapping ranged sets", function(){ {start: 11, end: 17}, items.slice(0,2), items.slice(1,8), - comparators.rangeInclusive("start","end")); + props.rangeInclusive("start","end")); deepEqual(union, items); @@ -161,13 +161,13 @@ test("getUnion against overlapping ranged sets", function(){ {start: 10, end: 11}, items.slice(1,8), items.slice(0,2), - comparators.rangeInclusive("start","end")); + props.rangeInclusive("start","end")); deepEqual(union, items); }); test("getSubset passed same object works (#3)", function(){ - var algebra = new set.Algebra(comparators.rangeInclusive("start","end")); + var algebra = new set.Algebra(props.rangeInclusive("start","end")); var setObj = {start: 1, end: 2}; var items = algebra.getSubset(setObj, setObj, [{id: 1}]); deepEqual(items, [{id: 1}]); diff --git a/src/comparator_tests/boolean_test.js b/src/prop_tests/boolean_test.js similarity index 64% rename from src/comparator_tests/boolean_test.js rename to src/prop_tests/boolean_test.js index 4d53284..74da644 100644 --- a/src/comparator_tests/boolean_test.js +++ b/src/prop_tests/boolean_test.js @@ -1,12 +1,12 @@ var QUnit = require("steal-qunit"); var set = require('src/set-core'), - comparators = require("src/comparators"); + props = require("src/props"); -QUnit.module("comparators.boolean"); +QUnit.module("props.boolean"); /* - * For the boolean comparator, we define sets like so: + * For the boolean prop, we define sets like so: * * For a property p, * x ∈ {} | x.p = true @@ -16,7 +16,7 @@ QUnit.module("comparators.boolean"); */ test('boolean set.difference', function() { - var comparator = comparators.boolean('completed'); + var prop = props.boolean('completed'); /* * x ∈ {} | x.completed = true OR x.completed = false @@ -24,7 +24,7 @@ test('boolean set.difference', function() { * * z ∈ (X / Y) | y.completed = false */ - var res = set.difference({} , { completed: true }, comparator); + var res = set.difference({} , { completed: true }, prop); deepEqual(res, {completed: false}, "inverse of true"); /* @@ -33,7 +33,7 @@ test('boolean set.difference', function() { * * z ∈ (X / Y) | y.completed = false */ - res = set.difference({}, { completed: false }, comparator); + res = set.difference({}, { completed: false }, prop); deepEqual(res, {completed: true} , "inverse of false"); }); @@ -45,8 +45,8 @@ test('boolean set.difference', function() { * (X U Y) = c */ test('boolean set.union', function(){ - var comparator = comparators.boolean('completed'); - var res = set.union({completed: false} , { completed: true }, comparator); + var prop = props.boolean('completed'); + var res = set.union({completed: false} , { completed: true }, prop); deepEqual(res, {}, "union of true and false is entire boolean set"); }); @@ -70,28 +70,28 @@ test('boolean set.union', function(){ * Only requires that one property is always on an element */ test('boolean set.intersection', function(){ - var comparator = comparators.boolean('completed'); - var res = set.intersection({foo: "bar"} , { completed: true }, comparator); + var prop = props.boolean('completed'); + var res = set.intersection({foo: "bar"} , { completed: true }, prop); deepEqual(res, {foo: "bar", completed: true}, "intersection is false (#4)"); }); test('strings false and true are treated as booleans', function(){ - var comparator = comparators.boolean('completed'); - var res = set.subset({} , { completed: "true" }, comparator); + var prop = props.boolean('completed'); + var res = set.subset({} , { completed: "true" }, prop); ok(!res, "{} and 'true' not a subset"); - res = set.subset({} , { completed: "false" }, comparator); + res = set.subset({} , { completed: "false" }, prop); ok(!res, "{} and 'false' not a subset"); - res = set.subset({ completed: "true" }, {}, comparator); + res = set.subset({ completed: "true" }, {}, prop); ok(res, "subset"); - res = set.subset({ completed: "false" }, {}, comparator); + res = set.subset({ completed: "false" }, {}, prop); ok(res, "subset"); - res = set.union({completed: 'false'} , { completed: 'true' }, comparator); + res = set.union({completed: 'false'} , { completed: 'true' }, prop); deepEqual(res, {}, "union of true and false is entire boolean set"); - res = set.equal({completed: false} , { completed: "false" }, comparator); + res = set.equal({completed: false} , { completed: "false" }, prop); ok(res, "false and 'false'"); }); diff --git a/src/comparator_tests/enum_test.js b/src/prop_tests/enum_test.js similarity index 72% rename from src/comparator_tests/enum_test.js rename to src/prop_tests/enum_test.js index 150843e..f281d26 100644 --- a/src/comparator_tests/enum_test.js +++ b/src/prop_tests/enum_test.js @@ -1,16 +1,16 @@ var QUnit = require("steal-qunit"); var set = require('src/set-core'), - comparators = require("src/comparators"); + props = require("src/props"); -QUnit.module("comparators.enum"); +QUnit.module("props.enum"); test('enum set.intersection', function(){ /* * For a property p, * x ∈ {} | x.p exists */ - var comparator = comparators["enum"]('type',['new','prep','deliver','delivered']); + var prop = props["enum"]('type',['new','prep','deliver','delivered']); /* * x ∈ X ∀ x @@ -18,7 +18,7 @@ test('enum set.intersection', function(){ * * (X ∩ Y) = Y */ - var res = set.intersection({} , { type: 'new' }, comparator); + var res = set.intersection({} , { type: 'new' }, prop); deepEqual(res, {type: 'new' }, "single enum intersected with universal set is idempotent"); /* @@ -27,7 +27,7 @@ test('enum set.intersection', function(){ * * (X ∩ Y) = Y */ - res = set.intersection({} , { type: ['new','prep'] }, comparator); + res = set.intersection({} , { type: ['new','prep'] }, prop); deepEqual(res, {type: ['new','prep'] }, "array enum intersected with unversal set is idempotent"); /* @@ -36,7 +36,7 @@ test('enum set.intersection', function(){ * * z ∈ (X ∩ Y) | z.type = 'prep' */ - res = set.intersection({type: ['prep'] } , { type: ['new','prep'] }, comparator); + res = set.intersection({type: ['prep'] } , { type: ['new','prep'] }, prop); deepEqual(res, {type: 'prep' }, "items v items intersection"); @@ -46,7 +46,7 @@ test('enum set.intersection', function(){ * * (X ∩ Y) = Y */ - res = set.intersection({type: [] } , { type: ['new','prep'] }, comparator); + res = set.intersection({type: [] } , { type: ['new','prep'] }, prop); deepEqual(res, {type: ['new','prep'] }, "empty v array intersection"); /* @@ -55,12 +55,12 @@ test('enum set.intersection', function(){ * * (X ∩ Y) = X */ - res = set.intersection({ type: 'new' },{}, comparator); + res = set.intersection({ type: 'new' },{}, prop); deepEqual(res, {type: 'new' }, "single v all"); }); test('enum set.difference', function(){ - var comparator = comparators["enum"]('type',['new','prep','deliver','delivered']); + var prop = props["enum"]('type',['new','prep','deliver','delivered']); /* * x ∈ {} | x.type ∈ ['new', 'prep', 'deliver', 'delivered'] */ @@ -71,7 +71,7 @@ test('enum set.difference', function(){ * * z ∈ ({} / Y) | z.type ∈ ['prep', 'deliver', 'delivered'] */ - var res = set.difference({} , { type: 'new' }, comparator); + var res = set.difference({} , { type: 'new' }, prop); deepEqual(res, {type: ['prep','deliver','delivered'] }, "difference from universal set"); /* @@ -80,7 +80,7 @@ test('enum set.difference', function(){ * * z ∈ ({} / Y) | z.type = ['deliver', 'delivered'] */ - res = set.difference({} , { type: ['new','prep'] }, comparator); + res = set.difference({} , { type: ['new','prep'] }, prop); deepEqual(res, {type: ['deliver','delivered'] }, "difference from universal set"); /* @@ -89,13 +89,13 @@ test('enum set.difference', function(){ * * X / Y = ∅ */ - res = set.difference({type: ['prep'] } , { type: ['new','prep'] }, comparator); + res = set.difference({type: ['prep'] } , { type: ['new','prep'] }, prop); deepEqual(res, false, "difference from a superset"); /* * {} = {type: []} */ - res = set.difference({type: [] } , { type: ['new','prep'] }, comparator); + res = set.difference({type: [] } , { type: ['new','prep'] }, prop); deepEqual(res, {type: ['deliver','delivered'] }, "empty enum definition is same as universal set"); /* @@ -104,12 +104,12 @@ test('enum set.difference', function(){ * * X / {} = ∅ */ - res = set.difference({ type: 'new' },{}, comparator); + res = set.difference({ type: 'new' },{}, prop); deepEqual(res, false, "all"); }); test('enum set.union', function(){ - var comparator = comparators["enum"]('type',['new','prep','deliver','delivered']); + var prop = props["enum"]('type',['new','prep','deliver','delivered']); /* * x ∈ {} | x.type ∈ ['new', 'prep', 'deliver', 'delivered'] * ({} U Y) = {} ∀ Y @@ -118,13 +118,13 @@ test('enum set.union', function(){ /* * ({} U Y) = {} ∀ Y */ - var res = set.union({} , { type: 'new' }, comparator); + var res = set.union({} , { type: 'new' }, prop); deepEqual(res, {}, "all"); /* * ({} U Y) = {} ∀ Y */ - res = set.union({} , { type: ['new','prep'] }, comparator); + res = set.union({} , { type: ['new','prep'] }, prop); deepEqual(res, {}, "intersection"); @@ -132,7 +132,7 @@ test('enum set.union', function(){ * X ⊂ Y * (X U Y) = Y */ - res = set.union({type: ['prep'] } , { type: ['new','prep'] }, comparator); + res = set.union({type: ['prep'] } , { type: ['new','prep'] }, prop); deepEqual(res, { type: ['prep','new'] }, "union of a superset is superset"); @@ -140,13 +140,13 @@ test('enum set.union', function(){ * ({} U Y) = {} ∀ Y * {type: []} = {} */ - res = set.union({type: [] } , { type: ['new','prep'] }, comparator); + res = set.union({type: [] } , { type: ['new','prep'] }, prop); deepEqual(res, { }, "intersection"); /* * (Y U {}) = {} ∀ Y */ - res = set.union({ type: 'new' },{}, comparator); + res = set.union({ type: 'new' },{}, prop); deepEqual(res, {}, "all"); /* @@ -155,13 +155,13 @@ test('enum set.union', function(){ * * X U Y = {} */ - res = set.union({type: ['deliver','delivered'] } , { type: ['new','prep'] }, comparator); + res = set.union({type: ['deliver','delivered'] } , { type: ['new','prep'] }, prop); deepEqual(res, {}, "intersection"); }); test('enum set.equal', function(){ - var comparator = comparators["enum"]('type',['new','prep','deliver','delivered']); + var prop = props["enum"]('type',['new','prep','deliver','delivered']); /* * x ∈ {} | x.type ∈ ['new', 'prep', 'deliver', 'delivered'] */ @@ -172,7 +172,7 @@ test('enum set.equal', function(){ * * {} != Y */ - var res = set.equal({} , { type: 'new' }, comparator); + var res = set.equal({} , { type: 'new' }, prop); deepEqual(res, false, "proper subset is not the universal set"); /* @@ -181,7 +181,7 @@ test('enum set.equal', function(){ * * {} = Y */ - res = set.equal({} , { type: ['new','prep','deliver','delivered'] }, comparator); + res = set.equal({} , { type: ['new','prep','deliver','delivered'] }, prop); deepEqual(res, true, "subset of all possible enums is the same as universal set"); /* @@ -190,7 +190,7 @@ test('enum set.equal', function(){ * * X = Y */ - res = set.equal({type: ['prep'] } , { type: ['prep'] }, comparator); + res = set.equal({type: ['prep'] } , { type: ['prep'] }, prop); deepEqual(res, true, "identical sets with single array enum are equal"); /* @@ -199,7 +199,7 @@ test('enum set.equal', function(){ * * X = Y */ - res = set.equal({type: 'prep'} , { type: 'prep' }, comparator); + res = set.equal({type: 'prep'} , { type: 'prep' }, prop); deepEqual(res, true, "identical sets with single property enum are equal"); /* @@ -208,13 +208,13 @@ test('enum set.equal', function(){ * * Y != X */ - res = set.equal({ type: 'new' },{type: 'prep'}, comparator); + res = set.equal({ type: 'new' },{type: 'prep'}, prop); deepEqual(res, false, "two sets with different enum properties are not equal"); }); test('enum set.subset', function(){ - var comparator = comparators["enum"]('type',['new','prep','deliver','delivered']); + var prop = props["enum"]('type',['new','prep','deliver','delivered']); /* * x ∈ X | x.type ∈ ['new', 'prep', 'deliver', 'delivered'] * {} = X @@ -225,35 +225,35 @@ test('enum set.subset', function(){ * Y ⊂ {} * {} ⊄ Y */ - var res = set.subset({} , { type: 'new' }, comparator); + var res = set.subset({} , { type: 'new' }, prop); deepEqual(res, false, "universal set is not a subset"); /* * y ∈ Y | y.type = 'new' * Y ⊆ X ∀ Y */ - res = set.subset({ type: 'new' }, {} , comparator); + res = set.subset({ type: 'new' }, {} , prop); deepEqual(res, true, "any single enum is a subset of universal set"); /* * Y = {} * Y ⊆ X ∀ Y */ - res = set.subset({} , { type: ['new','prep','deliver','delivered'] }, comparator); + res = set.subset({} , { type: ['new','prep','deliver','delivered'] }, prop); deepEqual(res, true, "enum set matching definition of universal set is a subset of universal set"); /* * y ∈ Y | x.type ∈ ['prep'] * Y ⊆ X ∀ Y */ - res = set.subset({type: ['prep'] } , { type: ['prep'] }, comparator); + res = set.subset({type: ['prep'] } , { type: ['prep'] }, prop); deepEqual(res, true, "any list of possible enums are subset of universal set"); /* * y ∈ Y | x.type = 'prep' * Y ⊆ X ∀ Y */ - res = set.subset({type: 'prep'} , { type: 'prep' }, comparator); + res = set.subset({type: 'prep'} , { type: 'prep' }, prop); deepEqual(res, true, "intersection"); /* @@ -262,13 +262,13 @@ test('enum set.subset', function(){ * * X ⊄ Y */ - res = set.subset({ type: 'new' },{type: 'prep'}, comparator); + res = set.subset({ type: 'new' },{type: 'prep'}, prop); deepEqual(res, false, "all"); /* * x ∈ X | x.type ∈ ['new', 'prep', 'deliver', 'delivered'] * Y ⊆ X ∀ Y */ - res = set.subset({type: 'prep'} , { type: ['new','prep','deliver','delivered'] }, comparator); + res = set.subset({type: 'prep'} , { type: ['new','prep','deliver','delivered'] }, prop); deepEqual(res, true, "intersection"); }); diff --git a/src/comparator_tests/rangeInclusive_test.js b/src/prop_tests/rangeInclusive_test.js similarity index 83% rename from src/comparator_tests/rangeInclusive_test.js rename to src/prop_tests/rangeInclusive_test.js index be0d8bf..37b3027 100644 --- a/src/comparator_tests/rangeInclusive_test.js +++ b/src/prop_tests/rangeInclusive_test.js @@ -1,9 +1,9 @@ var QUnit = require("steal-qunit"); var set = require('src/set-core'), - comparators = require("src/comparators"); + props = require("src/props"); -QUnit.module("comparators.rangeInclusive"); +QUnit.module("props.rangeInclusive"); test('rangeInclusive set.equal', function(){ @@ -15,7 +15,7 @@ test('rangeInclusive set.equal', function(){ set.equal( {start: 0, end: 100}, {start: 0, end: 100}, - comparators.rangeInclusive("start", "end")), + props.rangeInclusive("start", "end")), "they are equal" ); /* @@ -26,7 +26,7 @@ test('rangeInclusive set.equal', function(){ !set.equal( {start: 0, end: 100}, {start: 0, end: 101}, - comparators.rangeInclusive("start", "end")), + props.rangeInclusive("start", "end")), "they are not equal" ); /* @@ -37,7 +37,7 @@ test('rangeInclusive set.equal', function(){ !set.equal( {start: 0, end: 100}, {start: 1, end: 100}, - comparators.rangeInclusive("start", "end")), + props.rangeInclusive("start", "end")), "they are not equal" ); }); @@ -50,7 +50,7 @@ test('rangeInclusive set.subset', function(){ set.subset( {start: 0, end: 100}, {start: 0, end: 100}, - comparators.rangeInclusive("start", "end")), + props.rangeInclusive("start", "end")), "self is a subset" ); /* @@ -61,7 +61,7 @@ test('rangeInclusive set.subset', function(){ set.subset( {start: 0, end: 100}, {start: 0, end: 101}, - comparators.rangeInclusive("start", "end")), + props.rangeInclusive("start", "end")), "end extends past subset" ); /* @@ -72,7 +72,7 @@ test('rangeInclusive set.subset', function(){ !set.subset( {start: 0, end: 101}, {start: 0, end: 100}, - comparators.rangeInclusive("start", "end")), + props.rangeInclusive("start", "end")), "non-subset extends past end" ); /* @@ -83,7 +83,7 @@ test('rangeInclusive set.subset', function(){ set.subset( {start: 1, end: 100}, {start: 0, end: 100}, - comparators.rangeInclusive("start", "end")), + props.rangeInclusive("start", "end")), "start extends before subset" ); /* @@ -94,13 +94,13 @@ test('rangeInclusive set.subset', function(){ !set.subset( {start: 0, end: 100}, {start: 1, end: 100}, - comparators.rangeInclusive("start", "end")), + props.rangeInclusive("start", "end")), "non-subset extends before start" ); }); test('rangeInclusive set.difference', function() { - var comparator = comparators.rangeInclusive('start', 'end'); + var prop = props.rangeInclusive('start', 'end'); /* * X = [A0, ..., A99] @@ -108,7 +108,7 @@ test('rangeInclusive set.difference', function() { * * X / Y = [A0, ..., A49] */ - var res = set.difference({ start: 0, end: 99 }, { start: 50, end: 101 }, comparator); + var res = set.difference({ start: 0, end: 99 }, { start: 50, end: 101 }, prop); deepEqual(res, { start: 0, end: 49 }, "got a diff"); /* @@ -125,7 +125,7 @@ test('rangeInclusive set.difference', function() { * more broadly * X / Y = the set of all things not in Y */ - res = set.difference({}, { start: 0, end: 10 }, comparator); + res = set.difference({}, { start: 0, end: 10 }, prop); equal(res, true, 'universal set'); /* @@ -134,7 +134,7 @@ test('rangeInclusive set.difference', function() { * * X / Y = X */ - res = set.difference({ start: 0, end: 49 }, { start: 50, end: 101 }, comparator); + res = set.difference({ start: 0, end: 49 }, { start: 50, end: 101 }, prop); deepEqual(res, { start: 0, end: 49 }, "side by side"); /* @@ -143,7 +143,7 @@ test('rangeInclusive set.difference', function() { * * X / Y = [A21, ..., A49] */ - res = set.difference({ start: 0, end: 49 }, { start: 0, end: 20 }, comparator); + res = set.difference({ start: 0, end: 49 }, { start: 0, end: 20 }, prop); deepEqual(res, { start: 21, end: 49 }, "first set extends past second"); /* @@ -152,12 +152,12 @@ test('rangeInclusive set.difference', function() { * * X / Y = [A0, ..., A19] */ - res = set.difference({ start: 0, end: 49 }, { start: 20, end: 49 }, comparator); + res = set.difference({ start: 0, end: 49 }, { start: 20, end: 49 }, prop); deepEqual(res, { start: 0, end: 19 }, "first set starts before second"); }); test('rangeInclusive set.union', function() { - var comparator = comparators.rangeInclusive('start', 'end'); + var prop = props.rangeInclusive('start', 'end'); /* @@ -166,7 +166,7 @@ test('rangeInclusive set.union', function() { * * X U Y = [A0, ..., A101] */ - var res = set.union({ start: 0, end: 99 }, { start: 50, end: 101 }, comparator); + var res = set.union({ start: 0, end: 99 }, { start: 50, end: 101 }, prop); deepEqual(res, { start: 0, end: 101 }, "got a union"); /* @@ -175,7 +175,7 @@ test('rangeInclusive set.union', function() { * * X U Y = X */ - res = set.union({}, { start: 0, end: 10 }, comparator); + res = set.union({}, { start: 0, end: 10 }, prop); deepEqual(res, {}, "universal set"); /* @@ -184,7 +184,7 @@ test('rangeInclusive set.union', function() { * * X U Y = [A100, ..., A299] */ - res = set.union({start: 100, end: 199}, {start: 200, end: 299}, comparator); + res = set.union({start: 100, end: 199}, {start: 200, end: 299}, prop); deepEqual(res, {start:100, end:299}, "no intersection"); /* @@ -193,7 +193,7 @@ test('rangeInclusive set.union', function() { * * X U Y = [A100, ..., A299] */ - res = set.union({start: 200, end: 299}, {start: 100, end: 199}, comparator); + res = set.union({start: 200, end: 299}, {start: 100, end: 199}, prop); deepEqual(res, {start:100, end:299}, "no intersection with either argument order"); /* @@ -202,7 +202,7 @@ test('rangeInclusive set.union', function() { * * X U Y = [A100, ..., A299] */ - res = set.union({start: 200, end: 299}, {start: 100, end: 209}, comparator); + res = set.union({start: 200, end: 299}, {start: 100, end: 209}, prop); deepEqual(res, {start:100, end:299}, "sets can intersect"); /* @@ -211,7 +211,7 @@ test('rangeInclusive set.union', function() { * * X U Y = [A100, ..., A299] */ - res = set.union({start: 100, end: 209}, {start: 200, end: 299}, comparator); + res = set.union({start: 100, end: 209}, {start: 200, end: 299}, prop); deepEqual(res, {start:100, end:299}, "sets can intersect with either argument order"); /* @@ -220,7 +220,7 @@ test('rangeInclusive set.union', function() { * * X U Y = [A100, ..., A299] */ - res = set.union({start: 100, end: 299}, {start: 103, end: 209}, comparator); + res = set.union({start: 100, end: 299}, {start: 103, end: 209}, prop); deepEqual(res, {start:100, end:299}, "first set contains second"); /* @@ -229,7 +229,7 @@ test('rangeInclusive set.union', function() { * * X U Y = [A100, ..., A299] */ - res = set.union({start: 100, end: 299}, {start: 103, end: 209}, comparator); + res = set.union({start: 100, end: 299}, {start: 103, end: 209}, prop); deepEqual(res, {start:100, end:299}, "second set contains first"); /* @@ -238,25 +238,25 @@ test('rangeInclusive set.union', function() { * * X U Y = [A100, ..., A299] */ - res = set.union({start: 100, end: 299}, {start: 100, end: 299}, comparator); + res = set.union({start: 100, end: 299}, {start: 100, end: 299}, prop); deepEqual(res, {start:100, end:299}, "union of identical sets is the same as those sets"); }); test('rangeInclusive set.count', function(){ - var comparator = comparators.rangeInclusive('start', 'end'); + var prop = props.rangeInclusive('start', 'end'); /* * X = [A0, ..., A99] * |X| = 100 */ - var res = set.count({ start: 0, end: 99 }, comparator); + var res = set.count({ start: 0, end: 99 }, prop); equal(res, 100, "count is right"); }); test('rangeInclusive set.intersection', function(){ - var comparator = comparators.rangeInclusive('start', 'end'); + var prop = props.rangeInclusive('start', 'end'); /* * X = [A0, A99] @@ -264,13 +264,13 @@ test('rangeInclusive set.intersection', function(){ * * X ∩ Y = [A50, A99] */ - var res = set.intersection({ start: 0, end: 99 }, { start: 50, end: 101 }, comparator); + var res = set.intersection({ start: 0, end: 99 }, { start: 50, end: 101 }, prop); deepEqual(res, { start: 50, end: 99 }, "got a intersection"); }); test('rangeInclusive with string numbers (#17)', function(){ var algebra = new set.Algebra( - comparators.rangeInclusive('start','end') + props.rangeInclusive('start','end') ); ok( algebra.subset( diff --git a/src/comparator_tests/sort_test.js b/src/prop_tests/sort_test.js similarity index 83% rename from src/comparator_tests/sort_test.js rename to src/prop_tests/sort_test.js index 998d479..3613508 100644 --- a/src/comparator_tests/sort_test.js +++ b/src/prop_tests/sort_test.js @@ -1,31 +1,31 @@ var QUnit = require("steal-qunit"); var set = require('src/set-core'), - comparators = require("src/comparators"); + props = require("src/props"); var each = require("can-util/js/each/each"); -QUnit.module("comparators.sort"); +QUnit.module("props.sort"); test('set.difference', function(){ - var comparator = comparators.sort('sort'); + var prop = props.sort('sort'); - var res = set.difference({sort: "foo"}, { completed: true }, comparator); + var res = set.difference({sort: "foo"}, { completed: true }, prop); ok(res === true, "diff should be true"); - res = set.difference({ completed: true }, { completed: true, sort: "foo" }, comparator); + res = set.difference({ completed: true }, { completed: true, sort: "foo" }, prop); equal(res, false, "the same except for sort"); - res = set.difference({ completed: true }, { sort: "foo"}, comparator); + res = set.difference({ completed: true }, { sort: "foo"}, prop); equal(res, false); - res = set.difference({ completed: true }, { foo: 'bar', sort: "foo" }, comparator); + res = set.difference({ completed: true }, { foo: 'bar', sort: "foo" }, prop); equal(res, false); }); test('set.difference({ function })', function() { var algebra = new set.Algebra( - comparators.sort('sort'), + props.sort('sort'), { colors: function() { return { @@ -44,34 +44,34 @@ test('set.difference({ function })', function() { }); test('set.union', function(){ - var comparator = comparators.sort('sort'); + var prop = props.sort('sort'); // set / subset - var res = set.union({sort: "name"}, { completed: true }, comparator); + var res = set.union({sort: "name"}, { completed: true }, prop); deepEqual(res , {}, "set / subset sort left"); - res = set.union({}, { completed: true, sort: "name" }, comparator); + res = set.union({}, { completed: true, sort: "name" }, prop); deepEqual(res , {}, "set / subset sort right"); - res = set.union({ sort: "name" }, { completed: true, sort: "namer" }, comparator); + res = set.union({ sort: "name" }, { completed: true, sort: "namer" }, prop); deepEqual(res , {}, "set / subset both sorts"); - res = set.union({ completed: true }, {sort: "foo"}, comparator); + res = set.union({ completed: true }, {sort: "foo"}, prop); deepEqual(res , {}, "subset / set"); - res = set.union({foo: "bar", sort: "foo"},{foo: "bar"}, comparator); + res = set.union({foo: "bar", sort: "foo"},{foo: "bar"}, prop); deepEqual(res, {foo: "bar"}, "equal"); - res = set.union({foo: "bar"},{foo: "zed", sort: "foo"}, comparator); + res = set.union({foo: "bar"},{foo: "zed", sort: "foo"}, prop); ok(!res, "values not equal"); - res = set.union({foo: "bar", sort: "foo"},{name: "A"}, comparator); + res = set.union({foo: "bar", sort: "foo"},{name: "A"}, prop); ok(!res, "values not equal"); }); test('set.union Array', function(){ - var comparator = comparators.sort('sort'); + var prop = props.sort('sort'); var res = set.union({foo: ["a","b"], sort: "foo"}, { foo: ["a","c"] }, - comparator); + prop); deepEqual(res , {foo: ["a","b","c"]}, "set / subset"); }); @@ -91,25 +91,25 @@ test('set.count', function(){ test('set.intersection', function(){ - var comparator = comparators.sort('sort'); + var prop = props.sort('sort'); - var res = set.intersection({} , { sort: 'name' }, comparator); + var res = set.intersection({} , { sort: 'name' }, prop); deepEqual(res, {}, "no sort if only one is sorted"); - res = set.intersection({ sort: 'name' } , { sort: 'name' }, comparator); + res = set.intersection({ sort: 'name' } , { sort: 'name' }, prop); deepEqual(res, {sort: 'name'}, ""); - res = set.intersection({type: 'new'} , { sort: 'name', userId: 5 }, comparator); + res = set.intersection({type: 'new'} , { sort: 'name', userId: 5 }, prop); deepEqual(res, {type: 'new', userId: 5 }, ""); - res = set.intersection({type: 'new', sort: "age"} , { sort: 'name', userId: 5 }, comparator); + res = set.intersection({type: 'new', sort: "age"} , { sort: 'name', userId: 5 }, prop); deepEqual(res, {type: 'new', userId: 5 }, ""); }); test('set.intersection Array', function(){ - var comparator = comparators.sort('sort'); + var prop = props.sort('sort'); var res = set.intersection({foo: ["a","b"], sort: 'foo'}, - { foo: ["a","c"] }, comparator); + { foo: ["a","c"] }, prop); deepEqual(res , {foo: ["a"]}, "intersection"); }); @@ -117,7 +117,7 @@ test('set.intersection Array', function(){ test('set.subset', function(){ var ignoreProp = function(){ return true; }; - var algebra = new set.Algebra(comparators.sort('sort'),{ + var algebra = new set.Algebra(props.sort('sort'),{ foo: ignoreProp, bar: ignoreProp, kind: ignoreProp, @@ -159,7 +159,7 @@ test('set.subset', function(){ }); test('set.subset with range', function(){ - var algebra = new set.Algebra(comparators.sort('sort'),comparators.rangeInclusive('start','end')); + var algebra = new set.Algebra(props.sort('sort'),props.rangeInclusive('start','end')); // add sort .. same .. different // add range .. same ... more ... less @@ -245,7 +245,7 @@ test('set.subset with range', function(){ }); test("set.index", function(){ - var algebra = new set.Algebra(comparators.sort('sort')); + var algebra = new set.Algebra(props.sort('sort')); var index = algebra.index( {sort: "name"}, @@ -256,7 +256,7 @@ test("set.index", function(){ test("set.getSubset (#14)", function(){ - var algebra = new set.Algebra(comparators.sort('sort')); + var algebra = new set.Algebra(props.sort('sort')); var subset = algebra.getSubset({sort: "name"},{},[{id: 1, name:"s"}, {id: 2, name:"j"}, {id: 3, name:"m"}, {id: 4, name:"g"}]); deepEqual(subset, [ {id: 4, name:"g"},{id: 2, name:"j"}, {id: 3, name:"m"},{id: 1, name:"s"}]); }); @@ -264,8 +264,8 @@ test("set.getSubset (#14)", function(){ test("set.getUnion", function(){ var algebra = new set.Algebra( - comparators.sort('sort'), - comparators.boolean('complete') + props.sort('sort'), + props.boolean('complete') ); // a,b,aItems, bItems @@ -284,8 +284,8 @@ test("set.getUnion", function(){ test("set.union keeps sort", function(){ var algebra = new set.Algebra( - comparators.sort('sort'), - comparators.boolean('complete') + props.sort('sort'), + props.boolean('complete') ); var union = algebra.union( @@ -297,8 +297,8 @@ test("set.union keeps sort", function(){ test("paginated and sorted is subset (#17)", function(){ var algebra = new set.Algebra( - comparators.sort('sort'), - comparators.rangeInclusive('start','end') + props.sort('sort'), + props.rangeInclusive('start','end') ); var res = algebra.subset({start: 0, end: 100, sort: "name"},{start: 0, end: 100, sort: "name"}); diff --git a/src/comparators.js b/src/props.js similarity index 98% rename from src/comparators.js rename to src/props.js index 9a08932..4b27f19 100644 --- a/src/comparators.js +++ b/src/props.js @@ -140,7 +140,7 @@ module.exports = { * * @signature `set.props.enum(property, propertyValues)` * - * Makes a comparator for a set of values. + * Makes a prop for a set of values. * * ``` * var compare = set.props.enum("type", ["new","accepted","pending","resolved"]) @@ -181,7 +181,7 @@ module.exports = { * * @signature `set.props.rangeInclusive(startIndexProperty, endIndexProperty)` * - * Makes a comparator for two ranged properties that specify a range of items + * Makes a prop for two ranged properties that specify a range of items * that includes both the startIndex and endIndex. For example, a range of * [0,20] loads 21 items. * @@ -191,7 +191,7 @@ module.exports = { * * @param {String} startIndexProperty The starting property name * @param {String} endIndexProperty The ending property name - * @return {can-set.compares} Returns a comparator + * @return {can-set.compares} Returns a prop */ rangeInclusive: function(startIndexProperty, endIndexProperty){ var compares = {}; @@ -356,7 +356,7 @@ module.exports = { * @parent can-set.props * * @description Defines the identify property. - * + * * @signature `set.props.id(prop)` * * Defines the property name on items that uniquely diff --git a/src/props_test.js b/src/props_test.js new file mode 100644 index 0000000..89dd2ab --- /dev/null +++ b/src/props_test.js @@ -0,0 +1,8 @@ +var QUnit = require("steal-qunit"); + +QUnit.module("props"); + +require('./prop_tests/sort_test'); +require('./prop_tests/rangeInclusive_test'); +require('./prop_tests/boolean_test'); +require('./prop_tests/enum_test'); diff --git a/src/set-core.js b/src/set-core.js index 31acbd6..1ea640e 100644 --- a/src/set-core.js +++ b/src/set-core.js @@ -292,7 +292,7 @@ assign(Algebra.prototype, { // if both have a paginate, make sure order is the same. if( bClauseProps.enabled.paginate && (aClauseProps.enabled.order || bClauseProps.enabled.order)) { - // compare order clauses without any special comparators + // compare order clauses without any special props compatibleSort = compare.equal(aClauseProps.order, bClauseProps.order, undefined, undefined, undefined, {}, {}); } @@ -504,7 +504,7 @@ assign(Algebra.prototype, { // if there is a paginate and an order, order has to be the same first. if((propsClauseProps.enabled.paginate || aClauseProps.enabled.paginate) && (propsClauseProps.enabled.order || aClauseProps.enabled.order)) { - // compare order clauses without any special comparators + // compare order clauses without any special props compatibleSort = compare.equal(propsClauseProps.order, aClauseProps.order, undefined, undefined, undefined, {}, {}); } diff --git a/src/set.js b/src/set.js index 27f9105..cf74401 100644 --- a/src/set.js +++ b/src/set.js @@ -1,7 +1,8 @@ var set = require("./set-core"); -var comparators = require("./comparators"); -set.comparators = comparators; +var props = require("./props"); +set.comparators = props; // For backward compatibility +set.props = props; set.helpers = require("./helpers"); diff --git a/src/set_test.js b/src/set_test.js index 6614576..c3b4d92 100644 --- a/src/set_test.js +++ b/src/set_test.js @@ -9,13 +9,10 @@ test('set.Algebra constructors', function(){ var algebra = new set.Algebra( set.props.rangeInclusive("start", "end"), set.props.boolean('completed'), - set.comparators["enum"]('type',['new','prep','deliver','delivered']) + set.props["enum"]('type',['new','prep','deliver','delivered']) ); var res = algebra.subset({ type: ['new'] },{type: ['new','prep']}); deepEqual(res, true, "enum"); }); - - - diff --git a/src/test.js b/src/test.js index c031f21..332085f 100644 --- a/src/test.js +++ b/src/test.js @@ -1,5 +1,5 @@ require('./set-core_test'); require('./set-core-nested_test'); -require('./comparators_test'); +require('./props_test'); require('./get_test'); require('./set_test');