core.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Utilities: A classic collection of JavaScript utilities
  3. * Copyright 2112 Matthew Eernisse ([email protected])
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. var assert = require('assert')
  19. , core = require('../lib/core')
  20. , tests;
  21. tests = {
  22. 'simple mixin for core': function () {
  23. var expected = {secret: 'asdf', geddy: 'geddyKey'}
  24. , result = core.mixin({secret: 'asdf'}, {geddy: 'geddyKey'});
  25. assert.deepEqual(expected, result);
  26. }
  27. , 'mixin with overiding key for core': function () {
  28. var expected = {secret: 'geddySecret', geddy: 'geddyKey'}
  29. , result = core.mixin({secret: 'asdf'}, {geddy: 'geddyKey', secret: 'geddySecret'});
  30. assert.deepEqual(expected, result);
  31. }
  32. , 'simple enhance for core': function () {
  33. var expected = {secret: 'asdf', geddy: 'geddyKey'}
  34. , result = core.enhance({secret: 'asdf'}, {geddy: 'geddyKey'});
  35. assert.deepEqual(expected, result);
  36. }
  37. , 'enhance with overiding key for core': function () {
  38. var expected = {secret: 'geddySecret', geddy: 'geddyKey'}
  39. , result = core.enhance({secret: 'asdf'}, {geddy: 'geddyKey', secret: 'geddySecret'});
  40. assert.deepEqual(expected, result);
  41. }
  42. , 'isEmpty, empty string (true)': function () {
  43. assert.ok(core.isEmpty(''));
  44. }
  45. , 'isEmpty, null (true)': function () {
  46. assert.ok(core.isEmpty(null));
  47. }
  48. , 'isEmpty, undefined (true)': function () {
  49. assert.ok(core.isEmpty(null));
  50. }
  51. , 'isEmpty, NaN (true)': function () {
  52. assert.ok(core.isEmpty(NaN));
  53. }
  54. , 'isEmpty, invalid Date (true)': function () {
  55. assert.ok(core.isEmpty(new Date(NaN)));
  56. }
  57. , 'isEmpty, zero (false)': function () {
  58. assert.ok(!core.isEmpty(0));
  59. }
  60. ,
  61. 'bind': function () {
  62. function bar() {}
  63. function foo() {
  64. assert.equal(this.name, 'bar');
  65. }
  66. var fooBoundToBar = core.bind(bar, foo);
  67. fooBoundToBar();
  68. }
  69. ,
  70. 'bind, arguments': function () {
  71. function bar() {}
  72. function foo(arg) {
  73. assert.equal(this.name, 'bar');
  74. assert.equal(arg, 'cats');
  75. }
  76. var fooBoundToBarWithCats = core.bind(bar, foo, 'cats');
  77. fooBoundToBarWithCats();
  78. }
  79. };
  80. module.exports = tests;