Skip to content

Commit

Permalink
Merge pull request #4 from shokuie/choice-revision
Browse files Browse the repository at this point in the history
Adding more test for better coverage
  • Loading branch information
shokuie committed Dec 9, 2018
2 parents 7c5f084 + 32941bd commit b92b7c5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@ node_modules
.nyc_output
coverage
.DS_Store
package-lock.json
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -21,7 +21,7 @@
},
"homepage": "https://github.com/atesgoral/node-asn1-mapper#readme",
"devDependencies": {
"ava": "1.0.0-beta.4",
"ava": "^0.25.0",
"coveralls": "^2.13.1",
"nyc": "^11.1.0"
}
Expand Down
30 changes: 30 additions & 0 deletions test/index.js
Expand Up @@ -462,6 +462,36 @@ test('fromTree: CHOICE where element is CLS_CONTEXT_SPECIFIC and second choice m
t.deepEqual(asn1Mapper.fromTree(tree, definition), mapped);
});

test('fromTree: CHOICE where element is CLS_CONTEXT_SPECIFIC and no choice matches', (t) => {
const tree = {
cls: CLS_CONTEXT_SPECIFIC,
form: FORM_CONSTRUCTED,
tagCode: 3,
elements: [{
cls: CLS_CONTEXT_SPECIFIC,
form: FORM_PRIMITIVE,
tagCode: 2,
value: Buffer.from([1, 2, 3])
}]
};
const definition = {
type: 'CHOICE',
tag: 3,
elements: [{
name: 'foo',
tag: 0,
type: 'NULL'
}, {
name: 'bar',
tag: 1,
type: 'OCTET STRING'
}]
};

const error = t.throws(() => asn1Mapper.fromTree(tree, definition));
t.is(error.message, 'No definitions found for element.');
});

test('fromTree: CHOICE where no choices match', (t) => {
const tree = {
cls: CLS_UNIVERSAL,
Expand Down

0 comments on commit b92b7c5

Please sign in to comment.