| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- /**
- * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- /* bender-tags: treeview */
- 'use strict';
- import Writer from '/ckeditor5/engine/treeview/writer.js';
- import Element from '/ckeditor5/engine/treeview/element.js';
- import Text from '/ckeditor5/engine/treeview/text.js';
- import utils from '/tests/engine/treeview/writer/_utils/utils.js';
- describe( 'Writer', () => {
- const create = utils.create;
- const test = utils.test;
- let writer;
- beforeEach( () => {
- writer = new Writer();
- } );
- describe( 'breakAttributes', () => {
- // <p>{|foobar}</p> -> <p>|{foobar}</p>
- it( '<p>{|foobar}</p>', () => {
- const created = create( writer, {
- instanceOf: Element,
- name: 'p',
- children: [
- { instanceOf: Text, data: 'foobar', position: 0 }
- ]
- } );
- const newPosition = writer.breakAttributes( created.position );
- test( writer, newPosition, created.node, {
- instanceOf: Element,
- name: 'p',
- position: 0,
- children: [
- { instanceOf: Text, data: 'foobar' }
- ]
- } );
- } );
- it( '<p>foo|bar</p>', () => {
- // <p>{foo|bar}</p> -> <p>{foo}|{bar}</p>
- const created = create( writer, {
- instanceOf: Element,
- name: 'p',
- children: [
- { instanceOf: Text, data: 'foobar', position: 3 }
- ]
- } );
- const newPosition = writer.breakAttributes( created.position );
- test( writer, newPosition, created.node, {
- instanceOf: Element,
- name: 'p',
- position: 1,
- children: [
- { instanceOf: Text, data: 'foo' },
- { instanceOf: Text, data: 'bar' }
- ]
- } );
- } );
- it( '<p>{foobar|}</p>', () => {
- // <p>{foobar|}</p> -> <p>{foobar}|</p>
- const created = create( writer, {
- instanceOf: Element,
- name: 'p',
- children: [
- { instanceOf: Text, data: 'foobar', position: 6 }
- ]
- } );
- const newPosition = writer.breakAttributes( created.position );
- test( writer, newPosition, created.node, {
- instanceOf: Element,
- name: 'p',
- position: 1,
- children: [
- { instanceOf: Text, data: 'foobar' }
- ]
- } );
- } );
- it( '<p><b>{foo|bar}</b></p>', () => {
- // <p><b>{foo|bar}</b></p> -> <p><b>{foo}</b>|<b>{bar}</b></p>
- const created = create( writer, {
- instanceOf: Element,
- name: 'p',
- children: [
- {
- instanceOf: Element,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobar', position: 3 }
- ]
- }
- ]
- } );
- const newPosition = writer.breakAttributes( created.position );
- test( writer, newPosition, created.node, {
- instanceOf: Element,
- name: 'p',
- position: 1,
- children: [
- {
- instanceOf: Element,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foo' }
- ]
- },
- {
- instanceOf: Element,
- name: 'b',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bar' }
- ]
- }
- ]
- } );
- } );
- it( '<p><b><u>{|foobar}</u></b></p>', () => {
- // <p><b><u>{|foobar}</u></b></p> -> <p>|<b><u>{foobar}</u></b></p>
- const created = create( writer, {
- instanceOf: Element,
- name: 'p',
- children: [
- {
- instanceOf: Element,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: Element,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobar', position: 0 }
- ]
- }
- ]
- }
- ]
- } );
- const newPosition = writer.breakAttributes( created.position );
- test( writer, newPosition, created.node, {
- instanceOf: Element,
- name: 'p',
- position: 0,
- children: [
- {
- instanceOf: Element,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: Element,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobar' }
- ]
- }
- ]
- }
- ]
- } );
- } );
- // <p><b><u>{foo|ba}r</u></b></p> -> <p><b><u>{foo}</u></b>|<b></u>{bar}</u></b></p>
- it( '<p><b><u>{foo|bar}</u></b></p>', () => {
- const created = create( writer, {
- instanceOf: Element,
- name: 'p',
- children: [
- {
- instanceOf: Element,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: Element,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobar', position: 3 }
- ]
- }
- ]
- }
- ]
- } );
- const newPosition = writer.breakAttributes( created.position );
- test( writer, newPosition, created.node, {
- instanceOf: Element,
- name: 'p',
- position: 1,
- children: [
- {
- instanceOf: Element,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: Element,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foo' }
- ]
- }
- ]
- },
- {
- instanceOf: Element,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: Element,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'bar' }
- ]
- }
- ]
- }
- ]
- } );
- } );
- it( '<p><b><u>{foobar|}</u></b></p>', () => {
- // <p><b><u>{foobar|}</u></b></p> -> <p><b><u>{foobar}</u></b>|</p>
- const created = create( writer, {
- instanceOf: Element,
- name: 'p',
- children: [
- {
- instanceOf: Element,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: Element,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobar', position: 6 }
- ]
- }
- ]
- }
- ]
- } );
- const newPosition = writer.breakAttributes( created.position );
- test( writer, newPosition, created.node, {
- instanceOf: Element,
- name: 'p',
- position: 1,
- children: [
- {
- instanceOf: Element,
- name: 'b',
- priority: 1,
- children: [
- {
- instanceOf: Element,
- name: 'u',
- priority: 1,
- children: [
- { instanceOf: Text, data: 'foobar' }
- ]
- }
- ]
- }
- ]
- } );
- } );
- } );
- } );
|