array.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. , array = require('../lib/array')
  20. , tests;
  21. tests = {
  22. 'test basic humanize for array': function () {
  23. var actual = array.humanize(["array", "array", "array"])
  24. , expected = "array, array and array";
  25. assert.equal(expected, actual);
  26. }
  27. , 'test humanize with two items for array': function () {
  28. var actual = array.humanize(["array", "array"])
  29. , expected = "array and array";
  30. assert.equal(expected, actual);
  31. }
  32. , 'test humanize with a single item for array': function () {
  33. var actual = array.humanize(["array"])
  34. , expected = "array";
  35. assert.equal(expected, actual);
  36. }
  37. , 'test humanize with no items for array': function () {
  38. var actual = array.humanize([])
  39. , expected = "";
  40. assert.equal(expected, actual);
  41. }
  42. , 'test basic include for array': function () {
  43. var test = ["array"]
  44. , actual = array.include(test, "array");
  45. assert.equal(true, actual);
  46. }
  47. , 'test false include for array': function () {
  48. var test = ["array"]
  49. , actual = array.include(test, 'nope');
  50. assert.equal(false, actual);
  51. }
  52. , 'test false boolean include for array': function () {
  53. var test = ["array", false]
  54. , actual = array.include(test, false);
  55. assert.equal(true, actual);
  56. }
  57. };
  58. module.exports = tests;