2023-09-21 21:12:48 +02:00
|
|
|
const { safeParseJson, indentString, outdentString, get } = require('../src/utils');
|
2023-01-15 20:19:06 +01:00
|
|
|
|
|
|
|
describe('utils', () => {
|
|
|
|
describe('safeParseJson', () => {
|
|
|
|
it('should parse valid json', () => {
|
|
|
|
const input = '{"a": 1}';
|
|
|
|
const result = safeParseJson(input);
|
|
|
|
expect(result).toEqual({ a: 1 });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return null for invalid json', () => {
|
|
|
|
const input = '{"a": 1';
|
|
|
|
const result = safeParseJson(input);
|
|
|
|
expect(result).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('indentString', () => {
|
|
|
|
it('correctly indents a multiline string', () => {
|
2023-09-21 21:12:48 +02:00
|
|
|
const input = 'line1\nline2\nline3';
|
|
|
|
const expectedOutput = ' line1\n line2\n line3';
|
2023-01-15 20:19:06 +01:00
|
|
|
expect(indentString(input)).toBe(expectedOutput);
|
|
|
|
});
|
|
|
|
});
|
2023-01-16 20:25:47 +01:00
|
|
|
|
|
|
|
describe('outdentString', () => {
|
|
|
|
it('correctly outdents a multiline string', () => {
|
2023-09-21 21:12:48 +02:00
|
|
|
const input = ' line1\n line2\n line3';
|
|
|
|
const expectedOutput = 'line1\nline2\nline3';
|
2023-01-16 20:25:47 +01:00
|
|
|
expect(outdentString(input)).toBe(expectedOutput);
|
|
|
|
});
|
|
|
|
});
|
2023-09-21 21:12:48 +02:00
|
|
|
});
|