|
1 | 1 | import test from 'node:test'; |
2 | 2 | import assert from 'node:assert'; |
3 | | -import getSchema from '@sourcemeta/std'; |
| 3 | +import getSchema, { schemas } from '@sourcemeta/std'; |
4 | 4 |
|
5 | 5 | test('loads a valid schema', () => { |
6 | 6 | const schema = getSchema('2020-12/misc/schema-like'); |
@@ -36,3 +36,31 @@ test('loads schema from nested path', () => { |
36 | 36 | assert.strictEqual(typeof schema, 'object'); |
37 | 37 | assert.strictEqual(schema.$schema, 'https://json-schema.org/draft/2020-12/schema'); |
38 | 38 | }); |
| 39 | + |
| 40 | +test('lazy loads schema via schemas object', () => { |
| 41 | + const schema = schemas['2020-12'].misc['schema-like']; |
| 42 | + assert.strictEqual(typeof schema, 'object'); |
| 43 | + assert.strictEqual(schema.title, 'JSON Schema Document'); |
| 44 | +}); |
| 45 | + |
| 46 | +test('caches loaded schemas', () => { |
| 47 | + const schema1 = schemas['2020-12'].misc['schema-like']; |
| 48 | + const schema2 = schemas['2020-12'].misc['schema-like']; |
| 49 | + assert.strictEqual(schema1, schema2); |
| 50 | +}); |
| 51 | + |
| 52 | +test('handles deeply nested paths', () => { |
| 53 | + const schema = schemas['2020-12'].w3c.xmlschema['2001']['hex-binary']; |
| 54 | + assert.strictEqual(typeof schema, 'object'); |
| 55 | + assert.strictEqual(schema.$schema, 'https://json-schema.org/draft/2020-12/schema'); |
| 56 | +}); |
| 57 | + |
| 58 | +test('returns undefined for non-existent directories', () => { |
| 59 | + const result = schemas['2020-12'].nonexistent; |
| 60 | + assert.strictEqual(result, undefined); |
| 61 | +}); |
| 62 | + |
| 63 | +test('returns undefined for non-existent files', () => { |
| 64 | + const result = schemas['2020-12'].misc['nonexistent-file']; |
| 65 | + assert.strictEqual(result, undefined); |
| 66 | +}); |
0 commit comments