2021-11-05 07:25:50 -06:00
|
|
|
import { JSONWriter } from './json-writer';
|
|
|
|
|
|
|
|
describe('util/json-writer/json-writer', () => {
|
|
|
|
const DATA = {
|
|
|
|
value: 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should apply 2 spaces indentation by default', () => {
|
|
|
|
const jsonWriter = new JSONWriter();
|
|
|
|
|
2021-11-08 05:16:58 -07:00
|
|
|
expect(jsonWriter.write(DATA)).toBe('{\n "value": 1\n}\n');
|
2021-11-05 07:25:50 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should apply indentation size', () => {
|
|
|
|
const jsonWriter = new JSONWriter({
|
2022-11-05 03:12:03 -06:00
|
|
|
indentationType: 'space',
|
2021-11-05 07:25:50 -06:00
|
|
|
indentationSize: 10,
|
|
|
|
});
|
|
|
|
|
2021-11-08 05:16:58 -07:00
|
|
|
expect(jsonWriter.write(DATA)).toBe('{\n "value": 1\n}\n');
|
2021-11-05 07:25:50 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should apply indentation type', () => {
|
|
|
|
const jsonWriter = new JSONWriter({
|
2022-11-05 03:12:03 -06:00
|
|
|
indentationType: 'tab',
|
2021-11-05 07:25:50 -06:00
|
|
|
});
|
|
|
|
|
2021-11-08 05:16:58 -07:00
|
|
|
expect(jsonWriter.write(DATA)).toBe('{\n\t"value": 1\n}\n');
|
2021-11-05 07:25:50 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('new line at the end should be optional', () => {
|
|
|
|
const jsonWriter = new JSONWriter({
|
2022-11-05 03:12:03 -06:00
|
|
|
indentationType: 'space',
|
2021-11-05 07:25:50 -06:00
|
|
|
indentationSize: 10,
|
|
|
|
});
|
|
|
|
|
2021-11-08 05:16:58 -07:00
|
|
|
expect(jsonWriter.write(DATA, false)).toBe('{\n "value": 1\n}');
|
2021-11-05 07:25:50 -06:00
|
|
|
});
|
|
|
|
});
|