@@ -21,6 +21,7 @@ import { expect } from 'chai';
2121import { SettingsState , TextDocumentTestManager } from '../src/yamlSettings' ;
2222import { LanguageService } from '../src' ;
2323import { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers' ;
24+ import { convertObjectToArrayItem } from '../src/languageservice/services/yamlCompletion' ;
2425
2526describe ( 'Auto Completion Tests' , ( ) => {
2627 let languageSettingsSetup : ServiceSetup ;
@@ -931,6 +932,89 @@ describe('Auto Completion Tests', () => {
931932 ) ;
932933 } ) ;
933934
935+ it ( 'Autocompletion with default value as an object' , async ( ) => {
936+ schemaProvider . addSchema ( SCHEMA_ID , {
937+ type : 'object' ,
938+ properties : {
939+ car : {
940+ type : 'object' ,
941+ default : {
942+ engine : {
943+ fuel : 'gasoline' ,
944+ } ,
945+ wheel : 4 ,
946+ } ,
947+ } ,
948+ } ,
949+ } ) ;
950+ const content = 'car: |\n|' ;
951+ const completion = await parseSetup ( content ) ;
952+ expect ( completion . items . map ( ( i ) => i . insertText ) ) . to . deep . equal ( [
953+ '\n ${1:engine}:\n ${2:fuel}: ${3:gasoline}\n ${4:wheel}: ${5:4}\n' ,
954+ ] ) ;
955+ } ) ;
956+
957+ it ( 'Autocompletion with default value as an array' , async ( ) => {
958+ schemaProvider . addSchema ( SCHEMA_ID , {
959+ type : 'object' ,
960+ properties : {
961+ garage : {
962+ type : 'array' ,
963+ items : {
964+ type : 'object' ,
965+ } ,
966+ default : [
967+ {
968+ car : {
969+ engine : { fuel : 'gasoline' } ,
970+ wheel : [ 1 , 2 ] ,
971+ } ,
972+ } ,
973+ {
974+ car : {
975+ engine : { fuel : 'diesel' } ,
976+ } ,
977+ } ,
978+ ] ,
979+ } ,
980+ } ,
981+ } ) ;
982+ const content = 'garage: |\n|' ;
983+ const completion = await parseSetup ( content ) ;
984+ const expected = `
985+ - \${1:car}:
986+ \${2:engine}:
987+ \${3:fuel}: \${4:gasoline}
988+ \${5:wheel}:
989+ - \${6:1}
990+ - \${7:2}
991+ - \${1:car}:
992+ \${2:engine}:
993+ \${3:fuel}: \${4:diesel}
994+ ` ;
995+ expect ( completion . items . map ( ( i ) => i . insertText ) ) . to . deep . equal ( [ expected ] ) ;
996+ } ) ;
997+
998+ it ( 'should convert object to array item' , ( ) => {
999+ const objectText = `
1000+ car:
1001+ engine:
1002+ fuel: gasoline
1003+ wheel:
1004+ - 1
1005+ - 2
1006+ ` ;
1007+ const expectedArrayItem = ` - car:
1008+ engine:
1009+ fuel: gasoline
1010+ wheel:
1011+ - 1
1012+ - 2
1013+ ` ;
1014+ const arrayItem = convertObjectToArrayItem ( objectText , ' ' ) ;
1015+ expect ( arrayItem ) . to . equal ( expectedArrayItem ) ;
1016+ } ) ;
1017+
9341018 it ( 'Autocompletion should escape colon when indicating map' , async ( ) => {
9351019 schemaProvider . addSchema ( SCHEMA_ID , {
9361020 type : 'object' ,
0 commit comments