-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement merge/omit/concat/compact (#84)
- Loading branch information
Showing
3 changed files
with
179 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import { Slangroom } from '@slangroom/core'; | ||
import { helpers } from '@slangroom/helpers'; | ||
import test from 'ava'; | ||
|
||
test('@slangroom/helpers π compact arrays ', async (t) => { | ||
const picked = `Rule unknown ignore | ||
Given I send array 'the_array' and manipulate and compact and output into 'mimmo' | ||
Given I have a 'string array' named 'the_array' | ||
Given I have a 'string dictionary' named 'mimmo' | ||
Then print 'mimmo' | ||
`; | ||
|
||
const slangroom = new Slangroom(helpers); | ||
const res = await slangroom.execute(picked, { | ||
data: { | ||
"the_array": [0, "c", false, "d", '', "π"] | ||
}, | ||
}); | ||
t.deepEqual(res.result, { | ||
mimmo: [ | ||
"c", | ||
"d", | ||
"π", | ||
] | ||
}, res.logs) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { Slangroom } from '@slangroom/core'; | ||
import { helpers } from '@slangroom/helpers'; | ||
import test from 'ava'; | ||
|
||
test('@slangroom/helpers 𧲠concat arrays ', async (t) => { | ||
const picked = `Rule unknown ignore | ||
Given I send array 'the_array' and send values 'v' and manipulate and concat and output into 'r' | ||
Given I have a 'string array' named 'the_array' | ||
Given I have a 'string dictionary' named 'r' | ||
Then print 'r' | ||
`; | ||
|
||
const slangroom = new Slangroom(helpers); | ||
const res = await slangroom.execute(picked, { | ||
data: { | ||
"v": ["a", "b", "π"], | ||
"the_array": ["c", "d", "π"] | ||
}, | ||
}); | ||
t.deepEqual(res.result, { | ||
r: [ | ||
"c", | ||
"d", | ||
"π", | ||
"a", | ||
"b", | ||
"π" | ||
] | ||
}, res.logs) | ||
}); | ||
|
||
test('@slangroom/helpers 𧲠concat arrays with missing values', async (t) => { | ||
const picked = `Rule unknown ignore | ||
Given I send array 'the_array' and manipulate and concat and output into 'r' | ||
Given I have a 'string array' named 'the_array' | ||
Given I have a 'string dictionary' named 'r' | ||
Then print 'r' | ||
`; | ||
|
||
const slangroom = new Slangroom(helpers); | ||
const fn = slangroom.execute(picked, { | ||
data: { | ||
"the_array": ["c", "d", "π"] | ||
}, | ||
}); | ||
const error = await t.throwsAsync(fn); | ||
t.is((error as Error).message, 'ParseError: "concat" between (50, 55) must be one of: compact'); | ||
}); | ||
|
||
test('@slangroom/helpers 𧲠concat empty array', async (t) => { | ||
const picked = `Rule unknown ignore | ||
Given I send array 'the_array' and send values 'v' and manipulate and concat and output into 'r' | ||
Given I have a 'string array' named 'the_array' | ||
Given I have a 'string dictionary' named 'r' | ||
Then print 'r' | ||
`; | ||
|
||
const slangroom = new Slangroom(helpers); | ||
const res = await slangroom.execute(picked, { | ||
data: { | ||
"v": ["a", "b", "π"], | ||
"the_array": [] | ||
}, | ||
}); | ||
t.deepEqual(res.result, { | ||
r: ["a", "b", "π"] | ||
}, res.logs) | ||
}); | ||
|
||
test('@slangroom/helpers 𧲠concat empty values', async (t) => { | ||
const picked = `Rule unknown ignore | ||
Given I send array 'the_array' and send values 'v' and manipulate and concat and output into 'r' | ||
Given I have a 'string array' named 'the_array' | ||
Given I have a 'string dictionary' named 'r' | ||
Then print 'r' | ||
`; | ||
|
||
const slangroom = new Slangroom(helpers); | ||
const res = await slangroom.execute(picked, { | ||
data: { | ||
"v": [], | ||
"the_array": ["c", "d", "π"] | ||
}, | ||
}); | ||
t.deepEqual(res.result, { | ||
r: ["c", "d", "π"] | ||
}, res.logs) | ||
}); | ||
|
||
test('@slangroom/helpers 𧲠concat empty values and empty array', async (t) => { | ||
const picked = `Rule unknown ignore | ||
Given I send array 'the_array' and send values 'v' and manipulate and concat and output into 'r' | ||
Given I have a 'string array' named 'the_array' | ||
Given I have a 'string dictionary' named 'r' | ||
Then print 'r' | ||
`; | ||
|
||
const slangroom = new Slangroom(helpers); | ||
const res = await slangroom.execute(picked, { | ||
data: { | ||
"v": [], | ||
"the_array": [] | ||
}, | ||
}); | ||
t.deepEqual(res.result, { | ||
r: [] | ||
}, res.logs) | ||
}); |