mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 09:23:17 +01:00
feat: assert tab allows any valid js code as keys
This commit is contained in:
parent
45ed47ff90
commit
aff6499478
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@usebruno/lang",
|
||||
"version": "0.1.0",
|
||||
"version": "0.1.1",
|
||||
"main": "src/index.js",
|
||||
"files": [
|
||||
"src",
|
||||
|
@ -43,6 +43,13 @@ const grammar = ohm.grammar(`Bru {
|
||||
key = ~tagend validkey*
|
||||
value = ~tagend validvalue*
|
||||
|
||||
// Dictionary for Assert Block
|
||||
assertdictionary = st* "{" assertpairlist? tagend
|
||||
assertpairlist = optionalnl* assertpair (~tagend stnl* assertpair)* (~tagend space)*
|
||||
assertpair = st* assertkey st* ":" st* value? st*
|
||||
assertkey = ~tagend assertvalidkey*
|
||||
assertvalidkey = ~(":") any
|
||||
|
||||
// Text Blocks
|
||||
textblock = textline (~tagend nl textline)*
|
||||
textline = textchar*
|
||||
@ -67,7 +74,7 @@ const grammar = ohm.grammar(`Bru {
|
||||
varsandassert = varsreq | varsres | assert
|
||||
varsreq = "vars:pre-request" dictionary
|
||||
varsres = "vars:post-response" dictionary
|
||||
assert = "assert" dictionary
|
||||
assert = "assert" assertdictionary
|
||||
|
||||
body = "body" st* "{" nl* textblock tagend
|
||||
bodyjson = "body:json" st* "{" nl* textblock tagend
|
||||
@ -148,6 +155,20 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
||||
value(chars) {
|
||||
return chars.sourceString ? chars.sourceString.trim() : '';
|
||||
},
|
||||
assertdictionary(_1, _2, pairlist, _3) {
|
||||
return pairlist.ast;
|
||||
},
|
||||
assertpairlist(_1, pair, _2, rest, _3) {
|
||||
return [pair.ast, ...rest.ast];
|
||||
},
|
||||
assertpair(_1, key, _2, _3, _4, value, _5) {
|
||||
let res = {};
|
||||
res[key.ast] = _.get(value, 'ast[0]', '');
|
||||
return res;
|
||||
},
|
||||
assertkey(chars) {
|
||||
return chars.sourceString ? chars.sourceString.trim() : '';
|
||||
},
|
||||
textblock(line, _1, rest) {
|
||||
return [line.ast, ...rest.ast].join('\n');
|
||||
},
|
||||
|
24
packages/bruno-lang/v2/tests/assert.spec.js
Normal file
24
packages/bruno-lang/v2/tests/assert.spec.js
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* This test file is used to test the text parser.
|
||||
*/
|
||||
const parser = require("../src/bruToJson");
|
||||
|
||||
describe("assert parser", () => {
|
||||
it("should parse assert statement", () => {
|
||||
const input = `
|
||||
assert {
|
||||
res("data.airports").filter(a => a.code ==="BLR").name: "Bangalore International Airport"
|
||||
}
|
||||
`;
|
||||
|
||||
const output = parser(input);
|
||||
const expected = {
|
||||
"assert": [{
|
||||
name: "res(\"data.airports\").filter(a => a.code ===\"BLR\").name",
|
||||
value: '"Bangalore International Airport"',
|
||||
enabled: true
|
||||
}]
|
||||
};
|
||||
expect(output).toEqual(expected);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user