mirror of
https://github.com/vlang/v.git
synced 2025-09-14 09:56:16 -04:00
vdoc: add attributes to enums and structs (#20957)
This commit is contained in:
parent
293dd36f92
commit
ddf1ae9115
@ -242,6 +242,14 @@ pub fn (mut d Doc) stmt(mut stmt ast.Stmt, filename string) !DocNode {
|
||||
}
|
||||
}
|
||||
}
|
||||
for sa in stmt.attrs {
|
||||
node.attrs[sa.name] = if sa.has_at {
|
||||
'@[${sa.str()}]'
|
||||
} else {
|
||||
'[${sa.str()}]'
|
||||
}
|
||||
node.tags << node.attrs[sa.name]
|
||||
}
|
||||
}
|
||||
ast.InterfaceDecl {
|
||||
node.kind = .interface_
|
||||
@ -264,6 +272,14 @@ pub fn (mut d Doc) stmt(mut stmt ast.Stmt, filename string) !DocNode {
|
||||
}
|
||||
}
|
||||
}
|
||||
for sa in stmt.attrs {
|
||||
node.attrs[sa.name] = if sa.has_at {
|
||||
'@[${sa.str()}]'
|
||||
} else {
|
||||
'[${sa.str()}]'
|
||||
}
|
||||
node.tags << node.attrs[sa.name]
|
||||
}
|
||||
}
|
||||
ast.TypeDecl {
|
||||
node.kind = .typedef
|
||||
|
@ -16,3 +16,47 @@ fn test_generate_from_mod() {
|
||||
assert nested_mod_doc.contents.len == 3
|
||||
assert nested_mod_doc.contents['ChunkScanner'].children.len == 3
|
||||
}
|
||||
|
||||
fn test_tags_with_flag_struct_attribute() {
|
||||
mod_name := 'gg'
|
||||
mod_doc := doc.generate_from_mod(mod_name, false, true) or {
|
||||
eprintln(err)
|
||||
assert false
|
||||
doc.Doc{}
|
||||
}
|
||||
assert mod_doc.head.name == mod_name
|
||||
|
||||
mouse_buttons := mod_doc.contents['MouseButtons']!
|
||||
assert mouse_buttons.content == '@[flag]
|
||||
pub enum MouseButtons {
|
||||
left
|
||||
right
|
||||
middle
|
||||
}'
|
||||
assert mouse_buttons.attrs == {
|
||||
'flag': '@[flag]'
|
||||
}
|
||||
assert mouse_buttons.tags == ['@[flag]']
|
||||
|
||||
end_options := mod_doc.contents['EndOptions']
|
||||
assert end_options.content == '@[params]
|
||||
pub struct EndOptions {
|
||||
how EndEnum
|
||||
}'
|
||||
assert end_options.attrs == {
|
||||
'params': '@[params]'
|
||||
}
|
||||
assert end_options.tags == ['@[params]']
|
||||
|
||||
pipeline_container := mod_doc.contents['PipelineContainer']
|
||||
assert pipeline_container.content == '@[heap]
|
||||
pub struct PipelineContainer {
|
||||
pub mut:
|
||||
alpha sgl.Pipeline
|
||||
add sgl.Pipeline
|
||||
}'
|
||||
assert pipeline_container.attrs == {
|
||||
'heap': '@[heap]'
|
||||
}
|
||||
assert pipeline_container.tags == ['@[heap]']
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user