From bb1f61030e197fa22c716fd91917572c6172896e Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Fri, 31 Oct 2025 12:40:15 +0100 Subject: [PATCH] test: add test for precision preservation of repeating decimals --- test/encode.test.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/encode.test.ts b/test/encode.test.ts index 9ffaedf..679f0db 100644 --- a/test/encode.test.ts +++ b/test/encode.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { encode } from '../src/index' +import { decode, encode } from '../src/index' describe('primitives', () => { it('encodes safe strings without quotes', () => { @@ -57,6 +57,14 @@ describe('primitives', () => { expect(encode(Number.MAX_SAFE_INTEGER)).toBe('9007199254740991') }) + it('preserves precision for repeating decimals', () => { + const value = 1 / 3 + const encodedValue = encode({ value }) + const decodedValue = decode(encodedValue) + expect((decodedValue as Record)?.value).toBe(value) // Round-trip fidelity + expect(encodedValue).toContain('0.3333333333333333') // Default JS precision + }) + it('encodes booleans', () => { expect(encode(true)).toBe('true') expect(encode(false)).toBe('false')