Skip to content

Commit

Permalink
Fix the bug where copy constructor fails to copy the option of the so…
Browse files Browse the repository at this point in the history
…urce

Closes #9
  • Loading branch information
smikitky committed Sep 13, 2017
1 parent bb03d66 commit 9da8fba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 6 additions & 4 deletions multi-integer-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ export class MultiRange {
this.appendRange(data, data);
} else if (data instanceof MultiRange) {
this.ranges = data.getRanges();
this.options = {
parseNegative: this.options.parseNegative,
parseUnbounded: this.options.parseUnbounded
};
if (arguments[1] === undefined) {
this.options = {
parseNegative: data.options.parseNegative,
parseUnbounded: data.options.parseUnbounded
};
}
} else if (isArray(data)) {
for (let item of <(number|Range)[]>data) {
if (isArray(item)) {
Expand Down
13 changes: 13 additions & 0 deletions test/multi-integer-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ describe('MultiRange', function() {
t(mr(mr('5-10')), '5-10'); // aka clone
});

it('must copy the options when using copy constructor', function() {
var original = mrd('5-10', { parseNegative: true });

var b = mrd(original);
assert.isTrue(b.options.parseNegative);
assert.isFalse(b.options.parseUnbounded);

// If another options is explicitly provided, respect it
var c = mrd(original, { parseNegative: false, parseUnbounded: true });
assert.isFalse(c.options.parseNegative);
assert.isTrue(c.options.parseUnbounded);
});

it('must throw an error for invalid input', function() {
assert.throws(function() { mr('abc'); }, SyntaxError);
assert.throws(function() { mr('1.5'); }, SyntaxError);
Expand Down

0 comments on commit 9da8fba

Please sign in to comment.