Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js |
— | — | @@ -201,16 +201,24 @@ |
202 | 202 | new es.ParagraphModel( data[25], 1 ) |
203 | 203 | ]; |
204 | 204 | |
205 | | -test( 'es.DocumentModel', 23, function() { |
| 205 | +test( 'es.DocumentModel.getData', 1, function() { |
206 | 206 | var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
207 | 207 | |
208 | 208 | // Test 1 |
209 | 209 | deepEqual( documentModel.getData(), data, 'Flattening plain objects results in correct data' ); |
| 210 | +} ); |
210 | 211 | |
211 | | - // Test 2 |
| 212 | +test( 'es.DocumentModel.slice', 1, function() { |
| 213 | + var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 214 | + |
| 215 | + // Test 1 |
212 | 216 | deepEqual( documentModel.slice( 0 ), tree, 'Nodes in the model tree contain correct lengths' ); |
| 217 | +} ); |
| 218 | + |
| 219 | +test( 'es.DocumentModel.getContent', 6, function() { |
| 220 | + var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
213 | 221 | |
214 | | - // Test 3 |
| 222 | + // Test 1 |
215 | 223 | deepEqual( |
216 | 224 | documentModel[0].getContent( new es.Range( 1, 3 ) ), |
217 | 225 | [ |
— | — | @@ -220,14 +228,14 @@ |
221 | 229 | 'getContent can return an ending portion of the content' |
222 | 230 | ); |
223 | 231 | |
224 | | - // Test 4 |
| 232 | + // Test 2 |
225 | 233 | deepEqual( |
226 | 234 | documentModel[0].getContent( new es.Range( 0, 2 ) ), |
227 | 235 | ['a', ['b', { 'type': 'bold', 'hash': '#bold' }]], |
228 | 236 | 'getContent can return a beginning portion of the content' |
229 | 237 | ); |
230 | 238 | |
231 | | - // Test 5 |
| 239 | + // Test 3 |
232 | 240 | deepEqual( |
233 | 241 | documentModel[0].getContent( new es.Range( 1, 2 ) ), |
234 | 242 | [['b', { 'type': 'bold', 'hash': '#bold' }]], |
— | — | @@ -237,47 +245,55 @@ |
238 | 246 | try { |
239 | 247 | documentModel[0].getContent( new es.Range( -1, 3 ) ); |
240 | 248 | } catch ( negativeIndexError ) { |
241 | | - // Test 6 |
| 249 | + // Test 4 |
242 | 250 | ok( true, 'getContent throws exceptions when given a range with start < 0' ); |
243 | 251 | } |
244 | 252 | |
245 | 253 | try { |
246 | 254 | documentModel[0].getContent( new es.Range( 0, 4 ) ); |
247 | 255 | } catch ( outOfRangeError ) { |
248 | | - // Test 7 |
| 256 | + // Test 5 |
249 | 257 | ok( true, 'getContent throws exceptions when given a range with end > length' ); |
250 | 258 | } |
251 | 259 | |
252 | | - // Test 8 |
| 260 | + // Test 6 |
253 | 261 | deepEqual( documentModel[2].getContent(), ['a'], 'Content can be extracted from nodes' ); |
| 262 | +} ); |
| 263 | + |
| 264 | +test( 'es.DocumentModel.getIndexOfAnnotation', 3, function() { |
| 265 | + var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
254 | 266 | |
255 | 267 | var bold = { 'type': 'bold', 'hash': '#bold' }, |
256 | 268 | italic = { 'type': 'italic', 'hash': '#italic' }, |
257 | 269 | nothing = { 'type': 'nothing', 'hash': '#nothing' }, |
258 | 270 | character = ['a', bold, italic]; |
259 | 271 | |
260 | | - // Test 9 |
| 272 | + // Test 1 |
261 | 273 | equal( |
262 | 274 | es.DocumentModel.getIndexOfAnnotation( character, bold ), |
263 | 275 | 1, |
264 | 276 | 'getIndexOfAnnotation get the correct index' |
265 | 277 | ); |
266 | 278 | |
267 | | - // Test 10 |
| 279 | + // Test 2 |
268 | 280 | equal( |
269 | 281 | es.DocumentModel.getIndexOfAnnotation( character, italic ), |
270 | 282 | 2, |
271 | 283 | 'getIndexOfAnnotation get the correct index' |
272 | 284 | ); |
273 | 285 | |
274 | | - // Test 11 |
| 286 | + // Test 3 |
275 | 287 | equal( |
276 | 288 | es.DocumentModel.getIndexOfAnnotation( character, nothing ), |
277 | 289 | -1, |
278 | 290 | 'getIndexOfAnnotation returns -1 if the annotation was not found' |
279 | 291 | ); |
280 | | - |
281 | | - // Test 12 |
| 292 | +} ); |
| 293 | + |
| 294 | +test( 'es.DocumentModel.prepareElementAttributeChange', 4, function() { |
| 295 | + var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 296 | + |
| 297 | + // Test 1 |
282 | 298 | deepEqual( |
283 | 299 | documentModel.prepareElementAttributeChange( 0, 'set', 'test', 1234 ), |
284 | 300 | [ |
— | — | @@ -287,7 +303,7 @@ |
288 | 304 | 'prepareElementAttributeChange retains data after attribute change for first element' |
289 | 305 | ); |
290 | 306 | |
291 | | - // Test 13 |
| 307 | + // Test 2 |
292 | 308 | deepEqual( |
293 | 309 | documentModel.prepareElementAttributeChange( 5, 'set', 'test', 1234 ), |
294 | 310 | [ |
— | — | @@ -301,7 +317,7 @@ |
302 | 318 | try { |
303 | 319 | documentModel.prepareElementAttributeChange( 1, 'set', 'test', 1234 ); |
304 | 320 | } catch ( invalidOffsetError ) { |
305 | | - // Test 14 |
| 321 | + // Test 3 |
306 | 322 | ok( |
307 | 323 | true, |
308 | 324 | 'prepareElementAttributeChange throws an exception when offset is not an element' |
— | — | @@ -311,14 +327,18 @@ |
312 | 328 | try { |
313 | 329 | documentModel.prepareElementAttributeChange( 4, 'set', 'test', 1234 ); |
314 | 330 | } catch ( closingElementError ) { |
315 | | - // Test 15 |
| 331 | + // Test 4 |
316 | 332 | ok( |
317 | 333 | true, |
318 | 334 | 'prepareElementAttributeChange throws an exception when offset is a closing element' |
319 | 335 | ); |
320 | 336 | } |
321 | | - |
322 | | - // Test 16 |
| 337 | +} ); |
| 338 | + |
| 339 | +test( 'es.DocumentModel.prepareContentAnnotation', 1, function() { |
| 340 | + var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 341 | + |
| 342 | + // Test 1 |
323 | 343 | deepEqual( |
324 | 344 | documentModel.prepareContentAnnotation( new es.Range( 1, 4 ), 'set', { 'type': 'bold' } ), |
325 | 345 | [ |
— | — | @@ -354,8 +374,12 @@ |
355 | 375 | ], |
356 | 376 | 'prepareContentAnnotation skips over content that is already set or cleared' |
357 | 377 | ); |
358 | | - |
359 | | - // Test 17 |
| 378 | +} ); |
| 379 | + |
| 380 | +test( 'es.DocumentModel.prepareRemoval', 3, function() { |
| 381 | + var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 382 | + |
| 383 | + // Test 1 |
360 | 384 | deepEqual( |
361 | 385 | documentModel.prepareRemoval( new es.Range( 1, 4 ) ), |
362 | 386 | [ |
— | — | @@ -373,7 +397,7 @@ |
374 | 398 | 'prepareRemoval includes the content being removed' |
375 | 399 | ); |
376 | 400 | |
377 | | - // Test 18 |
| 401 | + // Test 2 |
378 | 402 | deepEqual( |
379 | 403 | documentModel.prepareRemoval( new es.Range( 15, 18 ) ), |
380 | 404 | [ |
— | — | @@ -391,7 +415,7 @@ |
392 | 416 | 'prepareRemoval removes entire elements' |
393 | 417 | ); |
394 | 418 | |
395 | | - // Test 19 |
| 419 | + // Test 3 |
396 | 420 | deepEqual( |
397 | 421 | documentModel.prepareRemoval( new es.Range( 17, 19 ) ), |
398 | 422 | [ |
— | — | @@ -407,8 +431,12 @@ |
408 | 432 | ], |
409 | 433 | 'prepareRemoval merges two list items' |
410 | 434 | ); |
411 | | - |
412 | | - // Test 20 |
| 435 | +} ); |
| 436 | + |
| 437 | +test( 'es.DocumentModel.prepareInsertion', 4, function() { |
| 438 | + var documentModel = es.DocumentModel.newFromPlainObject( obj ); |
| 439 | + |
| 440 | + // Test 1 |
413 | 441 | deepEqual( |
414 | 442 | documentModel.prepareInsertion( 1, ['d', 'e', 'f'] ), |
415 | 443 | [ |
— | — | @@ -419,7 +447,7 @@ |
420 | 448 | 'prepareInsertion retains data up to the offset and includes the content being inserted' |
421 | 449 | ); |
422 | 450 | |
423 | | - // Test 21 |
| 451 | + // Test 2 |
424 | 452 | deepEqual( |
425 | 453 | documentModel.prepareInsertion( |
426 | 454 | 5, |
— | — | @@ -436,7 +464,7 @@ |
437 | 465 | 'prepareInsertion inserts a paragraph between two structural elements' |
438 | 466 | ); |
439 | 467 | |
440 | | - // Test 22 |
| 468 | + // Test 3 |
441 | 469 | deepEqual( |
442 | 470 | documentModel.prepareInsertion( |
443 | 471 | 5, |
— | — | @@ -453,7 +481,7 @@ |
454 | 482 | 'prepareInsertion wraps unstructured content inserted between elements in a paragraph' |
455 | 483 | ); |
456 | 484 | |
457 | | - // Test 23 |
| 485 | + // Test 4 |
458 | 486 | deepEqual( |
459 | 487 | documentModel.prepareInsertion( |
460 | 488 | 5, |