test.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. 'use strict';
  2. var assert = require('assert');
  3. var parseInterval = require('./').default;
  4. describe('Parser', function () {
  5. describe('should return null if', function () {
  6. it('input is invalid', function () {
  7. assert.equal(null, parseInterval('INVALID INPUT'));
  8. assert.equal(null, parseInterval('1,2'));
  9. assert.equal(null, parseInterval('[]'));
  10. assert.equal(null, parseInterval(']['));
  11. });
  12. it('left value more than right value', function () {
  13. assert.equal(null, parseInterval('[2,-2]'));
  14. assert.equal(null, parseInterval('[Infinity,-2]'));
  15. assert.equal(null, parseInterval('[1,-Infinity]'));
  16. });
  17. it('value equals, but not included to interval', function () {
  18. assert.equal(null, parseInterval('[2,2)'));
  19. assert.equal(null, parseInterval('(2,2]'));
  20. assert.equal(null, parseInterval('[2,2['));
  21. assert.equal(null, parseInterval(']2,2]'));
  22. assert.equal(null, parseInterval('(2,2)'));
  23. assert.equal(null, parseInterval(']2,2['));
  24. assert.equal(null, parseInterval('(2)'));
  25. assert.equal(null, parseInterval(']2['));
  26. assert.equal(null, parseInterval('(Infinity,Infinity]'));
  27. });
  28. });
  29. describe('should right work', function () {
  30. it('in full form', function () {
  31. assert.deepEqual({
  32. from: {
  33. value: -10,
  34. included: true
  35. },
  36. to: {
  37. value: 10,
  38. included: false
  39. }
  40. }, parseInterval('[-10,10)'));
  41. });
  42. it('in not full form', function () {
  43. assert.deepEqual({
  44. from: {
  45. value: 10,
  46. included: true
  47. },
  48. to: {
  49. value: 10,
  50. included: true
  51. }
  52. }, parseInterval('[10]'));
  53. assert.deepEqual({
  54. from: {
  55. value: 10,
  56. included: true
  57. },
  58. to: {
  59. value: Infinity,
  60. included: true
  61. }
  62. }, parseInterval('[10,]'));
  63. assert.deepEqual({
  64. from: {
  65. value: -Infinity,
  66. included: true
  67. },
  68. to: {
  69. value: 10,
  70. included: true
  71. }
  72. }, parseInterval('[,10]'));
  73. assert.deepEqual({
  74. from: {
  75. value: -Infinity,
  76. included: true
  77. },
  78. to: {
  79. value: Infinity,
  80. included: true
  81. }
  82. }, parseInterval('[,]'));
  83. });
  84. });
  85. });