Update pexpr tests
This commit is contained in:
parent
a8b300e57d
commit
cadf54b927
|
@ -1,21 +1,27 @@
|
||||||
import { Pexpr, stringify } from '../src/index';
|
import { Pexpr, Value, fromJS, parse, stringify } from '../src/index';
|
||||||
import './test-utils';
|
import './test-utils';
|
||||||
|
|
||||||
|
function P(s: string): Value<any>[] {
|
||||||
|
return parse(s, { includeAnnotations: true });
|
||||||
|
}
|
||||||
|
|
||||||
describe('basics', () => {
|
describe('basics', () => {
|
||||||
it('simple example', () => {
|
it('simple example', () => {
|
||||||
const r = new Pexpr.Reader('#!foo\n<bar {zot ::quux}, [a; b; c;]>');
|
const r = new Pexpr.Reader('#!foo\n<bar {zot ::quux}, [a; b; c;]>');
|
||||||
const d = r.nextDocument();
|
const d = r.nextDocument();
|
||||||
console.dir(d, { depth: null });
|
expect(fromJS(d)).is(P(`[\n#!foo\n
|
||||||
console.log(stringify(d, { indent: 4 }));
|
<r bar <b zot <p |::|> quux> <p |,|> [a <p |;|> b <p |;|> c <p |;|>]>]`));
|
||||||
for (const p of d.get(0)!.item as Pexpr.Record) {
|
});
|
||||||
console.log(stringify(p.item, { indent: 4 }));
|
|
||||||
}
|
it('simple group', () => {
|
||||||
|
const r = new Pexpr.Reader('(+ 1 2)');
|
||||||
|
expect(fromJS(r.nextDocument())).is(P('[<g + 1 2>]'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('asPreserves', () => {
|
it('asPreserves', () => {
|
||||||
const d = new Pexpr.Reader('{a: b, c: d, e: [1, 2 <r 3 4>]}').nextDocument();
|
const s = '{a: b, c: d, e: [1, 2 <r 3 4>]}';
|
||||||
|
const d = new Pexpr.Reader(s).nextDocument();
|
||||||
const v = Pexpr.asPreserves(d.get(0)!);
|
const v = Pexpr.asPreserves(d.get(0)!);
|
||||||
console.log(stringify(v, { indent: 4 }));
|
expect(v).is(P(s));
|
||||||
console.log(stringify(d.get(0)!.item, { indent: 4 }));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue