@@ -46,21 +46,72 @@ describe('editor/operations: formatting operations', () => {
4646 expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "hello _world_!" , "type" : "plain" } ] ) ;
4747 } ) ;
4848
49- it ( 'works for escaping backticks in between texts' , ( ) => {
50- const renderer = createRenderer ( ) ;
51- const pc = createPartCreator ( ) ;
52- const model = new EditorModel ( [
53- pc . plain ( "hello ` world!" ) ,
54- ] , pc , renderer ) ;
55-
56- const range = model . startRange ( model . positionForOffset ( 0 , false ) ,
57- model . positionForOffset ( 13 , false ) ) ; // hello ` world
58-
59- expect ( range . parts [ 0 ] . text . trim ( ) . includes ( "`" ) ) . toBeTruthy ( ) ;
60- expect ( longestBacktickSequence ( range . parts [ 0 ] . text . trim ( ) ) ) . toBe ( 1 ) ;
61- expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "hello ` world!" , "type" : "plain" } ] ) ;
62- formatRangeAsCode ( range ) ;
63- expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "``hello ` world``!" , "type" : "plain" } ] ) ;
49+ describe ( 'escape backticks' , ( ) => {
50+ it ( 'works for escaping backticks in between texts' , ( ) => {
51+ const renderer = createRenderer ( ) ;
52+ const pc = createPartCreator ( ) ;
53+ const model = new EditorModel ( [
54+ pc . plain ( "hello ` world!" ) ,
55+ ] , pc , renderer ) ;
56+
57+ const range = model . startRange ( model . positionForOffset ( 0 , false ) ,
58+ model . positionForOffset ( 13 , false ) ) ; // hello ` world
59+
60+ expect ( range . parts [ 0 ] . text . trim ( ) . includes ( "`" ) ) . toBeTruthy ( ) ;
61+ expect ( longestBacktickSequence ( range . parts [ 0 ] . text . trim ( ) ) ) . toBe ( 1 ) ;
62+ expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "hello ` world!" , "type" : "plain" } ] ) ;
63+ formatRangeAsCode ( range ) ;
64+ expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "``hello ` world``!" , "type" : "plain" } ] ) ;
65+ } ) ;
66+
67+ it ( 'escapes longer backticks in between text' , ( ) => {
68+ const renderer = createRenderer ( ) ;
69+ const pc = createPartCreator ( ) ;
70+ const model = new EditorModel ( [
71+ pc . plain ( "hello```world" ) ,
72+ ] , pc , renderer ) ;
73+
74+ const range = model . startRange ( model . positionForOffset ( 0 , false ) ,
75+ model . getPositionAtEnd ( ) ) ; // hello```world
76+
77+ expect ( range . parts [ 0 ] . text . includes ( "`" ) ) . toBeTruthy ( ) ;
78+ expect ( longestBacktickSequence ( range . parts [ 0 ] . text ) ) . toBe ( 3 ) ;
79+ expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "hello```world" , "type" : "plain" } ] ) ;
80+ formatRangeAsCode ( range ) ;
81+ expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "````hello```world````" , "type" : "plain" } ] ) ;
82+ } ) ;
83+
84+ it ( 'escapes non-consecutive with varying length backticks in between text' , ( ) => {
85+ const renderer = createRenderer ( ) ;
86+ const pc = createPartCreator ( ) ;
87+ const model = new EditorModel ( [
88+ pc . plain ( "hell```o`w`o``rld" ) ,
89+ ] , pc , renderer ) ;
90+
91+ const range = model . startRange ( model . positionForOffset ( 0 , false ) ,
92+ model . getPositionAtEnd ( ) ) ; // hell```o`w`o``rld
93+ expect ( range . parts [ 0 ] . text . includes ( "`" ) ) . toBeTruthy ( ) ;
94+ expect ( longestBacktickSequence ( range . parts [ 0 ] . text ) ) . toBe ( 3 ) ;
95+ expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "hell```o`w`o``rld" , "type" : "plain" } ] ) ;
96+ formatRangeAsCode ( range ) ;
97+ expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "````hell```o`w`o``rld````" , "type" : "plain" } ] ) ;
98+ } ) ;
99+
100+ it ( 'escapes backticks in between text and untoggles already formated code text' , ( ) => {
101+ const renderer = createRenderer ( ) ;
102+ const pc = createPartCreator ( ) ;
103+ const model = new EditorModel ( [
104+ pc . plain ( "`hello`world`" ) ,
105+ ] , pc , renderer ) ;
106+
107+ const range = model . startRange ( model . positionForOffset ( 0 , false ) ,
108+ model . getPositionAtEnd ( ) ) ; // `hello`world`
109+ expect ( range . parts [ 0 ] . text . includes ( "`" ) ) . toBeTruthy ( ) ;
110+ expect ( longestBacktickSequence ( range . parts [ 0 ] . text ) ) . toBe ( 1 ) ;
111+ expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "`hello`world`" , "type" : "plain" } ] ) ;
112+ formatRangeAsCode ( range ) ;
113+ expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "hello`world" , "type" : "plain" } ] ) ;
114+ } ) ;
64115 } ) ;
65116
66117 it ( 'works for parts of words' , ( ) => {
0 commit comments