feat: bruno lang - support parsing text body

This commit is contained in:
Anoop M D 2023-01-15 04:03:52 +05:30
parent 24e11a864c
commit a645d1459c
4 changed files with 22 additions and 3 deletions

View File

@ -12,6 +12,9 @@ const bodyJsonBegin = regex(/^body\s*\(\s*type\s*=\s*json\s*\)\s*\r?\n/);
// body(type=graphql)
const bodyGraphqlBegin = regex(/^body\s*\(\s*type\s*=\s*graphql\s*\)\s*\r?\n/);
// body(type=text)
const bodyTextBegin = regex(/^body\s*\(\s*type\s*=\s*text\s*\)\s*\r?\n/);
const bodyEnd = regex(/^\/body\s*[\r?\n]*/);
const bodyJsonTag = between(bodyJsonBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyJson) => {
@ -51,7 +54,16 @@ const bodyGraphqlTag = between(bodyGraphqlBegin)(bodyEnd)(everyCharUntil(bodyEnd
}
});
const bodyTextTag = between(bodyTextBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyText) => {
return {
body: {
text: bodyText
}
}
});
module.exports = {
bodyJsonTag,
bodyGraphqlTag
bodyGraphqlTag,
bodyTextTag
};

View File

@ -10,7 +10,8 @@ const paramsTag = require('./params-tag');
const headersTag = require('./headers-tag');
const {
bodyJsonTag,
bodyGraphqlTag
bodyGraphqlTag,
bodyTextTag
} = require('./body-tag');
const bruToJson = (fileContents) => {
@ -20,6 +21,7 @@ const bruToJson = (fileContents) => {
headersTag,
bodyJsonTag,
bodyGraphqlTag,
bodyTextTag,
anyChar
]));

View File

@ -32,3 +32,7 @@ body(type=graphql)
}
/body
body(type=text)
Hello, there. You must be from the past
/body

View File

@ -54,7 +54,8 @@ describe('bruToJson', () => {
"json": '{"apikey":"secret","numbers":"+91998877665"}',
"graphql": {
"query": " {\n launchesPast {\n launch_success\n }\n }\n"
}
},
"text": " Hello, there. You must be from the past\n"
}
});
});