diff --git a/src/values/options.js b/src/values/options.js index dcf2c02..1f79341 100644 --- a/src/values/options.js +++ b/src/values/options.js @@ -65,11 +65,7 @@ class Builder { parent.add(parser, v => v[0]); } - parent.mapResults(v => ({ - option: v.intent, - values: v.values, - expression: v.expression - })); + parent.mapResults(v => new Option(v.intent, v.values, v.expression)); const repeating = language.repeating(parent.toMatcher()) .onlyBest() @@ -85,3 +81,22 @@ class Builder { export default function(options={}) { return new Builder(options); } + +/** + * Custom option value to hide enumeration for equality checks. + */ +class Option { + + constructor(option, values, expression) { + this.option = option; + this.values = values; + + Object.defineProperty(this, 'expression', { + enumerable: false, + writable: true + }); + + this.expression = expression; + } + +} diff --git a/test/value-options.test.js b/test/value-options.test.js index 6677e8d..688c656 100644 --- a/test/value-options.test.js +++ b/test/value-options.test.js @@ -21,13 +21,14 @@ describe('Value: Options', function() { { option: 'deadline', values: {}, - expression: [ - { - type: 'text', - value: 'with deadline', - source: { start: 0, end: 13 } - } - ] + } + ]); + + expect(v[0].expression).to.deep.equal([ + { + type: 'text', + value: 'with deadline', + source: { start: 0, end: 13 } } ]); }) @@ -39,13 +40,14 @@ describe('Value: Options', function() { { option: 'deadline', values: {}, - expression: [ - { - type: 'text', - value: 'with deadline', - source: { start: 0, end: 13 } - } - ] + } + ]); + + expect(v[0].expression).to.deep.equal([ + { + type: 'text', + value: 'with deadline', + source: { start: 0, end: 13 } } ]); }) @@ -57,13 +59,14 @@ describe('Value: Options', function() { { option: 'deadline', values: {}, - expression: [ - { - type: 'text', - value: 'with deadline', - source: { start: 0, end: 4 } - } - ] + } + ]); + + expect(v[0].expression).to.deep.equal([ + { + type: 'text', + value: 'with deadline', + source: { start: 0, end: 4 } } ]); }) @@ -75,13 +78,14 @@ describe('Value: Options', function() { { option: 'deadline', values: {}, - expression: [ - { - type: 'text', - value: 'with deadline', - source: { start: 0, end: 6 } - } - ] + } + ]); + + expect(v[0].expression).to.deep.equal([ + { + type: 'text', + value: 'with deadline', + source: { start: 0, end: 6 } } ]); }) @@ -93,24 +97,26 @@ describe('Value: Options', function() { { option: 'deadline', values: {}, - expression: [ - { - type: 'text', - value: 'with deadline', - source: { start: 0, end: 13 } - } - ] }, { option: 'deadline', - values: {}, - expression: [ - { - type: 'text', - value: 'with deadline', - source: { start: 18, end: 20 } - } - ] + values: {} + } + ]); + + expect(v[0].expression).to.deep.equal([ + { + type: 'text', + value: 'with deadline', + source: { start: 0, end: 13 } + } + ]); + + expect(v[1].expression).to.deep.equal([ + { + type: 'text', + value: 'with deadline', + source: { start: 18, end: 20 } } ]); })