@noeldemartin/solid-utils 0.6.0-next.cccdc9c7e033588e2df9d1887ceae49788344d84 → 0.6.0-next.de0818e7dae2a2267973b88c05e3e19601d4f4d0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ import type { MatcherState, MatchersObject } from '@vitest/expect';
2
+
3
+ import { normalizeSparql, normalizeTurtle } from '@noeldemartin/solid-utils/helpers/io';
4
+ import { jsonldEquals, sparqlEquals, turtleEquals } from '@noeldemartin/solid-utils/testing/helpers';
5
+ import type { EqualityResult } from '@noeldemartin/solid-utils/testing/helpers';
6
+ import type { JsonLD } from '@noeldemartin/solid-utils/helpers';
7
+
8
+ interface FormatResultOptions {
9
+ state: MatcherState;
10
+ hint: string;
11
+ expected: unknown;
12
+ received: unknown;
13
+ }
14
+
15
+ function formatResult(result: EqualityResult, options: FormatResultOptions) {
16
+ const pass = result.success;
17
+ const utils = options.state.utils;
18
+ const message = pass
19
+ ? () => [result.message, utils.matcherHint(options.hint)].join('\n\n')
20
+ : () =>
21
+ [
22
+ result.message,
23
+ utils.matcherHint(options.hint),
24
+ [
25
+ `Expected: not ${utils.printExpected(options.expected)}`,
26
+ `Received: ${utils.printReceived(options.received)}`,
27
+ ].join('\n'),
28
+ ].join('\n\n');
29
+
30
+ return { pass, message };
31
+ }
32
+
33
+ export function defineMatchers<T extends MatchersObject>(matchers: T): T {
34
+ return matchers;
35
+ }
36
+
37
+ export default defineMatchers({
38
+ async toEqualJsonLD(received, expected: JsonLD) {
39
+ const result = await jsonldEquals(expected, received);
40
+
41
+ return formatResult(result, {
42
+ state: this,
43
+ hint: 'toEqualJsonLD',
44
+ expected,
45
+ received,
46
+ });
47
+ },
48
+ toEqualSparql(received, expected: string) {
49
+ const result = sparqlEquals(expected, received);
50
+
51
+ return formatResult(result, {
52
+ state: this,
53
+ hint: 'toEqualSparql',
54
+ expected: normalizeSparql(expected),
55
+ received: normalizeSparql(received),
56
+ });
57
+ },
58
+ toEqualTurtle(received, expected: string) {
59
+ const result = turtleEquals(expected, received);
60
+
61
+ return formatResult(result, {
62
+ state: this,
63
+ hint: 'toEqualTurtle',
64
+ expected: normalizeTurtle(expected),
65
+ received: normalizeTurtle(received),
66
+ });
67
+ },
68
+ });