refactor(tui): 重构 UI 设计
- 将 UI 组件分解为更小的模块,提高可维护性 - 优化了列表渲染和路径输入逻辑 - 改进了帮助界面的显示方式 - 调整了 UI 样式,去除了冗余代码
This commit is contained in:
57
node/utils_test.go
Normal file
57
node/utils_test.go
Normal file
@ -0,0 +1,57 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// 测试 BytesToHumanReadable 函数
|
||||
func TestBytesToHumanReadable(t *testing.T) {
|
||||
tests := []struct {
|
||||
num float64
|
||||
suffix string
|
||||
want string
|
||||
}{
|
||||
{1024, "B", "1.0 KiB"},
|
||||
{1024 * 1024, "B", "1.0 MiB"},
|
||||
{1024 * 1024 * 1024, "B", "1.0 GiB"},
|
||||
{1024 * 1024 * 1024 * 1024, "B", "1.0 TiB"},
|
||||
{1024 * 1024 * 1024 * 1024 * 1024, "B", "1.0 PiB"},
|
||||
{1024 * 1024 * 1024 * 1024 * 1024 * 1024, "B", "1.0 EiB"},
|
||||
{1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, "B", "1.0 ZiB"},
|
||||
{1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, "B", "1.0 YiB"},
|
||||
{512, "B", "512.0 B"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("%f_%s", tt.num, tt.suffix), func(t *testing.T) {
|
||||
got := BytesToHumanReadable(tt.num, tt.suffix)
|
||||
if got != tt.want {
|
||||
t.Errorf("BytesToHumanReadable(%f, %s) = %s; want %s", tt.num, tt.suffix, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 测试 FormatSize 函数
|
||||
func TestFormatSize(t *testing.T) {
|
||||
tests := []struct {
|
||||
size int64
|
||||
want string
|
||||
}{
|
||||
{1024, " 1.0 KiB"},
|
||||
{1024 * 1024, " 1.0 MiB"},
|
||||
{1024 * 1024 * 1024, " 1.0 GiB"},
|
||||
{1024 * 1024 * 1024 * 1024, " 1.0 TiB"},
|
||||
{512, " 512.0 B"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(fmt.Sprintf("%d", tt.size), func(t *testing.T) {
|
||||
got := FormatSize(tt.size)
|
||||
if got != tt.want {
|
||||
t.Errorf("FormatSize(%d) = %s; want %s", tt.size, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user