Clean up language wrt invertibility/"bijection"
This commit is contained in:
parent
badb059440
commit
460529e1c7
|
@ -61,7 +61,7 @@ export function readSchema(source: string,
|
||||||
{
|
{
|
||||||
const checked = checkSchema(parseSchema(_readSchema(source, options), options ?? {}));
|
const checked = checkSchema(parseSchema(_readSchema(source, options), options ?? {}));
|
||||||
if (checked.ok) return checked.schema;
|
if (checked.ok) return checked.schema;
|
||||||
throw new Error(`Schema does not specify a bijection:\n` +
|
throw new Error(`Schema is not invertible:\n` +
|
||||||
checked.problems.map(c => ' - ' + c).join('\n'));
|
checked.problems.map(c => ' - ' + c).join('\n'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,17 @@ import { Meta, readSchema } from '../src/index';
|
||||||
import './test-utils';
|
import './test-utils';
|
||||||
|
|
||||||
describe('checker', () => {
|
describe('checker', () => {
|
||||||
describe('simplest non-bijection tests', () => {
|
describe('simplest invertibility tests', () => {
|
||||||
it('passes simple non-bijection test', () => {
|
it('passes simple invertibility test', () => {
|
||||||
expect(readSchema('version 1 . A = <a @x string @y symbol> .')).not.toBeNull();
|
expect(readSchema('version 1 . A = <a @x string @y symbol> .')).not.toBeNull();
|
||||||
});
|
});
|
||||||
it('passes non-bijection check for literal field', () => {
|
it('passes invertibility check for literal field', () => {
|
||||||
expect(readSchema('version 1 . A = <a "string" @y symbol> .')).not.toBeNull();
|
expect(readSchema('version 1 . A = <a "string" @y symbol> .')).not.toBeNull();
|
||||||
});
|
});
|
||||||
it('detects non-bijection for string field', () => {
|
it('detects non-invertibility for string field', () => {
|
||||||
expect(() => readSchema('version 1 . A = <a string @y symbol> .')).toThrow(/item 0 of fields of A/);
|
expect(() => readSchema('version 1 . A = <a string @y symbol> .')).toThrow(/item 0 of fields of A/);
|
||||||
});
|
});
|
||||||
it('detects non-bijection for symbol field', () => {
|
it('detects non-invertibility for symbol field', () => {
|
||||||
expect(() => readSchema('version 1 . A = <a @x string symbol> .')).toThrow(/item 1 of fields of A/);
|
expect(() => readSchema('version 1 . A = <a @x string symbol> .')).toThrow(/item 1 of fields of A/);
|
||||||
});
|
});
|
||||||
it('is OK with no names in simple seqof', () => {
|
it('is OK with no names in simple seqof', () => {
|
||||||
|
@ -35,7 +35,7 @@ describe('checker', () => {
|
||||||
<tuple* [<named a <atom String>>, <named b <atom String>>]
|
<tuple* [<named a <atom String>>, <named b <atom String>>]
|
||||||
<named extra <seqof any>>>>}}>`).next());
|
<named extra <seqof any>>>>}}>`).next());
|
||||||
});
|
});
|
||||||
it('non-bijection tail', () => {
|
it('non-invertibility tail', () => {
|
||||||
expect(() => readSchema(
|
expect(() => readSchema(
|
||||||
'version 1 . ExtensibleRecord = <foo @a string @b string any ...>.'))
|
'version 1 . ExtensibleRecord = <foo @a string @b string any ...>.'))
|
||||||
.toThrow(/tail of fields of ExtensibleRecord/);
|
.toThrow(/tail of fields of ExtensibleRecord/);
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
[(SimplePattern-lit _)
|
[(SimplePattern-lit _)
|
||||||
(void)]
|
(void)]
|
||||||
[(? SimplePattern?)
|
[(? SimplePattern?)
|
||||||
(when (not value-available?) (problem! context "non-bijection"))]
|
(when (not value-available?) (problem! context "necessary information not captured"))]
|
||||||
[(CompoundPattern-rec l f)
|
[(CompoundPattern-rec l f)
|
||||||
(check-named-pattern (cons "label" context) scope l)
|
(check-named-pattern (cons "label" context) scope l)
|
||||||
(check-named-pattern (cons "fields" context) scope f)]
|
(check-named-pattern (cons "fields" context) scope f)]
|
||||||
|
|
Loading…
Reference in New Issue