11e1b3ca3b
CI / docker (push) Failing after 11s
包含 JSON 格式化、文本/JSON 对比、编解码、变量名转换、二维码、时间戳与颜色转换等工具;修复编辑器行号同步;补充 Vitest 单元测试、Docker 部署与 Gitea CI;完善开源文档;支持通过环境变量配置站点标题、备案号及第三方集成。 Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
973 B
JavaScript
31 lines
973 B
JavaScript
import { describe, it, expect } from 'vitest'
|
|
import { getByteLength, truncateToMaxBytes } from '../../src/utils/byteUtils.js'
|
|
|
|
describe('byteUtils', () => {
|
|
it('counts ASCII bytes', () => {
|
|
expect(getByteLength('hello')).toBe(5)
|
|
expect(getByteLength('')).toBe(0)
|
|
})
|
|
|
|
it('counts UTF-8 multibyte characters', () => {
|
|
expect(getByteLength('中')).toBe(3)
|
|
expect(getByteLength('hello世界')).toBe(11)
|
|
})
|
|
|
|
it('returns original string when within limit', () => {
|
|
expect(truncateToMaxBytes('hello', 10)).toBe('hello')
|
|
})
|
|
|
|
it('truncates by bytes without breaking multibyte chars', () => {
|
|
const text = 'a'.repeat(10) + '中'
|
|
const truncated = truncateToMaxBytes(text, 11)
|
|
expect(getByteLength(truncated)).toBeLessThanOrEqual(11)
|
|
expect(truncated).not.toContain('中')
|
|
})
|
|
|
|
it('handles exact byte boundary', () => {
|
|
expect(truncateToMaxBytes('ab', 2)).toBe('ab')
|
|
expect(truncateToMaxBytes('abc', 2)).toBe('ab')
|
|
})
|
|
})
|