mirror of
https://github.com/voson-wang/toon.git
synced 2026-01-29 15:24:10 +08:00
test: add test for precision preservation of repeating decimals
This commit is contained in:
@@ -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<string, unknown>)?.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')
|
||||
|
||||
Reference in New Issue
Block a user