import { Reader } from '@preserves/core';
import { Meta, readSchema } from '../src/index';
import './test-utils';
describe('checker', () => {
describe('simplest non-bijection tests', () => {
it('passes simple non-bijection test', () => {
expect(readSchema('version 1 . A = .')).not.toBeNull();
});
it('passes non-bijection check for literal field', () => {
expect(readSchema('version 1 . A = .')).not.toBeNull();
});
it('detects non-bijection for string field', () => {
expect(() => readSchema('version 1 . A = .')).toThrow(/item 0 of fields of A/);
});
it('detects non-bijection for symbol field', () => {
expect(() => readSchema('version 1 . A = .')).toThrow(/item 1 of fields of A/);
});
});
describe('extensible record', () => {
it('is happy with extensible record', () => {
expect(Meta.fromSchema(readSchema(
'version 1 . ExtensibleRecord = .')))
.is(new Reader(
`
>, >]
>>>}}>`).next());
});
it('non-bijection tail', () => {
expect(() => readSchema(
'version 1 . ExtensibleRecord = .'))
.toThrow(/tail of fields of ExtensibleRecord/);
});
});
});