123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 'use strict';
- var assert = require('assert');
- var parseInterval = require('./').default;
- describe('Parser', function () {
- describe('should return null if', function () {
- it('input is invalid', function () {
- assert.equal(null, parseInterval('INVALID INPUT'));
- assert.equal(null, parseInterval('1,2'));
- assert.equal(null, parseInterval('[]'));
- assert.equal(null, parseInterval(']['));
- });
- it('left value more than right value', function () {
- assert.equal(null, parseInterval('[2,-2]'));
- assert.equal(null, parseInterval('[Infinity,-2]'));
- assert.equal(null, parseInterval('[1,-Infinity]'));
- });
- it('value equals, but not included to interval', function () {
- assert.equal(null, parseInterval('[2,2)'));
- assert.equal(null, parseInterval('(2,2]'));
- assert.equal(null, parseInterval('[2,2['));
- assert.equal(null, parseInterval(']2,2]'));
- assert.equal(null, parseInterval('(2,2)'));
- assert.equal(null, parseInterval(']2,2['));
- assert.equal(null, parseInterval('(2)'));
- assert.equal(null, parseInterval(']2['));
- assert.equal(null, parseInterval('(Infinity,Infinity]'));
- });
- });
- describe('should right work', function () {
- it('in full form', function () {
- assert.deepEqual({
- from: {
- value: -10,
- included: true
- },
- to: {
- value: 10,
- included: false
- }
- }, parseInterval('[-10,10)'));
- });
- it('in not full form', function () {
- assert.deepEqual({
- from: {
- value: 10,
- included: true
- },
- to: {
- value: 10,
- included: true
- }
- }, parseInterval('[10]'));
- assert.deepEqual({
- from: {
- value: 10,
- included: true
- },
- to: {
- value: Infinity,
- included: true
- }
- }, parseInterval('[10,]'));
- assert.deepEqual({
- from: {
- value: -Infinity,
- included: true
- },
- to: {
- value: 10,
- included: true
- }
- }, parseInterval('[,10]'));
- assert.deepEqual({
- from: {
- value: -Infinity,
- included: true
- },
- to: {
- value: Infinity,
- included: true
- }
- }, parseInterval('[,]'));
- });
- });
- });
|