mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-11 09:51:30 +00:00
Refactor: Remove normalizeNewlines function and update tests to preserve newline types (#5697)
* refactor: remove `normalizeNewlines` function and update tests to preserve newline types
This commit is contained in:
@@ -153,7 +153,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
||||
},
|
||||
multilinetextblock(_1, content, _2) {
|
||||
return content.ast
|
||||
.split('\n')
|
||||
.split(/\r\n|\r|\n/)
|
||||
.map((line) => line.slice(indentLevel)) // Remove 4-space indentation
|
||||
.join('\n')
|
||||
.trim();
|
||||
|
||||
@@ -7,22 +7,14 @@ const safeParseJson = (json) => {
|
||||
}
|
||||
};
|
||||
|
||||
const normalizeNewlines = (str) => {
|
||||
if (!str || typeof str !== 'string') {
|
||||
return str || '';
|
||||
}
|
||||
|
||||
// "\r\n" is windows, "\r" is old mac, "\n" is linux
|
||||
return str.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
||||
};
|
||||
|
||||
const indentString = (str) => {
|
||||
if (!str || !str.length) {
|
||||
return str || '';
|
||||
}
|
||||
|
||||
return normalizeNewlines(str)
|
||||
.split('\n')
|
||||
return str
|
||||
.split(/\r\n|\r|\n/)
|
||||
.map((line) => ' ' + line)
|
||||
.join('\n');
|
||||
};
|
||||
@@ -32,8 +24,8 @@ const outdentString = (str) => {
|
||||
return str || '';
|
||||
}
|
||||
|
||||
return normalizeNewlines(str)
|
||||
.split('\n')
|
||||
return str
|
||||
.split(/\r\n|\r|\n/)
|
||||
.map((line) => line.replace(/^ /, ''))
|
||||
.join('\n');
|
||||
};
|
||||
@@ -56,7 +48,6 @@ const getValueString = (value) => {
|
||||
|
||||
module.exports = {
|
||||
safeParseJson,
|
||||
normalizeNewlines,
|
||||
indentString,
|
||||
outdentString,
|
||||
getValueString
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('getValueString', () => {
|
||||
});
|
||||
|
||||
it('normalizes different newline types', () => {
|
||||
expect(getValueString('line1\r\nline2\rline3\nline4')).toBe("'''\n line1\n line2\n line3\n line4\n'''");
|
||||
expect(getValueString('line1\r\nline2\rline3\nline4')).toBe('\'\'\'\n line1\n line2\n line3\n line4\n\'\'\'');
|
||||
});
|
||||
|
||||
it('returns empty string for empty/null/undefined', () => {
|
||||
|
||||
Reference in New Issue
Block a user