mirror of
https://github.com/vlang/v.git
synced 2025-08-03 17:57:59 -04:00
This commit is contained in:
parent
d9a2fb1630
commit
25f14d3bbb
@ -203,7 +203,8 @@ fn (mut g Gen) gen_str_for_option(typ ast.Type, styp string, str_fn_name string)
|
|||||||
g.auto_str_funcs.writeln('\tstring res;')
|
g.auto_str_funcs.writeln('\tstring res;')
|
||||||
g.auto_str_funcs.writeln('\tif (it.state == 0) {')
|
g.auto_str_funcs.writeln('\tif (it.state == 0) {')
|
||||||
deref := if typ.is_ptr() {
|
deref := if typ.is_ptr() {
|
||||||
'**(${sym.cname}**)&'
|
dot := if expects_ptr { '*'.repeat(typ.nr_muls()) } else { '*'.repeat(typ.nr_muls() + 1) }
|
||||||
|
'${dot}(${sym.cname}**)&'
|
||||||
} else if expects_ptr {
|
} else if expects_ptr {
|
||||||
'(${sym.cname}*)'
|
'(${sym.cname}*)'
|
||||||
} else {
|
} else {
|
||||||
|
19
vlib/v/tests/printing/print_option_ref_test.v
Normal file
19
vlib/v/tests/printing/print_option_ref_test.v
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import net.html
|
||||||
|
|
||||||
|
fn test_nil() {
|
||||||
|
mut doc := html.parse('<body><div class="Box-footer"><div class="truncate">abc</div></div></body>')
|
||||||
|
footer := doc.get_tags_by_class_name('Box-footer')[0]
|
||||||
|
hrefs := footer.get_tag_by_class_name('Truncate')
|
||||||
|
println(hrefs)
|
||||||
|
res := '${hrefs}'
|
||||||
|
assert res == '&Option(&nil)'
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_non_nil() {
|
||||||
|
mut doc := html.parse('<body><div class="Box-footer"><div class="Truncate">abc</div></div></body>')
|
||||||
|
footer := doc.get_tags_by_class_name('Box-footer')[0]
|
||||||
|
hrefs := footer.get_tag_by_class_name('Truncate')
|
||||||
|
println(hrefs)
|
||||||
|
res := '${hrefs}'
|
||||||
|
assert res == '&Option(<div class="Truncate" >abc</div>)'
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user