Skip to content

Commit

Permalink
fix(values): Options value need to hide expression from equality check
Browse files Browse the repository at this point in the history
  • Loading branch information
aholstenson committed Oct 21, 2018
1 parent 2879f47 commit 6b12a3c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 48 deletions.
25 changes: 20 additions & 5 deletions src/values/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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;
}

}
92 changes: 49 additions & 43 deletions test/value-options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
]);
})
Expand All @@ -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 }
}
]);
})
Expand All @@ -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 }
}
]);
})
Expand All @@ -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 }
}
]);
})
Expand All @@ -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 }
}
]);
})
Expand Down

0 comments on commit 6b12a3c

Please sign in to comment.