Permalink
Browse files

Added test files

  • Loading branch information...
1 parent 4ab6d80 commit 0b7e376eb8c171c3fdb6c601a1b63522d01d8bd0 mde committed Aug 4, 2012
Showing with 222 additions and 0 deletions.
  1. +67 −0 test/array.js
  2. +69 −0 test/date.js
  3. +86 −0 test/object.js
View
@@ -0,0 +1,67 @@
+/*
+ * Utilities: A classic collection of JavaScript utilities
+ * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+
+var assert = require('assert')
+ , array = require('../lib/array')
+ , tests;
+
+tests = {
+
+ 'test basic humanize for array': function () {
+ var data = array.humanize(["array", "array", "array"])
+ , actual = "array, array and array";
+ assert.equal(data, actual);
+ }
+
+, 'test humanize with two items for array': function() {
+ var data = array.humanize(["array", "array"])
+ , actual = "array and array";
+ assert.equal(data, actual);
+ }
+
+, 'test humanize with two items for array': function() {
+ var data = array.humanize(["array"])
+ , actual = "array";
+ assert.equal(data, actual);
+ }
+
+, 'test basic included for array': function() {
+ var test = ["array"]
+ , data = array.included("array", test)
+ , actual = test;
+ assert.equal(data, actual);
+ }
+
+, 'test false included for array': function() {
+ var data = array.included("nope", ["array"])
+ , actual = false;
+ assert.equal(data, actual);
+ }
+
+, 'test false boolean included for array': function() {
+ var test = ["array", false]
+ , data = array.included(false, test)
+ , actual = test;
+ assert.equal(data, actual);
+ }
+
+};
+
+module.exports = tests;
+
+
View
@@ -0,0 +1,69 @@
+/*
+ * Utilities: A classic collection of JavaScript utilities
+ * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+var date = require('../lib/date')
+ , assert = require('assert')
+ , tests = {}
+ , _date = new Date();
+
+tests = {
+
+ 'test strftime for date': function() {
+ var data = date.strftime(_date, "%w")
+ , actual = _date.getDay();
+ assert.equal(data, actual);
+ }
+
+, 'test leftPad for date': function() {
+ var data = date.leftPad("geddy", 7, " ")
+ , actual = " geddy";
+ assert.equal(data, actual);
+ }
+
+, 'test calcCentury using current year for date': function() {
+ var data = date.calcCentury()
+ , actual = '21';
+ assert.equal(data, actual);
+ }
+
+, 'test calcCentury using 20th century year for date': function() {
+ var data = date.calcCentury(2000)
+ , actual = '20';
+ assert.equal(data, actual);
+ }
+
+, 'test calcCentury using 1st century year for date': function() {
+ var data = date.calcCentury(10)
+ , actual = '1';
+ assert.equal(data, actual);
+ }
+
+, 'test getMeridiem for date': function() {
+ var data = date.getMeridiem(_date.getHours())
+ , actual = (_date.getHours() > 11) ? 'PM' : 'AM';
+ assert.equal(data, actual);
+ }
+
+, 'test leftPad for date': function() {
+ var data = date.leftPad("geddy", 7, " ")
+ , actual = " geddy";
+ assert.equal(data, actual);
+ }
+
+};
+
+module.exports = tests;
View
@@ -0,0 +1,86 @@
+/*
+ * Utilities: A classic collection of JavaScript utilities
+ * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+*/
+var object = require('../lib/object')
+ , array = require('../lib/array')
+ , assert = require('assert')
+ , tests = {}
+ , checkObjects;
+
+// Check if two objects are similar
+checkObjects = function(first, second) {
+ var finished = [];
+
+ for(var i in first) {
+ if((typeof first[i] === 'object') && (typeof second[i] === 'object')) {
+ finished.push(checkObjects(first[i], second[i]));
+ } else {
+ if(first[i] === second[i]) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ if(array.included(false, finished)) {
+ return false;
+ }
+ return true;
+};
+
+tests = {
+
+ 'test merge in object': function() {
+ var data = object.merge({user: 'geddy'}, {key: 'key'})
+ , actual = {user: 'geddy', key: 'key'};
+ assert.equal(checkObjects(data, actual), true);
+ }
+
+, 'test merge with overwriting keys in object': function() {
+ var data = object.merge({user: 'geddy', key: 'geddyKey'}, {key: 'key'})
+ , actual = {user: 'geddy', key: 'key'};
+ assert.equal(checkObjects(data, actual), true);
+ }
+
+, 'test reverseMerge in object': function() {
+ var data = object.reverseMerge({user: 'geddy'}, {key: 'key'})
+ , actual = {user: 'geddy', key: 'key'};
+ assert.equal(checkObjects(data, actual), true);
+ }
+
+, 'test reverseMerge with keys overwriting default in object': function() {
+ var data = object.reverseMerge({user: 'geddy', key: 'geddyKey'}, {key: 'key'})
+ , actual = {user: 'geddy', key: 'geddyKey'};
+ assert.equal(checkObjects(data, actual), true);
+ }
+
+, 'test isEmpty with non empty object in object': function() {
+ var data = object.isEmpty({user: 'geddy'})
+ , actual = false;
+ assert.equal(data, actual);
+ }
+
+, 'test isEmpty with empty object in object': function() {
+ var data = object.isEmpty({})
+ , actual = true;
+ assert.equal(data, actual);
+ }
+
+};
+
+module.exports = tests;

0 comments on commit 0b7e376

Please sign in to comment.