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);
console.log(collection);
return collection;
};

View File

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