mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import 'jest-rdf';
|
|
import { DataFactory } from 'n3';
|
|
import { parseQuads, serializeQuads } from '../../../src/util/QuadUtil';
|
|
import { guardedStreamFrom, readableToString } from '../../../src/util/StreamUtil';
|
|
const { literal, namedNode, quad } = DataFactory;
|
|
|
|
describe('QuadUtil', (): void => {
|
|
describe('#serializeQuads', (): void => {
|
|
it('converts quads to the requested format.', async(): Promise<void> => {
|
|
const quads = [ quad(
|
|
namedNode('pre:sub'),
|
|
namedNode('pre:pred'),
|
|
literal('obj'),
|
|
) ];
|
|
const stream = serializeQuads(quads, 'application/n-triples');
|
|
await expect(readableToString(stream)).resolves.toMatch('<pre:sub> <pre:pred> "obj" .');
|
|
});
|
|
});
|
|
|
|
describe('#parseQuads', (): void => {
|
|
it('parses quads.', async(): Promise<void> => {
|
|
const stream = guardedStreamFrom([ '<pre:sub> <pre:pred> "obj".' ]);
|
|
await expect(parseQuads(stream)).resolves.toEqualRdfQuadArray([ quad(
|
|
namedNode('pre:sub'),
|
|
namedNode('pre:pred'),
|
|
literal('obj'),
|
|
) ]);
|
|
});
|
|
|
|
it('parses quads with the given options.', async(): Promise<void> => {
|
|
const stream = guardedStreamFrom([ '<> <pre:pred> "obj".' ]);
|
|
await expect(parseQuads(stream, { baseIRI: 'pre:sub' })).resolves.toEqualRdfQuadArray([ quad(
|
|
namedNode('pre:sub'),
|
|
namedNode('pre:pred'),
|
|
literal('obj'),
|
|
) ]);
|
|
});
|
|
});
|
|
});
|