vdoc: fix sorting of docnodes on other than linux, enable tests (#21253)

This commit is contained in:
Turiiya 2024-04-12 09:35:01 +02:00 committed by GitHub
parent 313c3bc49d
commit 739730b9d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 25 deletions

View File

@ -278,7 +278,6 @@ const skip_on_linux = [
]
const skip_on_non_linux = [
'do_not_remove',
'cmd/tools/vdoc/tests/vdoc_file_test.v', // order of output is not as expected
]
const skip_on_windows_msvc = [
'do_not_remove',

View File

@ -514,8 +514,7 @@ pub fn (mut d Doc) file_asts(mut file_asts []ast.File) ! {
}
if d.contents[name].kind != .none_ || node.kind == .none_ {
d.contents[name].children << node.children
d.contents[name].children.sort_by_name()
d.contents[name].children.sort_by_kind()
d.contents[name].children.arrange()
}
}
}

View File

@ -13,23 +13,30 @@ pub fn (nodes []DocNode) find(symname string) !DocNode {
return error('symbol not found')
}
// sort_by_name sorts the array based on the symbol names.
pub fn (mut nodes []DocNode) sort_by_name() {
if doc.should_sort {
nodes.sort_with_compare(compare_nodes_by_name)
// arrange sorts the DocNodes based on their symbols and names.
pub fn (mut nodes []DocNode) arrange() {
if !doc.should_sort {
return
}
mut kinds := []SymbolKind{}
for v in nodes {
if v.kind !in kinds {
kinds << v.kind
}
}
kinds.sort_with_compare(compare_sym_kinds)
mut res := []DocNode{}
for k in kinds {
mut kind_nodes := nodes.filter(it.kind == k)
kind_nodes.sort(a.name < b.name)
res << kind_nodes
}
nodes = res.clone()
}
// sort_by_kind sorts the array based on the symbol kind.
pub fn (mut nodes []DocNode) sort_by_kind() {
if doc.should_sort {
nodes.sort_with_compare(compare_nodes_by_kind)
}
}
fn compare_nodes_by_kind(a &DocNode, b &DocNode) int {
ak := int(a.kind)
bk := int(b.kind)
fn compare_sym_kinds(a &SymbolKind, b &SymbolKind) int {
ak := int(*a)
bk := int(*b)
return match true {
ak < bk { -1 }
ak > bk { 1 }
@ -37,17 +44,10 @@ fn compare_nodes_by_kind(a &DocNode, b &DocNode) int {
}
}
fn compare_nodes_by_name(a &DocNode, b &DocNode) int {
al := a.name.to_lower()
bl := b.name.to_lower()
return compare_strings(al, bl)
}
// arr() converts the map into an array of `DocNode`.
pub fn (cnts map[string]DocNode) arr() []DocNode {
mut contents := cnts.values()
contents.sort_by_name()
contents.sort_by_kind()
contents.arrange()
return contents
}