@@ -17,58 +17,66 @@ function createParams(position: Position): DocumentOnTypeFormattingParams {
1717 } ;
1818}
1919describe ( 'YAML On Type Formatter' , ( ) => {
20- it ( 'should react on "\n" only ', ( ) => {
21- const doc = setupTextDocument ( 'foo:' ) ;
22- const params = createParams ( Position . create ( 1 , 0 ) ) ;
23- params . ch = '\t' ;
24- const result = doDocumentOnTypeFormatting ( doc , params ) ;
25- expect ( result ) . is . undefined ;
26- } ) ;
20+ describe ( 'On Enter Formatter ', ( ) => {
21+ it ( 'should add indentation for mapping' , ( ) => {
22+ const doc = setupTextDocument ( 'foo:\n' ) ;
23+ const params = createParams ( Position . create ( 1 , 0 ) ) ;
24+ const result = doDocumentOnTypeFormatting ( doc , params ) ;
25+ expect ( result ) . to . deep . include ( TextEdit . insert ( Position . create ( 1 , 0 ) , ' ' ) ) ;
26+ } ) ;
2727
28- it ( 'should add indentation for mapping' , ( ) => {
29- const doc = setupTextDocument ( 'foo:\n' ) ;
30- const params = createParams ( Position . create ( 1 , 0 ) ) ;
31- const result = doDocumentOnTypeFormatting ( doc , params ) ;
32- expect ( result ) . to . deep . include ( TextEdit . insert ( Position . create ( 1 , 0 ) , ' ' ) ) ;
33- } ) ;
28+ it ( 'should add indentation for scalar array items' , ( ) => {
29+ const doc = setupTextDocument ( 'foo:\n - some\n ' ) ;
30+ const pos = Position . create ( 2 , 2 ) ;
31+ const params = createParams ( pos ) ;
32+ const result = doDocumentOnTypeFormatting ( doc , params ) ;
33+ expect ( result [ 0 ] ) . to . eqls ( TextEdit . insert ( pos , '- ' ) ) ;
34+ } ) ;
3435
35- it ( 'should add indentation for scalar array items ' , ( ) => {
36- const doc = setupTextDocument ( 'foo :\n - some \n ' ) ;
37- const pos = Position . create ( 2 , 2 ) ;
38- const params = createParams ( pos ) ;
39- const result = doDocumentOnTypeFormatting ( doc , params ) ;
40- expect ( result [ 0 ] ) . to . eqls ( TextEdit . insert ( pos , '- ' ) ) ;
41- } ) ;
36+ it ( 'should add indentation for mapping in array ' , ( ) => {
37+ const doc = setupTextDocument ( 'some :\n - arr: \n ' ) ;
38+ const pos = Position . create ( 2 , 2 ) ;
39+ const params = createParams ( pos ) ;
40+ const result = doDocumentOnTypeFormatting ( doc , params ) ;
41+ expect ( result ) . to . deep . include ( TextEdit . insert ( pos , ' ' ) ) ;
42+ } ) ;
4243
43- it ( 'should add indentation for mapping in array' , ( ) => {
44- const doc = setupTextDocument ( 'some:\n - arr:\n ' ) ;
45- const pos = Position . create ( 2 , 2 ) ;
46- const params = createParams ( pos ) ;
47- const result = doDocumentOnTypeFormatting ( doc , params ) ;
48- expect ( result ) . to . deep . include ( TextEdit . insert ( pos , ' ' ) ) ;
49- } ) ;
44+ it ( 'should replace all spaces in newline' , ( ) => {
45+ const doc = setupTextDocument ( 'some:\n ' ) ;
46+ const pos = Position . create ( 1 , 0 ) ;
47+ const params = createParams ( pos ) ;
48+ const result = doDocumentOnTypeFormatting ( doc , params ) ;
49+ expect ( result ) . to . deep . include . members ( [
50+ TextEdit . del ( Range . create ( pos , Position . create ( 1 , 3 ) ) ) ,
51+ TextEdit . insert ( pos , ' ' ) ,
52+ ] ) ;
53+ } ) ;
5054
51- it ( 'should replace all spaces in newline' , ( ) => {
52- const doc = setupTextDocument ( 'some:\n ' ) ;
53- const pos = Position . create ( 1 , 0 ) ;
54- const params = createParams ( pos ) ;
55- const result = doDocumentOnTypeFormatting ( doc , params ) ;
56- expect ( result ) . to . deep . include . members ( [ TextEdit . del ( Range . create ( pos , Position . create ( 1 , 3 ) ) ) , TextEdit . insert ( pos , ' ' ) ] ) ;
57- } ) ;
55+ it ( 'should keep all non white spaces characters in newline' , ( ) => {
56+ const doc = setupTextDocument ( 'some:\n foo ' ) ;
57+ const pos = Position . create ( 1 , 0 ) ;
58+ const params = createParams ( pos ) ;
59+ const result = doDocumentOnTypeFormatting ( doc , params ) ;
60+ expect ( result ) . is . undefined ;
61+ } ) ;
5862
59- it ( 'should keep all non white spaces characters in newline' , ( ) => {
60- const doc = setupTextDocument ( 'some:\n foo' ) ;
61- const pos = Position . create ( 1 , 0 ) ;
62- const params = createParams ( pos ) ;
63- const result = doDocumentOnTypeFormatting ( doc , params ) ;
64- expect ( result ) . is . undefined ;
63+ it ( 'should add indentation for multiline string' , ( ) => {
64+ const doc = setupTextDocument ( 'some: |\n' ) ;
65+ const pos = Position . create ( 1 , 0 ) ;
66+ const params = createParams ( pos ) ;
67+ const result = doDocumentOnTypeFormatting ( doc , params ) ;
68+ expect ( result ) . to . deep . include ( TextEdit . insert ( pos , ' ' ) ) ;
69+ } ) ;
6570 } ) ;
6671
67- it ( 'should add indentation for multiline string' , ( ) => {
68- const doc = setupTextDocument ( 'some: |\n' ) ;
69- const pos = Position . create ( 1 , 0 ) ;
70- const params = createParams ( pos ) ;
71- const result = doDocumentOnTypeFormatting ( doc , params ) ;
72- expect ( result ) . to . deep . include ( TextEdit . insert ( pos , ' ' ) ) ;
72+ describe ( 'On Tab Formatter' , ( ) => {
73+ it ( 'should replace Tab with spaces' , ( ) => {
74+ const doc = setupTextDocument ( 'some:\n\t' ) ;
75+ const pos = Position . create ( 1 , 1 ) ;
76+ const params = createParams ( pos ) ;
77+ params . ch = '\t' ;
78+ const result = doDocumentOnTypeFormatting ( doc , params ) ;
79+ expect ( result ) . to . deep . include ( TextEdit . replace ( Range . create ( 1 , 0 , 1 , 1 ) , ' ' ) ) ;
80+ } ) ;
7381 } ) ;
7482} ) ;
0 commit comments