Skip to content

Commit

Permalink
fix: handle-array-wildcard (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
BillDorn authored and redonkulus committed Oct 1, 2019
1 parent 4fcbebc commit 9ac62b8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,8 @@ Ycb.prototype = {
var valueChunk = contextValue[k];
if(usedValues[dimensionName][valueChunk] === 2) {
newValue.push(this.valueToNumber[dimensionName][valueChunk]);
} else if(valueChunk === DEFAULT) {
newValue.push(0);
} else {
logBundleWarning(configIndex, 'invalid value ' + valueChunk + ' for dimension ' + dimensionName,
JSON.stringify(setting));
Expand Down
48 changes: 48 additions & 0 deletions tests/fixtures/wildcard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[
{
"dimensions": [
{
"lang": {
"en":null,
"fr": {
"fr_FR": {
"fr_CA": null
}
}
}
},
{
"region": {
"us": null,
"fr": null
}
},
{
"flavor": {
"att": null,
"bt": null
}
}
]
},
{
"settings": ["region:*"],
"val1": 1
},
{
"settings": ["region:fr","flavor:*"],
"val2": 1
},
{
"settings": ["region:fr","flavor:att,bt"],
"val3": 1
},
{
"settings": ["region:fr","flavor:att,*"],
"val4": 1
},
{
"settings": ["lang:en,*,*,*,*"],
"val5": 1
}
]
14 changes: 14 additions & 0 deletions tests/unit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,20 @@ describe('ycb unit tests', function () {
assert.equal(80, config.appPort);
});

it('should handle wildcard settings', function () {
var bundle,
ycb,
config;
bundle = readFixtureFile('wildcard.json');
ycb = new libycb.Ycb(bundle);
config = ycb.read({});
cmp(config, {val1:1, val5:1});
config = ycb.read({region: 'fr'});
cmp(config, {val1:1, val5:1, val2:1, val4:1});
config = ycb.read({region: 'fr', flavor: 'att'});
cmp(config, {val1:1, val5:1, val2:1, val4:1, val3:1});
});

it('should handle multi-level matching', function () {
var bundle,
ycb,
Expand Down

0 comments on commit 9ac62b8

Please sign in to comment.