json-validate-contract.test.mjs
40 lines 1.2 KB
Raw
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor ⚠ breaking 12 days ago
1 /**
2 * Contract examples for hub/icp JsonValidate.mo (enrich fragments).
3 * Motoko implementation mirrors RFC 8259 subset; these cases must stay parseable as JSON
4 * values and match JSON.parse for acceptance (including trailing whitespace after the value).
5 */
6 import assert from 'node:assert';
7 import test from 'node:test';
8
9 const validArrays = ['[]', '[1]', ' [ "a" ] ', '[1]\n', '["x","y"]'];
10 const validObjects = ['{}', '{"a":1}', ' { } ', '{"k":[1,2]}'];
11
12 for (const s of validArrays) {
13 test(`valid JSON array: ${JSON.stringify(s)}`, () => {
14 const v = JSON.parse(s);
15 assert.ok(Array.isArray(v));
16 });
17 }
18
19 for (const s of validObjects) {
20 test(`valid JSON object: ${JSON.stringify(s)}`, () => {
21 const v = JSON.parse(s);
22 assert.ok(v !== null && typeof v === 'object' && !Array.isArray(v));
23 });
24 }
25
26 const invalidAsArray = ['{}', '[', '[1,]', '{"a":1}', '[broken', ''];
27 for (const s of invalidAsArray) {
28 test(`not a JSON array (parse fails or not array): ${JSON.stringify(s)}`, () => {
29 try {
30 const v = JSON.parse(s);
31 assert.ok(notArray(v), 'expected not array');
32 } catch {
33 assert.ok(true);
34 }
35 });
36 }
37
38 function notArray(v) {
39 return !Array.isArray(v);
40 }
File History 4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf mirror: GitHub Phase A durable MCP OAuth (#270) Human minor 12 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b fix(7C-L1b): route hosted delegation proposals through cani… Human minor 32 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91 fix: repair endpoint now sets has_active_subscription when … Human minor 51 days ago