@@ -22,6 +22,7 @@ import { SettingsState, TextDocumentTestManager } from '../src/yamlSettings';
2222import { LanguageService } from '../src' ;
2323import { LanguageHandlers } from '../src/languageserver/handlers/languageHandlers' ;
2424import { jigxBranchTest } from './utils/testHelperJigx' ;
25+ import { convertObjectToArrayItem } from '../src/languageservice/services/yamlCompletion' ;
2526
2627//TODO Petr fix merge
2728describe ( 'Auto Completion Tests' , ( ) => {
@@ -1166,6 +1167,89 @@ describe('Auto Completion Tests', () => {
11661167 expect ( completion . items . map ( ( i ) => i . insertText ) ) . to . deep . equal ( [ 'car:\n engine: ${1:type\\$1234}' ] ) ;
11671168 } ) ;
11681169
1170+ it ( 'Autocompletion with default value as an object' , async ( ) => {
1171+ schemaProvider . addSchema ( SCHEMA_ID , {
1172+ type : 'object' ,
1173+ properties : {
1174+ car : {
1175+ type : 'object' ,
1176+ default : {
1177+ engine : {
1178+ fuel : 'gasoline' ,
1179+ } ,
1180+ wheel : 4 ,
1181+ } ,
1182+ } ,
1183+ } ,
1184+ } ) ;
1185+ const content = 'car: |\n|' ;
1186+ const completion = await parseSetup ( content ) ;
1187+ expect ( completion . items . map ( ( i ) => i . insertText ) ) . to . deep . equal ( [
1188+ '\n ${1:engine}:\n ${2:fuel}: ${3:gasoline}\n ${4:wheel}: ${5:4}\n' ,
1189+ ] ) ;
1190+ } ) ;
1191+
1192+ it ( 'Autocompletion with default value as an array' , async ( ) => {
1193+ schemaProvider . addSchema ( SCHEMA_ID , {
1194+ type : 'object' ,
1195+ properties : {
1196+ garage : {
1197+ type : 'array' ,
1198+ items : {
1199+ type : 'object' ,
1200+ } ,
1201+ default : [
1202+ {
1203+ car : {
1204+ engine : { fuel : 'gasoline' } ,
1205+ wheel : [ 1 , 2 ] ,
1206+ } ,
1207+ } ,
1208+ {
1209+ car : {
1210+ engine : { fuel : 'diesel' } ,
1211+ } ,
1212+ } ,
1213+ ] ,
1214+ } ,
1215+ } ,
1216+ } ) ;
1217+ const content = 'garage: |\n|' ;
1218+ const completion = await parseSetup ( content ) ;
1219+ const expected = `
1220+ - \${1:car}:
1221+ \${2:engine}:
1222+ \${3:fuel}: \${4:gasoline}
1223+ \${5:wheel}:
1224+ - \${6:1}
1225+ - \${7:2}
1226+ - \${1:car}:
1227+ \${2:engine}:
1228+ \${3:fuel}: \${4:diesel}
1229+ ` ;
1230+ expect ( completion . items . map ( ( i ) => i . insertText ) ) . to . deep . equal ( [ expected ] ) ;
1231+ } ) ;
1232+
1233+ it ( 'should convert object to array item' , ( ) => {
1234+ const objectText = `
1235+ car:
1236+ engine:
1237+ fuel: gasoline
1238+ wheel:
1239+ - 1
1240+ - 2
1241+ ` ;
1242+ const expectedArrayItem = ` - car:
1243+ engine:
1244+ fuel: gasoline
1245+ wheel:
1246+ - 1
1247+ - 2
1248+ ` ;
1249+ const arrayItem = convertObjectToArrayItem ( objectText , ' ' ) ;
1250+ expect ( arrayItem ) . to . equal ( expectedArrayItem ) ;
1251+ } ) ;
1252+
11691253 it ( 'Autocompletion should escape colon when indicating map' , async ( ) => {
11701254 schemaProvider . addSchema ( SCHEMA_ID , {
11711255 type : 'object' ,
0 commit comments