1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-09 15:12:26 +08:00

feat:add map to markdown conversion in map.go (#336)

* feat(file): add map to markdown conversion in map.go

* feat(file): add map to markdown conversion in map.go
This commit is contained in:
wangxc
2025-10-29 21:07:18 +08:00
committed by GitHub
parent 5b3a59e785
commit fc624195c7
3 changed files with 257 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package maputil
import (
"fmt"
"math/cmplx"
"sort"
"strconv"
@@ -926,3 +927,46 @@ func TestFindValuesBy(t *testing.T) {
assert.Equal(tt.expected, result)
}
}
func TestToMarkdownTable(t *testing.T) {
// 测试空数据
emptyResult := ToMarkdownTable([]map[string]interface{}{}, nil, nil)
expectedEmpty := "| |\n|---|\n"
if emptyResult != expectedEmpty {
t.Errorf("Expected empty table, got: %s", emptyResult)
}
// 测试基本数据
data := []map[string]interface{}{
{"name": "Alice", "age": 25, "salary": 50000},
{"name": "Bob", "age": 30, "salary": 60000},
}
result := ToMarkdownTable(data, nil, nil)
fmt.Printf("%s", result)
// 验证结果包含预期的表头和数据行
}
// 测试自定义列顺序
func TestToMarkdownTableWithColumnOrder(t *testing.T) {
data := []map[string]interface{}{
{"name": "Alice", "age": 25, "salary": 50000},
}
columnOrder := []string{"salary", "name", "age"}
result := ToMarkdownTable(data, nil, columnOrder)
fmt.Printf("%s", result)
// 验证列顺序是否正确
}
// 测试自定义表头
func TestToMarkdownTableWithHeaderMap(t *testing.T) {
data := []map[string]interface{}{
{"name": "Alice", "age": 25},
}
headerMap := map[string]string{
"name": "姓名",
"age": "年龄",
}
result := ToMarkdownTable(data, headerMap, nil)
fmt.Printf("%s", result)
// 验证中文表头是否正确显示
}