Skip to content

Commit

Permalink
test(core/slangroom): fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
denizenging committed Sep 21, 2023
1 parent 73a087f commit f48adb5
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions pkg/core/test/slangroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ Then this statement does not exist

test('before-plugins can inject parameters', async (t) => {
const before = new BeforePlugin(() => {
console.log("foobarbra")
return {foo: 'bar' };
return { foo: 'bar' };
});
const slang = new Slangroom(before);
const contract = `Rule unknown ignore
Expand All @@ -82,7 +81,7 @@ Then I print 'foo'

test('after-plugins can return values', async (t) => {
const before = new AfterPlugin(() => {
return { foo: "bar" };
return { foo: 'bar' };
});
const slang = new Slangroom(before);
const contract = `Rule unknown ignore
Expand All @@ -96,36 +95,36 @@ Then I need an ignored statement

test('check statements order', async (t) => {
const beforeA = new BeforePlugin((ctx) => {
if(!ctx.params?.data) return
if(ctx.statement == "Given A") {
t.is(ctx.params?.data['state'], "BEGIN")
return {state: "A"}
if (!ctx.params?.data) return;
if (ctx.statement === 'Given A') {
t.is(ctx.params?.data['state'], 'BEGIN');
return { state: 'A' };
}
return
return;
});
const beforeB = new BeforePlugin((ctx) => {
if(!ctx.params?.data) return
if(ctx.statement == "Given B") {
t.is(ctx.params?.data['state'], "A")
return {state: "B"}
if (!ctx.params?.data) return;
if (ctx.statement === 'Given B') {
t.is(ctx.params?.data['state'], 'A');
return { state: 'B' };
}
return
return;
});
const afterC = new AfterPlugin((ctx) => {
if(!ctx.params?.data) return
if(ctx.statement == "Then C") {
t.is(ctx.result['state'], "B")
return {state: "C"}
if (!ctx.params?.data) return;
if (ctx.statement === 'Then C') {
t.is(ctx.result['state'], 'B');
return { state: 'C' };
}
return
return;
});
const afterD = new AfterPlugin((ctx) => {
if(!ctx.params?.data) return
if(ctx.statement == "Then D") {
t.is(ctx.result['state'], "C")
return {state: "D"}
if (!ctx.params?.data) return;
if (ctx.statement === 'Then D') {
t.is(ctx.result['state'], 'C');
return { state: 'D' };
}
return
return;
});
const slang = new Slangroom(beforeB, beforeA, afterD, afterC);
const contract = `Rule unknown ignore
Expand All @@ -136,6 +135,6 @@ Then print the 'state'
Then C
Then D
`;
const zout = await slang.execute(contract, { data: { state: "BEGIN" } });
const zout = await slang.execute(contract, { data: { state: 'BEGIN' } });
t.is(zout.result['state'] as string, 'D');
});

0 comments on commit f48adb5

Please sign in to comment.