Debian Codegraph @

rhino/testsrc/tests/e4x/XML/13.4.4.26.js

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 gTestfile = '13.4.4.26.js';
8
9 START("13.4.4.26 - XML normalize()");
10
11 TEST(1, true, XML.prototype.hasOwnProperty("normalize"));
12
13 XML.ignoreWhitespace = false;
14 XML.prettyPrinting = false;
15
16 var x = <alpha> <bravo> one </bravo> </alpha>;
17
18 TEST_XML(2, "<alpha> <bravo> one </bravo> </alpha>", x);
19 x.normalize();
20 TEST_XML(3, "<alpha> <bravo> one </bravo> </alpha>", x);
21
22
23 // First, test text node coalescing
24
25 delete x.bravo[0];
26
27 TEST_XML(4, "<alpha> </alpha>", x);
28 TEST(5, 2, x.children().length());
29
30 x.normalize();
31
32 TEST_XML(6, "<alpha> </alpha>", x);
33 TEST(7, 1, x.children().length());
34
35 // check that nodes are inserted in the right place after a normalization
36
37 x.appendChild(<bravo> fun </bravo>);
38
39 TEST_XML(8, "<alpha> <bravo> fun </bravo></alpha>", x);
40 TEST(9, 2, x.children().length());
41
42 // recursive nature
43
44 var y = <charlie> <delta/> </charlie>;
45
46 TEST(10, 3, y.children().length());
47
48 x.appendChild(y);
49 delete y.delta[0];
50
51 TEST(11, 2, y.children().length());
52
53 x.normalize();
54
55 TEST(12, 1, y.children().length());
56 TEST(13, 1, x.charlie.children().length());
57
58
59
60 // Second, test empty text node removal
61
62 x = <alpha><beta/></alpha>;
63
64 TEST_XML(14, "<alpha><beta/></alpha>", x);
65 TEST(15, 1, x.children().length());
66
67 x.appendChild(XML());
68
69 TEST_XML(16, "<alpha><beta/></alpha>", x);
70 TEST(17, 2, x.children().length());
71
72 x.normalize();
73
74 TEST_XML(18, "<alpha><beta/></alpha>", x);
75 TEST(19, 1, x.children().length());
76
77 x.appendChild(XML(" "));
78
79 TEST_XML(20, "<alpha><beta/> </alpha>", x);
80 TEST(21, 2, x.children().length());
81
82 x.normalize();
83
84 // normalize does not remove whitespace-only text nodes
85 TEST_XML(22, "<alpha><beta/> </alpha>", x);
86 TEST(23, 2, x.children().length());
87
88 y = <foo/>;
89 y.appendChild(XML());
90
91 TEST(24, 1, y.children().length());
92
93 x.appendChild(y);
94
95 // check recursive nature
96
97 x.normalize();
98
99 TEST(25, 0, y.children().length());
100
101 END();