/[jsFind]/trunk/html/test.html
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/html/test.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (show annotations)
Thu Oct 7 17:30:03 2004 UTC (19 years, 7 months ago) by dpavlin
File MIME type: text/html
File size: 4654 byte(s)
create elements in test.html (instead of updating innerHTML), 10homer.t will
now split document in lines instead of paragraphs.

1 <!DOCTYPE html PUBLIC
2 "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 <head>
6 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
7 <title>jsFind Test page</title>
8 <script src="js/search.js" type="text/javascript"></script>
9 <script src="test_data.js" type="text/javascript"></script>
10 <script type="text/javascript">
11
12 /*
13 var test_data = {
14 'by': {
15 '33': 1,
16 '28': 1,
17 '7': 2,
18 '91': 1,
19 '78': 2,
20 '8': 1,
21 '1': 2,
22 '16': 1,
23 '23': 1,
24 '100': 1,
25 '65': 1
26 },
27 'voice.': {
28 '80': 1
29 }
30 };
31 */
32
33 function get_div(name) {
34 var div = document.getElementById(name);
35 if (! div) alert("can't find div "+name);
36 return div;
37 }
38
39 var good_div = null;
40 var bad_div = null;
41 var test_div = null;
42
43
44 var results_output = '';
45 var debug_output = '';
46 var test_ok = 0;
47 var test_error = 0;
48 var test_failed = false;
49
50 var word_nr = -1; // first emement is word_nr++
51 var words = Array();
52
53 function msg_debug(msg) {
54 debug_output += msg+"<br/>\n";
55 test_div.appendChild(document.createTextNode("DEBUG: "+msg));
56 test_div.appendChild(document.createElement("br"));
57 return;
58 }
59
60 function msg_error(msg) {
61 var e = document.createElement("span");
62 // e.style.color = 'red';
63 e.appendChild(document.createTextNode(msg));
64 bad_div.appendChild(e);
65 bad_div.appendChild(document.createElement("br"));
66
67 test_div.appendChild(e);
68 test_div.appendChild(document.createElement("br"));
69
70 test_error++;
71 test_failed = true;
72 return true;
73 }
74
75 function msg_ok(msg) {
76 var e = document.createElement("span");
77 e.style.color = 'green';
78 e.appendChild(document.createTextNode(msg));
79 good_div.appendChild(e);
80 good_div.appendChild(document.createElement("br"));
81
82 test_div.appendChild(e);
83 test_div.appendChild(document.createElement("br"));
84
85 test_ok++;
86 return true;
87 }
88
89 function got_result(result) {
90 if (result.length < 0) {
91 msg_error("no results for word "+words[word_nr]);
92 }
93
94 var word = words[word_nr];
95 var len = 0;
96 for (var i in result) len++;
97 result.length = len;
98 for (var i in test_data[word]) len++;
99
100 if (result.length == len) {
101 msg_ok("found "+result.lengh+" results");
102 } else if ( result.length > len )
103 msg_error("too much results "+result.length+" > "+len)
104 else msg_error("too fiew results "+result.length+" < "+len);
105
106 for(var i=result.length-1; i>=0; i--) {
107 var test_hit = i+": '"+
108 result[i].title+"' link: "+
109 result[i].link+" frequency: "+
110 result[i].frequency;
111
112 if ( test_data[ words[word_nr] ][ result[i].link ] != result[i].frequency ) {
113 msg_error("error in frequency for word: '"+words[word_nr]+"' [hit "+i+"] "+test_data[ words[word_nr] ][ result[i].link ]+" != "+result[i].frequency);
114 msg_error("HIT "+test_hit);
115
116 results_output += test_hit;
117 } else {
118 msg_debug("OK: "+words[word_nr]+" "+i+" "+result[i].frequency);
119 }
120
121 }
122
123 // try next search
124 if (word_nr < words.length) do_search();
125
126 return true;
127 }
128
129 function do_test() {
130
131 good_div = get_div('good');
132 bad_div = get_div('bad');
133 test_div = get_div('debug');
134
135 var test_words = 0;
136
137 for (word in test_data) {
138 words[test_words] = word;
139 msg_debug("word "+test_words+" is "+words[test_words]);
140 test_words++;
141 }
142
143 do_search();
144 }
145
146
147 function do_search() {
148
149 word_nr++;
150
151 if (word_nr < words.length && words[word_nr] != 'undefined') {
152
153 results_output = '';
154 debug_output = '';
155 test_failed = false;
156
157 msg_debug("search for "+words[word_nr]+" ["+word_nr+"]");
158
159 results = null;
160 doSearch('homer', words[word_nr], got_result);
161
162
163 if (1 || test_failed) {
164 if (test_div) test_div.innerHTML += debug_output + results_output;
165 } else {
166 if (test_div) test_div.innerHTML += debug_output;
167 }
168
169 } else {
170 msg_debug("tested "+word_nr+" words, "+test_ok+" test passed, "+test_error+" test failed.");
171 }
172 }
173
174 </script>
175 </head>
176
177 <body onLoad="do_test();">
178
179 <div style="color: blue;">
180 This is test html for jsFind -- it might take a long time on slower
181 computers and/or browsers, so please be patient!
182 </div>
183
184 <div id="good" style="border: 1px solid green; width: 30%; float: left;">
185 </div>
186
187 <div id="bad" style="border: 1px solid red; width: 30%; float: right;">
188 </div>
189
190 <div id="debug" style="color: gray;">
191 </div>
192
193 </body>
194 </html>

  ViewVC Help
Powered by ViewVC 1.1.26