-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-vectors.spec.ts
78 lines (72 loc) · 2.01 KB
/
test-vectors.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import * as fs from 'fs';
import * as path from 'path';
import { CBOR, types } from '..';
import { jsonld } from '../__fixtures__';
import { jsonLdToJson } from '../__fixtures__/utils/jsonldToJson';
import { documentLoader } from '../__fixtures__/utils/documentLoader';
const rows: any = [];
jsonld.forEach((vector: any) => {
let vectorName = vector.name.split('.')[0];
it(vectorName + ' can be converted to cbor', async () => {
const jsonld = vector.document;
const json = jsonLdToJson(jsonld);
const cbor = await CBOR.toCBOR(jsonld, types.CBOR);
const dag_cbor = await CBOR.toCBOR(jsonld, types.DAG_CBOR);
const zlib_urdna2015_cbor = await CBOR.toCBOR(
jsonld,
types.ZLIB_URDNA2015_CBOR,
documentLoader
);
fs.writeFileSync(
path.resolve(
__dirname,
'../__fixtures__/outputs/' + vector.name + `.json`
),
json
);
fs.writeFileSync(
path.resolve(
__dirname,
'../__fixtures__/outputs/' + vector.name + `.jsonld`
),
jsonld
);
fs.writeFileSync(
path.resolve(
__dirname,
'../__fixtures__/outputs/' + vector.name + `.cbor.b64`
),
cbor.toString('base64')
);
fs.writeFileSync(
path.resolve(
__dirname,
'../__fixtures__/outputs/' + vector.name + `.dag_cbor.b64`
),
dag_cbor.toString('base64')
);
fs.writeFileSync(
path.resolve(
__dirname,
'../__fixtures__/outputs/' + vector.name + `.zlib_urdna2015_cbor.b64`
),
zlib_urdna2015_cbor.toString('base64')
);
rows.push([
vectorName,
JSON.stringify(json).length,
JSON.stringify(jsonld).length,
cbor.length,
dag_cbor.length,
zlib_urdna2015_cbor.length,
]);
});
});
it('build-csv', () => {
const title = 'Input, JSON, JSON-LD, CBOR, DAG_CBOR, ZLIB_URDNA2015_CBOR';
const table = `${title}\n${rows.join('\n')}`;
fs.writeFileSync(
path.resolve(__dirname, '../__fixtures__/outputs/table.csv'),
table
);
});