mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
Answer binary requests in the literal-values test transport
Object replies are read through binary() since the checker objects are resolved from their ids, so the test transport answers both forms.
This commit is contained in:
@@ -8,16 +8,15 @@ import {
|
||||
|
||||
function harness() {
|
||||
const members = new Map<number, SemanticTypeData[]>();
|
||||
const snapshot = new SemanticSnapshot(1, {
|
||||
text(method, payload) {
|
||||
const query = JSON.parse(payload) as { objectId: number };
|
||||
if (method !== "getTypesOfType" || !members.has(query.objectId))
|
||||
throw new Error(`unexpected request: ${method}`);
|
||||
return JSON.stringify(members.get(query.objectId));
|
||||
},
|
||||
binary(method) {
|
||||
const reply = (method: string, payload: string) => {
|
||||
const query = JSON.parse(payload) as { objectId: number };
|
||||
if (method !== "getTypesOfType" || !members.has(query.objectId))
|
||||
throw new Error(`unexpected request: ${method}`);
|
||||
},
|
||||
return JSON.stringify(members.get(query.objectId));
|
||||
};
|
||||
const snapshot = new SemanticSnapshot(1, {
|
||||
text: reply,
|
||||
binary: (method, payload) => new TextEncoder().encode(reply(method, payload)),
|
||||
});
|
||||
const project = snapshot.addProject("literal-values", () => undefined);
|
||||
let id = 0;
|
||||
|
||||
Reference in New Issue
Block a user