Clean up language wrt invertibility/"bijection"

This commit is contained in:
Tony Garnock-Jones 2021-05-25 20:13:02 +02:00
parent badb059440
commit 460529e1c7
3 changed files with 8 additions and 8 deletions

View File

@ -61,7 +61,7 @@ export function readSchema(source: string,
{
const checked = checkSchema(parseSchema(_readSchema(source, options), options ?? {}));
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'));
}

View File

@ -3,17 +3,17 @@ import { Meta, readSchema } from '../src/index';
import './test-utils';
describe('checker', () => {
describe('simplest non-bijection tests', () => {
it('passes simple non-bijection test', () => {
describe('simplest invertibility tests', () => {
it('passes simple invertibility test', () => {
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();
});
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/);
});
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/);
});
it('is OK with no names in simple seqof', () => {
@ -35,7 +35,7 @@ describe('checker', () => {
<tuple* [<named a <atom String>>, <named b <atom String>>]
<named extra <seqof any>>>>}}>`).next());
});
it('non-bijection tail', () => {
it('non-invertibility tail', () => {
expect(() => readSchema(
'version 1 . ExtensibleRecord = <foo @a string @b string any ...>.'))
.toThrow(/tail of fields of ExtensibleRecord/);

View File

@ -25,7 +25,7 @@
[(SimplePattern-lit _)
(void)]
[(? SimplePattern?)
(when (not value-available?) (problem! context "non-bijection"))]
(when (not value-available?) (problem! context "necessary information not captured"))]
[(CompoundPattern-rec l f)
(check-named-pattern (cons "label" context) scope l)
(check-named-pattern (cons "fields" context) scope f)]