@@ -841,6 +841,29 @@ snippets:
841841 } ,
842842 ] ) ;
843843 } ) ;
844+
845+ it ( 'should suggest defaultSnippet(snippetArray) for ARRAY property - value on 2nd position' , async ( ) => {
846+ schemaProvider . addSchema ( SCHEMA_ID , schema ) ;
847+ const content = `
848+ snippets:
849+ snippetArray:
850+ - item1: test
851+ |\n|
852+ ` ;
853+ const completion = await parseCaret ( content ) ;
854+
855+ expect ( completion . items . map ( ( { label, insertText } ) => ( { label, insertText } ) ) ) . to . be . deep . equal ( [
856+ {
857+ label : 'labelSnippetArray' ,
858+ insertText : `- item1: value
859+ item2: value2` ,
860+ } ,
861+ {
862+ label : '- (array item) object' ,
863+ insertText : '- ' ,
864+ } ,
865+ ] ) ;
866+ } ) ;
844867 } ) ;
845868 describe ( 'defaultSnippets(snippetArray2) on the items level as an object value' , ( ) => {
846869 const schema = getNestedSchema ( {
@@ -919,6 +942,27 @@ snippets:
919942 item2: value2` ,
920943 ] ) ;
921944 } ) ;
945+ it ( 'should suggest defaultSnippet(snippetArray2) for ARRAY property - value on 2nd position (no hyphen)' , async ( ) => {
946+ schemaProvider . addSchema ( SCHEMA_ID , schema ) ;
947+ const content = `
948+ snippets:
949+ snippetArray2:
950+ - item1: test
951+ |\n|
952+ ` ;
953+ const completion = await parseCaret ( content ) ;
954+
955+ expect ( completion . items . map ( ( i ) => ( { label : i . label , insertText : i . insertText } ) ) ) . to . be . deep . equal ( [
956+ {
957+ insertText : '- item1: value\n item2: value2' ,
958+ label : 'labelSnippetArray' ,
959+ } ,
960+ {
961+ insertText : '- item1: value\n item2: value2' ,
962+ label : '- (array item) object' ,
963+ } ,
964+ ] ) ;
965+ } ) ;
922966 } ) ; // ARRAY - Snippet on items level
923967
924968 describe ( 'defaultSnippets(snippetArrayPrimitives) on the items level, ARRAY - Body is array of primitives' , ( ) => {
@@ -998,6 +1042,7 @@ snippets:
9981042 } ,
9991043 defaultSnippets : [
10001044 {
1045+ label : 'snippetArray2Objects' ,
10011046 body : [
10021047 {
10031048 item1 : 'value' ,
@@ -1074,6 +1119,27 @@ snippets:
10741119
10751120 expect ( completion . items . map ( ( i ) => i . insertText ) ) . to . be . deep . equal ( [ 'item1: value\n item2: value2\n- item3: value' ] ) ;
10761121 } ) ;
1122+ it ( 'should suggest defaultSnippet(snippetArray2Objects) for ARRAY property with objects - value on 2nd position (no hyphen)' , async ( ) => {
1123+ schemaProvider . addSchema ( SCHEMA_ID , schema ) ;
1124+ const content = `
1125+ snippets:
1126+ snippetArray2Objects:
1127+ - 1st: 1
1128+ |\n|
1129+ ` ;
1130+ const completion = await parseCaret ( content ) ;
1131+
1132+ expect ( completion . items . map ( ( i ) => ( { label : i . label , insertText : i . insertText } ) ) ) . to . be . deep . equal ( [
1133+ {
1134+ insertText : '- item1: value\n item2: value2\n- item3: value' ,
1135+ label : 'snippetArray2Objects' ,
1136+ } ,
1137+ {
1138+ insertText : '- $1\n' ,
1139+ label : '- (array item) object' ,
1140+ } ,
1141+ ] ) ;
1142+ } ) ;
10771143 } ) ; // ARRAY outside items - Body is array of objects
10781144
10791145 describe ( 'defaultSnippets(snippetArrayObjects) on the items level, ARRAY - Body is array of objects' , ( ) => {
@@ -1148,6 +1214,21 @@ snippets:
11481214
11491215 expect ( completion . items . map ( ( i ) => i . insertText ) ) . to . be . deep . equal ( [ 'item1: value\n item2: value2\n- item3: value' ] ) ;
11501216 } ) ;
1217+ it ( 'should suggest defaultSnippet(snippetArrayObjects) for ARRAY property with objects - value on 2nd position (no hyphen)' , async ( ) => {
1218+ schemaProvider . addSchema ( SCHEMA_ID , schema ) ;
1219+ const content = `
1220+ snippets:
1221+ snippetArrayObjects:
1222+ - 1st: 1
1223+ |\n|
1224+ ` ;
1225+ const completion = await parseCaret ( content ) ;
1226+
1227+ expect ( completion . items . map ( ( i ) => i . insertText ) ) . to . be . deep . equal ( [
1228+ '- item1: value\n item2: value2\n- item3: value' , // array item snippet from getInsertTextForObject
1229+ '- item1: value\n item2: value2\n- item3: value' , // from collectDefaultSnippets
1230+ ] ) ;
1231+ } ) ;
11511232 } ) ; // ARRAY - Body is array of objects
11521233
11531234 describe ( 'defaultSnippets(snippetArrayString) on the items level, ARRAY - Body is string' , ( ) => {
@@ -1212,6 +1293,27 @@ snippets:
12121293
12131294 expect ( completion . items . map ( ( i ) => i . insertText ) ) . to . be . deep . equal ( [ 'value' ] ) ;
12141295 } ) ;
1296+ it ( 'should suggest defaultSnippet(snippetArrayString) for ARRAY property with string - value on 2nd position (no hyphen)' , async ( ) => {
1297+ schemaProvider . addSchema ( SCHEMA_ID , schema ) ;
1298+ const content = `
1299+ snippets:
1300+ snippetArrayString:
1301+ - some other value
1302+ |\n|
1303+ ` ;
1304+ const completion = await parseCaret ( content ) ;
1305+
1306+ expect ( completion . items . map ( ( i ) => ( { label : i . label , insertText : i . insertText } ) ) ) . to . be . deep . equal ( [
1307+ {
1308+ insertText : '- value' ,
1309+ label : '"value"' ,
1310+ } ,
1311+ {
1312+ insertText : '- value' ,
1313+ label : '- (array item) string' ,
1314+ } ,
1315+ ] ) ;
1316+ } ) ;
12151317 } ) ; // ARRAY - Body is simple string
12161318 } ) ; // ARRAY
12171319
@@ -1295,6 +1397,24 @@ snippets:
12951397
12961398 expect ( completion . items . map ( ( i ) => i . insertText ) ) . to . be . deep . equal ( [ 'item1: value\n item2: value2\n- item3: value' ] ) ;
12971399 } ) ;
1400+
1401+ it ( 'should suggest defaultSnippet(snippetAnyOfArray) for ARRAY property with objects - value on 2nd position (no hyphen)' , async ( ) => {
1402+ schemaProvider . addSchema ( SCHEMA_ID , schema ) ;
1403+ const content = `
1404+ snippets:
1405+ snippetAnyOfArray:
1406+ - 1st: 1
1407+ |\n|
1408+ ` ;
1409+ const completion = await parseCaret ( content ) ;
1410+
1411+ expect ( completion . items . map ( ( i ) => ( { label : i . label , insertText : i . insertText } ) ) ) . to . be . deep . equal ( [
1412+ {
1413+ insertText : '- $1\n' , // could be better to suggest snippet - todo
1414+ label : '- (array item) object' ,
1415+ } ,
1416+ ] ) ;
1417+ } ) ;
12981418 } ) ; // anyOf - Body is array of objects
12991419 } ) ; // variations of defaultSnippets
13001420} ) ;
0 commit comments