v0.3.5: Bug修复+性能优化+状态栏文档统计
Bug修复: - BUG-01: Sidebar norm函数正则修复(单反斜杠匹配), Windows路径规范化恢复 - BUG-02: 3处result.content truthy检查改为content !== undefined, 空文件可打开 - BUG-03: TAB_SWITCHED路径校验顺序修复, activeFilePath不在校验前写入 优化: - OPT-01: Sidebar handleFileClick添加loading状态, 打开文件有视觉反馈 新功能: - FEAT-01: 状态栏添加行数/单词数/字符数统计 - useDocStats hook + computeDocStats 纯函数 - StatusBar右侧显示 行/词/字符 统计信息 - 12个单元测试覆盖空值/空白/ASCII/UTF-8/Markdown等场景 验证: TS 0错误, ESLint 0错误(1个预存警告), 90/90测试通过
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { computeDocStats } from '../useDocStats'
|
||||
|
||||
describe('computeDocStats', () => {
|
||||
it('should return zeros for undefined content', () => {
|
||||
expect(computeDocStats(undefined)).toEqual({ words: 0, chars: 0, charsNoSpace: 0, lines: 0 })
|
||||
})
|
||||
|
||||
it('should return zeros for null content', () => {
|
||||
expect(computeDocStats(null)).toEqual({ words: 0, chars: 0, charsNoSpace: 0, lines: 0 })
|
||||
})
|
||||
|
||||
it('should return zeros for empty string', () => {
|
||||
expect(computeDocStats('')).toEqual({ words: 0, chars: 0, charsNoSpace: 0, lines: 0 })
|
||||
})
|
||||
|
||||
it('should count single word', () => {
|
||||
const result = computeDocStats('hello')
|
||||
expect(result.words).toBe(1)
|
||||
expect(result.chars).toBe(5)
|
||||
expect(result.charsNoSpace).toBe(5)
|
||||
expect(result.lines).toBe(1)
|
||||
})
|
||||
|
||||
it('should count multiple words', () => {
|
||||
const result = computeDocStats('hello world')
|
||||
expect(result.words).toBe(2)
|
||||
expect(result.chars).toBe(11) // 'hello world' = 11 chars
|
||||
expect(result.charsNoSpace).toBe(10) // without the space
|
||||
})
|
||||
|
||||
it('should count characters without spaces', () => {
|
||||
const result = computeDocStats('a b c')
|
||||
expect(result.chars).toBe(5)
|
||||
expect(result.charsNoSpace).toBe(3)
|
||||
})
|
||||
|
||||
it('should count lines', () => {
|
||||
const result = computeDocStats('line1\nline2\nline3')
|
||||
expect(result.lines).toBe(3)
|
||||
expect(result.words).toBe(3)
|
||||
})
|
||||
|
||||
it('should handle Windows line endings', () => {
|
||||
const result = computeDocStats('line1\r\nline2\r\nline3')
|
||||
expect(result.lines).toBe(3)
|
||||
})
|
||||
|
||||
it('should handle trailing newline', () => {
|
||||
const result = computeDocStats('hello\n')
|
||||
expect(result.lines).toBe(2)
|
||||
expect(result.words).toBe(1)
|
||||
})
|
||||
|
||||
it('should count markdown content correctly', () => {
|
||||
const md = '# Title\n\nThis is a **paragraph** with some *text*.\n\n- List item 1\n- List item 2\n'
|
||||
const result = computeDocStats(md)
|
||||
expect(result.words).toBe(17)
|
||||
expect(result.lines).toBe(7)
|
||||
expect(result.chars).toBe(md.length)
|
||||
})
|
||||
|
||||
it('should handle whitespace-only content', () => {
|
||||
const result = computeDocStats(' \n \n ')
|
||||
expect(result.words).toBe(0)
|
||||
expect(result.chars).toBe(9)
|
||||
expect(result.charsNoSpace).toBe(0)
|
||||
expect(result.lines).toBe(3)
|
||||
})
|
||||
|
||||
it('should handle content with non-ASCII characters', () => {
|
||||
const result = computeDocStats('中文测试 日本語 한국어')
|
||||
expect(result.words).toBe(3)
|
||||
expect(result.chars).toBe(12)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user