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')