feat: bru lang now allows empty urls

This commit is contained in:
Anoop M D 2023-02-09 17:31:37 +05:30
parent efd15838aa
commit 242fcac2d3
3 changed files with 29 additions and 13 deletions

View File

@ -50,8 +50,6 @@ export const updateUidsInCollection = (_collection) => {
}; };
updateEnvUids(collection.environments); updateEnvUids(collection.environments);
console.log(collection);
return collection; return collection;
}; };

View File

@ -33,22 +33,22 @@ const grammar = ohm.grammar(`Bru {
stnl = st | nl stnl = st | nl
tagend = nl "}" tagend = nl "}"
optionalnl = ~tagend nl optionalnl = ~tagend nl
validkey = ~(st | ":") any keychar = ~(tagend | st | nl | ":") any
validvalue = ~nl any valuechar = ~(nl | tagend) any
// Dictionary Blocks // Dictionary Blocks
dictionary = st* "{" pairlist? tagend dictionary = st* "{" pairlist? tagend
pairlist = optionalnl* pair (~tagend stnl* pair)* (~tagend space)* pairlist = optionalnl* pair (~tagend stnl* pair)* (~tagend space)*
pair = st* key st* ":" st* value? st* pair = st* key st* ":" st* value st*
key = ~tagend validkey* key = keychar*
value = ~tagend validvalue* value = valuechar*
// Dictionary for Assert Block // Dictionary for Assert Block
assertdictionary = st* "{" assertpairlist? tagend assertdictionary = st* "{" assertpairlist? tagend
assertpairlist = optionalnl* assertpair (~tagend stnl* assertpair)* (~tagend space)* assertpairlist = optionalnl* assertpair (~tagend stnl* assertpair)* (~tagend space)*
assertpair = st* assertkey st* ":" st* value? st* assertpair = st* assertkey st* ":" st* value st*
assertkey = ~tagend assertvalidkey* assertkey = ~tagend assertkeychar*
assertvalidkey = ~(":") any assertkeychar = ~(tagend | nl | ":") any
// Text Blocks // Text Blocks
textblock = textline (~tagend nl textline)* textblock = textline (~tagend nl textline)*
@ -146,7 +146,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
}, },
pair(_1, key, _2, _3, _4, value, _5) { pair(_1, key, _2, _3, _4, value, _5) {
let res = {}; let res = {};
res[key.ast] = _.get(value, 'ast[0]', ''); res[key.ast] = value.ast ? value.ast.trim() : '';
return res; return res;
}, },
key(chars) { key(chars) {
@ -163,7 +163,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
}, },
assertpair(_1, key, _2, _3, _4, value, _5) { assertpair(_1, key, _2, _3, _4, value, _5) {
let res = {}; let res = {};
res[key.ast] = _.get(value, 'ast[0]', ''); res[key.ast] = value.ast ? value.ast.trim() : '';
return res; return res;
}, },
assertkey(chars) { assertkey(chars) {

View File

@ -1,5 +1,5 @@
/** /**
* This test file is used to test the text parser. * This test file is used to test the dictionary parser.
*/ */
const parser = require("../src/bruToJson"); const parser = require("../src/bruToJson");
@ -117,6 +117,24 @@ headers {
expect(output).toEqual(expected); expect(output).toEqual(expected);
}); });
it("should parse empty url", () => {
const input = `
get {
url:
body: json
}`;
const output = parser(input);
const expected = {
"http": {
"url": "",
"method": "get",
"body": "json",
}
};
expect(output).toEqual(expected);
});
it("should throw error on invalid header", () => { it("should throw error on invalid header", () => {
const input = ` const input = `
headers { headers {