File tree 2 files changed +23
-1
lines changed
2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -439,7 +439,9 @@ MagicPen.prototype.space = MagicPen.prototype.sp = function (count) {
439
439
} ) ;
440
440
441
441
MagicPen . prototype . clone = function ( format ) {
442
- this . ensureCompatibleFormat ( format ) ;
442
+ if ( ! this . isEmpty ( ) ) {
443
+ this . ensureCompatibleFormat ( format ) ;
444
+ }
443
445
444
446
function MagicPenClone ( ) { }
445
447
MagicPenClone . prototype = this ;
Original file line number Diff line number Diff line change @@ -830,6 +830,26 @@ describe('magicpen', function () {
830
830
} ) ;
831
831
} ) ;
832
832
833
+ describe ( 'clone' , function ( ) {
834
+ describe ( 'when given a format' , function ( ) {
835
+ it ( 'can be cloned to another format when the format is not specified yet' , function ( ) {
836
+ pen = pen . clone ( 'text' ) ;
837
+ expect ( pen . format , 'to equal' , 'text' ) ;
838
+ } ) ;
839
+
840
+ it ( 'can be cloned to another format when the pen is empty' , function ( ) {
841
+ pen = pen . clone ( 'text' ) . clone ( 'html' ) ;
842
+ expect ( pen . format , 'to equal' , 'html' ) ;
843
+ } ) ;
844
+
845
+ it ( 'fails when given an incompatible format' , function ( ) {
846
+ expect ( function ( ) {
847
+ pen . clone ( 'text' ) . text ( 'foobar' ) . clone ( 'html' ) ;
848
+ } , 'to throw' , 'This pen is only compatible with the format: text' ) ;
849
+ } ) ;
850
+ } ) ;
851
+ } ) ;
852
+
833
853
describe ( 'in text mode' , function ( ) {
834
854
it ( 'ignores unknown styles' , function ( ) {
835
855
pen . text ( '>' ) . write ( { style : 'test' , args : [ 'text' ] } ) . text ( '<' ) ;
You can’t perform that action at this time.
0 commit comments