mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
net.html: polish module, update docs (#7193)
This commit is contained in:
parent
5fa1e403ec
commit
b952bf2e6b
9 changed files with 302 additions and 446 deletions
|
@ -1,10 +1,10 @@
|
|||
module html
|
||||
|
||||
//import net.http
|
||||
import strings
|
||||
|
||||
fn test_split_parse() {
|
||||
mut parser := Parser{}
|
||||
parser.initialize_all()
|
||||
parser.init()
|
||||
parser.split_parse('<!doctype htm')
|
||||
parser.split_parse('l public')
|
||||
parser.split_parse('><html><he')
|
||||
|
@ -16,37 +16,26 @@ fn test_split_parse() {
|
|||
parser.split_parse('Nice Test!</h3>')
|
||||
parser.split_parse('</bo\n\n\ndy></html>')
|
||||
parser.finalize()
|
||||
assert parser.get_tags().len == 11
|
||||
assert parser.get_tags()[3].get_content() == ' Hum... A Tit\nle'
|
||||
assert parser.tags.len == 11
|
||||
assert parser.tags[3].content == ' Hum... A Tit\nle'
|
||||
}
|
||||
|
||||
fn test_giant_string() {
|
||||
mut temp_html := '<!doctype html><html><head><title>Giant String</title></head><body>'
|
||||
for counter := 0; counter < 2000; counter++ {
|
||||
temp_html += "<div id='name_$counter' class='several-$counter'>Look at $counter</div>"
|
||||
}
|
||||
temp_html += '</body></html>'
|
||||
mut temp_html := strings.new_builder(200)
|
||||
mut parser := Parser{}
|
||||
parser.parse_html(temp_html, false)
|
||||
assert parser.get_tags().len == 4009
|
||||
temp_html.write('<!doctype html><html><head><title>Giant String</title></head><body>')
|
||||
for counter := 0; counter < 2000; counter++ {
|
||||
temp_html.write("<div id='name_$counter' class='several-$counter'>Look at $counter</div>")
|
||||
}
|
||||
temp_html.write('</body></html>')
|
||||
parser.parse_html(temp_html.str())
|
||||
assert parser.tags.len == 4009
|
||||
}
|
||||
|
||||
fn test_script_tag() {
|
||||
temp_html := "<html><body><script>\nvar googletag = googletag || {};\n
|
||||
googletag.cmd = googletag.cmd || [];if(3 > 5) {console.log('Birl');}\n</script></body></html>"
|
||||
mut parser := Parser{}
|
||||
parser.parse_html(temp_html, false)
|
||||
assert parser.get_tags()[2].get_content().len == 101
|
||||
script_content := "\nvar googletag = googletag || {};\ngoogletag.cmd = googletag.cmd || [];if(3 > 5) {console.log(\'Birl\');}\n"
|
||||
temp_html := '<html><body><script>$script_content</script></body></html>'
|
||||
parser.parse_html(temp_html)
|
||||
assert parser.tags[2].content.len == script_content.replace('\n', '').len
|
||||
}
|
||||
|
||||
/*fn test_download_source() {
|
||||
println('Fetching github data in pastebin')
|
||||
resp := http.get('https://pastebin.com/raw/5snUQgqN') or {
|
||||
println('failed to fetch data from the server')
|
||||
return
|
||||
}
|
||||
println('Finalized fetching, start parsing')
|
||||
mut parser := Parser{}
|
||||
parser.parse_html(resp.text, false)
|
||||
assert parser.get_tags().len == 2244
|
||||
}*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue