File: reset.test

package info (click to toggle)
tk-html3 3.0~fossil20110109-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,644 kB
  • ctags: 5,882
  • sloc: ansic: 48,994; tcl: 26,030; sh: 1,190; yacc: 161; makefile: 24
file content (81 lines) | stat: -rw-r--r-- 1,863 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81


# This test script tests that Tkhtml3 behaves well when the 
# [$widget reset] method is called from with a node-handler
# callback. This happens in Hv3 when a <meta> node specifies
# a charset for the document.
#

proc sourcefile {file} {
  set fname [file join [file dirname [info script]] $file] 
  uplevel "#0" [list source $fname]
}
sourcefile common.tcl

set ::DocumentOne {
  <html>
    <head>
      <meta id=1>
      <script>script1 contents</script>
      <meta id=2>
      <script>script2 contents</script>
    </head>
    <body>
      <div>123</div>
    </body>
  </html>
}

set ::DocumentTwo {
  <html>
    <body>
      <div>456</div>
    </body>
}

html .h
.h handler node meta meta_node_handler

proc meta_node_handler {n} {
  if {[$n attr id] eq $::iReset} {
    .h reset
    if {$::doParse == 1} {
      .h parse -final $::DocumentTwo
    } elseif {$::doParse == 2} {
      set ::doParse 1
      .h parse -final $::DocumentOne
    }
  }
}

proc get_div_contents {} {
  set n [.h search div -index 0]
  if {$n eq ""} {
    set res ""
  } else {
    set res [[lindex [$n children] 0] text]
  }
  set res
}

# Run some tests with a few different values for global variables
# ::doParse and ::iReset (used by proc [meta_node_handler] above).
#
foreach {test_number ::iReset ::doParse result} [list \
         1           n/a      n/a       123           \
         2           1        0         ""            \
         3           1        1         456           \
         4           1        2         456           \
         5           2        0         ""            \
         6           2        1         456           \
         7           1        2         456           \
] {
  tcltest::test reset-1.$test_number {} -body {
    .h reset
    .h parse -final $::DocumentOne
    get_div_contents
  } -result $result
}

finish_test