feat(smartjson): Add JSONL stringify and ordering comparator; fix empty buffer handling; refactor Smartjson folding/enfolding
This commit is contained in:
@@ -72,4 +72,36 @@ tap.test('should work with buffers', async () => {
|
||||
expect(text).toEqual('hello');
|
||||
});
|
||||
|
||||
tap.test('should handle empty buffers', async () => {
|
||||
const someObject = { empty: new Uint8Array([]) };
|
||||
const json = smartjson.stringify(someObject);
|
||||
const parsed = smartjson.parse(json);
|
||||
expect(parsed.empty).toBeInstanceOf(Uint8Array);
|
||||
expect(parsed.empty.length).toEqual(0);
|
||||
});
|
||||
|
||||
tap.test('should parse and stringify JSONL', async () => {
|
||||
const items = [
|
||||
{ id: 1, name: 'a' },
|
||||
{ id: 2, name: 'b' }
|
||||
];
|
||||
const jsonl = smartjson.stringifyJsonL(items);
|
||||
const parsed = smartjson.parseJsonL(jsonl);
|
||||
expect(parsed).toEqual(items);
|
||||
});
|
||||
|
||||
tap.test('should deep-compare JSONL strings', async () => {
|
||||
const a = '{"id":2,"name":"b"}\n{"id":1,"name":"a"}';
|
||||
const b = '{"id":2,"name":"b"}\n{"id":1,"name":"a"}';
|
||||
expect(smartjson.deepEqualJsonLStrings(a, b)).toEqual(true);
|
||||
});
|
||||
|
||||
tap.test('should respect simpleOrderArray comparator', async () => {
|
||||
const obj = { c: 3, a: 1, b: 2 };
|
||||
const ordered = smartjson.stringify(obj, ['b', 'a']);
|
||||
// ensure keys b, a come before c
|
||||
expect(ordered.indexOf('"b"')).toBeLessThan(ordered.indexOf('"a"'));
|
||||
expect(ordered.indexOf('"a"')).toBeLessThan(ordered.indexOf('"c"'));
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
Reference in New Issue
Block a user