forked from syndicate-lang/preserves
Add peel(); tweak strip; adjust tests to use accessors and peel
This commit is contained in:
parent
e35c237c34
commit
7efce309f6
|
@ -30,6 +30,10 @@ Annotated.prototype.strip = function (depth) {
|
|||
return stripAnnotations(this, depth);
|
||||
};
|
||||
|
||||
Annotated.prototype.peel = function () {
|
||||
return stripAnnotations(this, 1);
|
||||
};
|
||||
|
||||
Annotated.prototype.equals = function (other) {
|
||||
return isAnnotated(other) && is(this.item, other.item);
|
||||
};
|
||||
|
@ -51,7 +55,7 @@ function stripAnnotations(v, depth) {
|
|||
function walk(v) { return step(v, nextDepth); }
|
||||
|
||||
if (v.item instanceof Record) {
|
||||
return new Record(walk(v.item.label), v.item.fields.map(walk));
|
||||
return new Record(step(v.item.label, depth), v.item.fields.map(walk));
|
||||
} else if (List.isList(v.item)) {
|
||||
return v.item.map(walk);
|
||||
} else if (Set.isSet(v.item)) {
|
||||
|
|
|
@ -381,8 +381,8 @@ Record.makeBasicConstructor = function (label, fieldNames) {
|
|||
fieldNames.forEach((name, i) => {
|
||||
ctor['_'+name] = function (r) {
|
||||
if (!ctor.isClassOf(r)) {
|
||||
throw new Error("Record: attempt to retrieve field "+label+"."+name+
|
||||
" from non-"+label+": "+(r && r.toString()));
|
||||
throw new Error("Record: attempt to retrieve field "+label.toString()+"."+name+
|
||||
" from non-"+label.toString()+": "+(r && r.toString()));
|
||||
}
|
||||
return r.get(i);
|
||||
};
|
||||
|
|
|
@ -81,8 +81,12 @@ describe('common test suite', () => {
|
|||
const samples_bin = fs.readFileSync(__dirname + '/../../../tests/samples.bin');
|
||||
const samples = decodeWithAnnotations(samples_bin);
|
||||
|
||||
const expectedPlaceholderMapping = samples.item.get(0).strip();
|
||||
const placeholders_decode = expectedPlaceholderMapping.get(0);
|
||||
const TestCases = Record.makeConstructor('TestCases', ['mapping', 'cases']);
|
||||
const ExpectedPlaceholderMapping =
|
||||
Record.makeConstructor('ExpectedPlaceholderMapping', ['table']);
|
||||
|
||||
const expectedPlaceholderMapping = TestCases._mapping(samples.peel()).strip();
|
||||
const placeholders_decode = ExpectedPlaceholderMapping._table(expectedPlaceholderMapping);
|
||||
const placeholders_encode = placeholders_decode.mapEntries((e) => [e[1],e[0]]);
|
||||
|
||||
function DS(bs) {
|
||||
|
@ -177,11 +181,11 @@ describe('common test suite', () => {
|
|||
});
|
||||
}
|
||||
|
||||
const tests = samples.item.get(1).item;
|
||||
const tests = TestCases._cases(samples.peel()).peel();
|
||||
tests.forEach((t0, tName0) => {
|
||||
const tName = Symbol.keyFor(tName0.strip());
|
||||
const t = t0.item;
|
||||
switch (t.label.item) {
|
||||
const t = t0.peel();
|
||||
switch (t.label) {
|
||||
case Symbol.for('Test'):
|
||||
runTestCase('normal', tName, t.get(0).strip(), t.get(1));
|
||||
break;
|
||||
|
@ -222,7 +226,7 @@ describe('common test suite', () => {
|
|||
default:{
|
||||
const e = new Error('Unsupported test kind');
|
||||
e.irritant = t;
|
||||
e.testKind = t.label.item;
|
||||
e.testKind = t.label;
|
||||
console.error(e);
|
||||
throw e;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue