nodelist.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: document */
  6. 'use strict';
  7. var modules = bender.amd.require(
  8. 'document/nodelist',
  9. 'document/character' );
  10. describe( 'constructor', function() {
  11. it( 'should change array of strings into a set of nodes', function() {
  12. var NodeList = modules[ 'document/nodelist' ];
  13. var Character = modules[ 'document/character' ];
  14. var nodeList = new NodeList( [ 'foo', new Character( null, 'x' ), 'bar' ] );
  15. expect( nodeList.length ).to.be.equal( 7 );
  16. expect( nodeList.get( 0 ).character ).to.be.equal( 'f' );
  17. expect( nodeList.get( 1 ).character ).to.be.equal( 'o' );
  18. expect( nodeList.get( 2 ).character ).to.be.equal( 'o' );
  19. expect( nodeList.get( 3 ).character ).to.be.equal( 'x' );
  20. expect( nodeList.get( 4 ).character ).to.be.equal( 'b' );
  21. expect( nodeList.get( 5 ).character ).to.be.equal( 'a' );
  22. expect( nodeList.get( 6 ).character ).to.be.equal( 'r' );
  23. } );
  24. it( 'should change string into a set of nodes', function() {
  25. var NodeList = modules[ 'document/nodelist' ];
  26. var nodeList = new NodeList( 'foo' );
  27. expect( nodeList.length ).to.be.equal( 3 );
  28. expect( nodeList.get( 0 ).character ).to.be.equal( 'f' );
  29. expect( nodeList.get( 1 ).character ).to.be.equal( 'o' );
  30. expect( nodeList.get( 2 ).character ).to.be.equal( 'o' );
  31. } );
  32. it( 'should change node into a set of nodes', function() {
  33. var NodeList = modules[ 'document/nodelist' ];
  34. var Character = modules[ 'document/character' ];
  35. var nodeList = new NodeList( new Character( null, 'x' ) );
  36. expect( nodeList.length ).to.be.equal( 1 );
  37. expect( nodeList.get( 0 ).character ).to.be.equal( 'x' );
  38. } );
  39. } );
  40. describe( 'insert', function() {
  41. it( 'should insert one nodelist into another', function() {
  42. var NodeList = modules[ 'document/nodelist' ];
  43. var outerList = new NodeList( 'foo' );
  44. var innerList = new NodeList( 'xxx' );
  45. outerList.insert( 2, innerList );
  46. expect( outerList.length ).to.be.equal( 6 );
  47. expect( outerList.get( 0 ).character ).to.be.equal( 'f' );
  48. expect( outerList.get( 1 ).character ).to.be.equal( 'o' );
  49. expect( outerList.get( 2 ).character ).to.be.equal( 'x' );
  50. expect( outerList.get( 3 ).character ).to.be.equal( 'x' );
  51. expect( outerList.get( 4 ).character ).to.be.equal( 'x' );
  52. expect( outerList.get( 5 ).character ).to.be.equal( 'o' );
  53. } );
  54. } );
  55. describe( 'remove', function() {
  56. it( 'should remove part of the nodelist', function() {
  57. var NodeList = modules[ 'document/nodelist' ];
  58. var nodeList = new NodeList( 'foobar' );
  59. nodeList.remove( 2, 3 );
  60. expect( nodeList.length ).to.be.equal( 3 );
  61. expect( nodeList.get( 0 ).character ).to.be.equal( 'f' );
  62. expect( nodeList.get( 1 ).character ).to.be.equal( 'o' );
  63. expect( nodeList.get( 2 ).character ).to.be.equal( 'r' );
  64. } );
  65. } );