Skip to content

Commit 16a040b

Browse files
davidlehndlongley
authored andcommitted
Add safe canonize mode tests.
1 parent 0229176 commit 16a040b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/misc.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3417,3 +3417,53 @@ _:b0 <ex:p> "v" .
34173417
});
34183418
});
34193419
});
3420+
3421+
describe('safe canonize defaults', () => {
3422+
it('does not throw on safe input', async () => {
3423+
const input =
3424+
{
3425+
"@id": "ex:id",
3426+
"ex:p": "v"
3427+
}
3428+
;
3429+
const expected =
3430+
'<ex:id> <ex:p> "v" .\n'
3431+
;
3432+
const result = await jsonld.canonize(input);
3433+
assert.deepStrictEqual(result, expected);
3434+
});
3435+
3436+
it('throws on unsafe input', async () => {
3437+
const input =
3438+
{
3439+
"@id": "ex:id",
3440+
"ex:p": "v",
3441+
"unknown": "error"
3442+
}
3443+
;
3444+
let error;
3445+
try {
3446+
await jsonld.canonize(input);
3447+
} catch(e) {
3448+
error = e;
3449+
}
3450+
assert(error, 'missing safe validation error');
3451+
});
3452+
3453+
it('allows override of safe mode', async () => {
3454+
const input =
3455+
{
3456+
"@id": "ex:id",
3457+
"ex:p": "v",
3458+
"unknown": "error"
3459+
}
3460+
;
3461+
const expected =
3462+
'<ex:id> <ex:p> "v" .\n'
3463+
;
3464+
const result = await jsonld.canonize(input, {
3465+
safe: false
3466+
});
3467+
assert.deepStrictEqual(result, expected);
3468+
});
3469+
});

0 commit comments

Comments
 (0)