Value.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. "use strict";
  2. var assert = require("assert"),
  3. Value = require("../../../lib/pipeline/Value");
  4. module.exports = {
  5. "Value": {
  6. "#ctor": {
  7. "should throw an error when used": function ctorThrows() {
  8. assert.throws(function() {
  9. var val = new Value();
  10. });
  11. }
  12. },
  13. "#consume": {
  14. "should return an equivalent array, empty the original":function works() {
  15. var testArray = [5,6,"hi"],
  16. result = Value.consume(testArray);
  17. assert.deepEqual([5,6,"hi"], result); // tests that insides were copied
  18. assert.notEqual(testArray, result); // tests that a new array was returned
  19. assert.equal(testArray.length, 0); // tests that the old array was emptied
  20. },
  21. "should work given an empty array":function worksWhenEmpty() {
  22. var testArray = [],
  23. result = Value.consume(testArray);
  24. assert.deepEqual([], result);
  25. assert.equal(testArray.length, 0);
  26. }
  27. },
  28. "#compare": {
  29. "follows canonical type order when types differ": function throwsWhenDiffTypes() {
  30. var a = 5,
  31. b = "hi",
  32. actual = Value.compare(a,b);
  33. assert.equal(actual, -1);
  34. },
  35. "should compare two numbers": function comparesNumbers() {
  36. var a = 5,
  37. b = 6,
  38. actual = Value.compare(a,b);
  39. assert.equal(actual, -1);
  40. },
  41. "should compare two strings": function comparesStrings() {
  42. var a = 'a',
  43. b = 'b',
  44. actual = Value.compare(b,a);
  45. assert.equal(actual, 1);
  46. },
  47. "should detect the same object": function compareSameObj() {
  48. var a = {},
  49. b = a,
  50. actual = Value.compare(a,b);
  51. assert.equal(actual, 0);
  52. }
  53. }
  54. }
  55. };
  56. if (!module.parent)(new(require("mocha"))()).ui("exports").reporter("spec").addFile(__filename).grep(process.env.MOCHA_GREP || '').run(process.exit);