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';
|
||||
|
||||
function P(s: string): Value<any>[] {
|
||||
return parse(s, { includeAnnotations: true });
|
||||
}
|
||||
|
||||
describe('basics', () => {
|
||||
it('simple example', () => {
|
||||
const r = new Pexpr.Reader('#!foo\n<bar {zot ::quux}, [a; b; c;]>');
|
||||
const d = r.nextDocument();
|
||||
console.dir(d, { depth: null });
|
||||
console.log(stringify(d, { indent: 4 }));
|
||||
for (const p of d.get(0)!.item as Pexpr.Record) {
|
||||
console.log(stringify(p.item, { indent: 4 }));
|
||||
}
|
||||
expect(fromJS(d)).is(P(`[\n#!foo\n
|
||||
<r bar <b zot <p |::|> quux> <p |,|> [a <p |;|> b <p |;|> c <p |;|>]>]`));
|
||||
});
|
||||
|
||||
it('simple group', () => {
|
||||
const r = new Pexpr.Reader('(+ 1 2)');
|
||||
expect(fromJS(r.nextDocument())).is(P('[<g + 1 2>]'));
|
||||
});
|
||||
|
||||
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)!);
|
||||
console.log(stringify(v, { indent: 4 }));
|
||||
console.log(stringify(d.get(0)!.item, { indent: 4 }));
|
||||
expect(v).is(P(s));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue