VariablesParseState_test.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use strict";
  2. if (!module.parent) return require.cache[__filename] = 0, (new(require("mocha"))()).addFile(__filename).ui("exports").run(process.exit);
  3. var assert = require("assert"),
  4. Variables = require("../../../../lib/pipeline/expressions/Variables"),
  5. VariablesIdGenerator = require("../../../../lib/pipeline/expressions/VariablesIdGenerator"),
  6. VariablesParseState = require("../../../../lib/pipeline/expressions/VariablesParseState");
  7. module.exports = {
  8. "VariablesParseState": {
  9. "constructor": {
  10. "Should be able to construct": function canConstruct() {
  11. var idGen = new VariablesIdGenerator();
  12. new VariablesParseState(idGen);
  13. },
  14. "Should throw given invalid args": function throwsForArgs() {
  15. assert.throws(function() {
  16. new VariablesParseState();
  17. });
  18. assert.throws(function() {
  19. new VariablesParseState(1);
  20. });
  21. assert.throws(function() {
  22. new VariablesParseState("hi");
  23. });
  24. assert.throws(function() {
  25. new VariablesParseState({});
  26. });
  27. assert.throws(function() {
  28. new VariablesParseState([]);
  29. });
  30. assert.throws(function() {
  31. new VariablesParseState(new Date());
  32. });
  33. }
  34. },
  35. "#defineVariable": {
  36. "Cannot define ROOT variable": function noCanRootDef() {
  37. var idGen = new VariablesIdGenerator(),
  38. vps = new VariablesParseState(idGen);
  39. assert.throws(function() {
  40. vps.defineVariable("ROOT", 5);
  41. });
  42. },
  43. "Should return new ids": function returnsNewIds() {
  44. var idGen = new VariablesIdGenerator(),
  45. vps = new VariablesParseState(idGen),
  46. firstId = vps.defineVariable("hi", "bye"),
  47. secondId = vps.defineVariable("bye", "hi");
  48. assert.notEqual(firstId, secondId);
  49. }
  50. },
  51. "#getVariable": {
  52. "Can retrieve defined variables": function getVariable() {
  53. var idGen = new VariablesIdGenerator(),
  54. vps = new VariablesParseState(idGen),
  55. firstId = vps.defineVariable("hi", "bye"),
  56. firstVariable = vps.getVariable("hi");
  57. assert.equal(firstVariable, firstId);
  58. },
  59. "Can retrieve root id": function getVariable() {
  60. var idGen = new VariablesIdGenerator(),
  61. vps = new VariablesParseState(idGen),
  62. firstVariable = vps.getVariable("ROOT");
  63. assert.equal(firstVariable, Variables.ROOT_ID);
  64. }
  65. }
  66. }
  67. };