aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/net/html/dom_test.v
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/net/html/dom_test.v
downloadcli-tools-windows-master.tar.gz
cli-tools-windows-master.tar.bz2
cli-tools-windows-master.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/vlib/net/html/dom_test.v')
-rw-r--r--v_windows/v/vlib/net/html/dom_test.v56
1 files changed, 56 insertions, 0 deletions
diff --git a/v_windows/v/vlib/net/html/dom_test.v b/v_windows/v/vlib/net/html/dom_test.v
new file mode 100644
index 0000000..d4fd292
--- /dev/null
+++ b/v_windows/v/vlib/net/html/dom_test.v
@@ -0,0 +1,56 @@
+module html
+
+import strings
+
+fn generate_temp_html() string {
+ mut temp_html := strings.new_builder(200)
+ temp_html.write_string('<!doctype html><html><head><title>Giant String</title></head><body>')
+ for counter := 0; counter < 4; counter++ {
+ temp_html.write_string("<div id='name_$counter' ")
+ temp_html.write_string("class='several-$counter'>Look at $counter</div>")
+ }
+ temp_html.write_string('</body></html>')
+ return temp_html.str()
+}
+
+fn test_search_by_tag_type() {
+ dom := parse(generate_temp_html())
+ assert dom.get_tag('div').len == 4
+ assert dom.get_tag('head').len == 1
+ assert dom.get_tag('body').len == 1
+}
+
+fn test_search_by_attribute_value() {
+ mut dom := parse(generate_temp_html())
+ // println(temp_html)
+ print('Amount ')
+ println(dom.get_tag_by_attribute_value('id', 'name_0'))
+ assert dom.get_tag_by_attribute_value('id', 'name_0').len == 1
+}
+
+fn test_access_parent() {
+ mut dom := parse(generate_temp_html())
+ div_tags := dom.get_tag('div')
+ parent := div_tags[0].parent
+ assert parent != 0
+ for div_tag in div_tags {
+ assert div_tag.parent == parent
+ }
+}
+
+fn test_search_by_attributes() {
+ dom := parse(generate_temp_html())
+ assert dom.get_tag_by_attribute('id').len == 4
+}
+
+fn test_tags_used() {
+ dom := parse(generate_temp_html())
+ assert dom.get_tags().len == 9
+}
+
+fn test_access_tag_fields() {
+ dom := parse(generate_temp_html())
+ id_tags := dom.get_tag_by_attribute('id')
+ assert id_tags[0].name == 'div'
+ assert id_tags[1].attributes['class'] == 'several-1'
+}