File: tree1.bt

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 (166 lines) | stat: -rw-r--r-- 5,146 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

#----------------------------------------------------------------------
# A "warm-body" test to check that the infrastructure is working.
# Count the anchors in a document.
#
do_browser_test warmbody.1 -html {
  <BODY>
    <A name="one">One</A>
    <A id="two">Two</A>          <!-- Not an anchor (no "name" attribute) -->
    <A name="three">Three</A>
} -javascript {
  return document.anchors.length
}
#----------------------------------------------------------------------

proc body_tree_test {name doc} {

  # Uses:
  #
  #     Node.childNodes
  #     Node.nodeType
  #     Document.getElementsByTagName()
  #
  #     NodeList.length
  #     NodeList.item()
  #
  set body_tree_function {
    <SCRIPT>

      function elem_to_string (elem) {
        var res = "<" + elem.tagName + ">"
        for (var ii = 0; ii < elem.childNodes.length; ii++) {
          var node = elem.childNodes.item(ii)
          if (node.nodeType == Node.ELEMENT_NODE) {
            res += elem_to_string(node)
          }
        }
        res += "</" + elem.tagName + ">"
        return res
      }

      function body_tree () {
        body = document.getElementsByTagName("BODY").item(0)
        return elem_to_string(body)
      }

      function node_to_string (N) {
        /*
         * Known incompatibility between Hv3 and firefox: Hv3 chops <SCRIPT>
         * tags out of the tree completely, firefox leaves them in (but
         * chops out their contents). Not sure if this is ever significant
         * or not...
         */
        if (N.nodeType == Node.ELEMENT_NODE && N.nodeName == "SCRIPT") {
          return ""
        }

        /*
         * Another known incompatibility: Hv3 tends to add white-space nodes
         * in a few places where fire-fox does not. This is probably more
         * serious than the <SCRIPT> problem above, but still not too
         * much of a concern in the short term. Ignore any text-node
         * that consists entirely of white-space.
         */
        if (N.nodeType == Node.TEXT_NODE && !/[^\t\n\r ]/.test(N.nodeValue)) {
          return ""
        }

        var res = "<" + N.nodeType + " " + N.nodeName + ">"

        for (var ii = 0; ii < N.childNodes.length; ii++) {
          var N2 = N.childNodes.item(ii)
          res += node_to_string(N2)
        }

        res += "</>"
        return res
      }

      function dom_tree () {
        return node_to_string(document)
      }

    </SCRIPT>
  }

  browsertest $name utf-8 [string trim "
    $body_tree_function
    $doc
    <SCRIPT>
      function browsertest () { return dom_tree() }
    </SCRIPT>
  "]

#  ::browsertest::do_test $name -timeout 10000000 -html [subst {
#    $body_tree_function
#    $doc
#  }] -javascript {
#    // return body_tree()
#    return dom_tree()
#  } -browsers {Hv3 Firefox}
}


#----------------------------------------------------------------------
# The following test cases - tables.X - examine the document trees
# created when incorrectly (or partially) specified tables are parsed.
#
# From the HTML 4.0.1 DTD:
#
# <!ELEMENT TABLE    - - (CAPTION?, (COL*|COLGROUP*), THEAD?, TFOOT?, TBODY+)> 
# <!ELEMENT CAPTION  - - (%inline;)*  -- table caption --> 
# <!ELEMENT THEAD    - O (TR)+        -- table header --> 
# <!ELEMENT TFOOT    - O (TR)+        -- table footer --> 
# <!ELEMENT TBODY    O O (TR)+        -- table body --> 
# <!ELEMENT COLGROUP - O (COL)*       -- table column group --> 
# <!ELEMENT COL      - O EMPTY        -- table column --> 
# <!ELEMENT TR       - O (TH|TD)+     -- table row --> 
# <!ELEMENT (TH|TD)  - O (%flow;)*    -- table header cell, table data cell-->
#
# In other words, all table sub-trees should look like:
#
# <TABLE>
#     <CAPTION>...</CAPTION>)
#     <COLGROUP>...</COLGROUP>   (etc.)
#     <THEAD>
#         (<TR> <TD|TH>*)*
#     <TFOOT>
#         (<TR> <TD|TH>*)*
#     <TBODY>
#         (<TR> <TD|TH>*)*
#
# The rules for how tag-soup is converted to this structure are 
# specified as part of:
#

body_tree_test tables.1 { <BODY> <TBODY><TR><TD><DIV> }
body_tree_test tables.2 { <BODY> <TABLE><TBODY><TR><TD><DIV> }

body_tree_test tables.3 { <BODY> <TABLE><DIV><SPAN></SPAN><TD> }
body_tree_test tables.4 { <BODY> <TABLE> <DIV> <DIV> <TR> <SPAN> }

body_tree_test tables.5 { <BODY> <TABLE><TD> }
body_tree_test tables.6 { <BODY> <TABLE><TR> }

body_tree_test tables.7 { <BODY> <TABLE><DIV><TR></DIV> }
body_tree_test tables.8 { <BODY> <TABLE><DIV><TD></DIV> }
body_tree_test tables.9 { <BODY> <TABLE><DIV><SPAN></DIV> }

body_tree_test tables.10 { <BODY> <TD><SPAN> }
body_tree_test tables.11 { <BODY> <TR><SPAN> }
body_tree_test tables.12 { <BODY> <TR><TD><SPAN> }
body_tree_test tables.13 { <BODY> <TBODY><TR><TD><SPAN> }

body_tree_test tables.14 { <BODY> <TABLE><DIV><DIV><SPAN></DIV><SPAN> }

# This structure is found in the mail.yahoo.com application.
#
body_tree_test tables.15 { <TABLE><FORM><TR><TR></TABLE> }
body_tree_test tables.16 { <TABLE><TBODY><FORM><TR><TR></TABLE> }

body_tree_test tree.1 { <BODY> <DIV> }
body_tree_test attr.1 { <BODY> <DIV id="two"> hello }

#----------------------------------------------------------------------