Skip to content

Commit 9da8fba

Browse files
committed
Fix the bug where copy constructor fails to copy the option of the source
Closes #9
1 parent bb03d66 commit 9da8fba

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

multi-integer-range.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ export class MultiRange {
3737
this.appendRange(data, data);
3838
} else if (data instanceof MultiRange) {
3939
this.ranges = data.getRanges();
40-
this.options = {
41-
parseNegative: this.options.parseNegative,
42-
parseUnbounded: this.options.parseUnbounded
43-
};
40+
if (arguments[1] === undefined) {
41+
this.options = {
42+
parseNegative: data.options.parseNegative,
43+
parseUnbounded: data.options.parseUnbounded
44+
};
45+
}
4446
} else if (isArray(data)) {
4547
for (let item of <(number|Range)[]>data) {
4648
if (isArray(item)) {

test/multi-integer-range.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ describe('MultiRange', function() {
7575
t(mr(mr('5-10')), '5-10'); // aka clone
7676
});
7777

78+
it('must copy the options when using copy constructor', function() {
79+
var original = mrd('5-10', { parseNegative: true });
80+
81+
var b = mrd(original);
82+
assert.isTrue(b.options.parseNegative);
83+
assert.isFalse(b.options.parseUnbounded);
84+
85+
// If another options is explicitly provided, respect it
86+
var c = mrd(original, { parseNegative: false, parseUnbounded: true });
87+
assert.isFalse(c.options.parseNegative);
88+
assert.isTrue(c.options.parseUnbounded);
89+
});
90+
7891
it('must throw an error for invalid input', function() {
7992
assert.throws(function() { mr('abc'); }, SyntaxError);
8093
assert.throws(function() { mr('1.5'); }, SyntaxError);

0 commit comments

Comments
 (0)