1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
\r
2 <html xmlns="http://www.w3.org/1999/xhtml">
\r
4 <title>CKEDITOR.dom.text</title>
\r
5 <link rel="stylesheet" type="text/css" href="../../test.css" />
\r
6 <script type="text/javascript" src="../../../ckeditor.js"></script>
\r
7 <script type="text/javascript" src="../../test.js"></script>
\r
8 <script type="text/javascript">
\r
12 CKEDITOR.test.addTestCase( tc = (function()
\r
14 // Local reference to the "assert" object.
\r
15 var assert = CKEDITOR.test.assert;
\r
19 test_substring1 : function()
\r
21 var text = new CKEDITOR.dom.text( '0123456789' );
\r
23 assert.areSame( '123', text.substring( 1, 4 ) );
\r
26 test_substring2 : function()
\r
28 var text = new CKEDITOR.dom.text( '0123456789' );
\r
30 assert.areSame( '56789', text.substring( 5 ) );
\r
33 test_substring3 : function()
\r
35 var text = new CKEDITOR.dom.text( '0123456789' );
\r
37 assert.areSame( '', text.substring( 1,1 ) );
\r
40 test_substring4 : function()
\r
42 var text = new CKEDITOR.dom.text( '0123456789' );
\r
44 assert.areSame( '012', text.substring( -10,3 ) );
\r
47 test_substring5 : function()
\r
49 var text = new CKEDITOR.dom.text( '0123456789' );
\r
51 assert.areSame( '89', text.substring( 8,100 ) );
\r
54 test_substring6 : function()
\r
56 var text = new CKEDITOR.dom.text( '0123456789' );
\r
58 assert.areSame( '234', text.substring( 5,2 ) );
\r
61 test_split1 : function()
\r
63 var div = CKEDITOR.document.getById( 'playground' );
\r
64 div.setHtml( '01234' );
\r
66 var text = div.getFirst(),
\r
67 next = text.split( 3 );
\r
69 assert.areSame( '012', text.getText(), 'text.getText() is wrong' );
\r
70 assert.areSame( '34', next.getText(), 'next.getText() is wrong' );
\r
72 assert.areSame( div.$, next.$.parentNode, 'parentNode is wrong' );
\r
73 assert.areSame( text.$, next.$.previousSibling, 'sibling is wrong' );
\r
76 test_split2 : function()
\r
78 var div = CKEDITOR.document.getById( 'playground' );
\r
79 div.setHtml( '01234' );
\r
81 var text = div.getFirst(),
\r
82 next = text.split( 5 );
\r
84 assert.areSame( '01234', text.getText(), 'text.getText() is wrong' );
\r
85 assert.areSame( '', next.getText(), 'next.getText() is wrong' );
\r
87 assert.areSame( div.$, next.$.parentNode, 'parentNode is wrong' );
\r
88 assert.areSame( text.$, next.$.previousSibling, 'sibling is wrong' );
\r
91 test_split3 : function()
\r
93 var div = CKEDITOR.document.getById( 'playground' );
\r
94 div.setHtml( '01234' );
\r
96 var text = div.getFirst(),
\r
97 next = text.split( 0 );
\r
99 assert.areSame( '', text.getText(), 'text.getText() is wrong' );
\r
100 assert.areSame( '01234', next.getText(), 'next.getText() is wrong' );
\r
102 assert.areSame( div.$, next.$.parentNode, 'parentNode is wrong' );
\r
103 assert.areSame( text.$, next.$.previousSibling, 'sibling is wrong' );
\r
106 test_split_3436 : function()
\r
108 var parent = CKEDITOR.document.getById( 'playground2' );
\r
109 parent.setHtml( 'A B <b>C </b>D E' );
\r
110 parent.getFirst().split( 2 ); // Right before "B"
\r
111 parent.getChildren().getItem( 3 ).split( 2 ); // Right before "E"
\r
112 assert.areSame( 5, parent.getChildren().count(), 'Child nodes num doesn\'t match after split' );
\r
115 name : document.title
\r
119 //window.onload = tc.test_split_3436;
\r
125 <p id="playground"></p>
\r
126 <p id="playground2"></p>
\r