@@ -315,6 +315,51 @@ suite('EditorConfig extension', function () {
315315 'editor selection end line changed' ,
316316 )
317317 } )
318+
319+ test ( 'charset (utf-8)' , async ( ) => {
320+ const document = await withSetting ( 'charset' , 'utf-8' ) . createDoc ( )
321+ assert . strictEqual (
322+ document . encoding ,
323+ 'utf8' ,
324+ `document encoding is ${ document . encoding } instead of utf8` ,
325+ )
326+ } )
327+
328+ test ( 'charset (utf-8-bom)' , async ( ) => {
329+ const document = await withSetting ( 'charset' , 'utf-8-bom' ) . createDoc ( )
330+ assert . strictEqual (
331+ document . encoding ,
332+ 'utf8bom' ,
333+ `document encoding is ${ document . encoding } instead of utf8bom` ,
334+ )
335+ } )
336+
337+ test ( 'charset (utf-16le)' , async ( ) => {
338+ const document = await withSetting ( 'charset' , 'utf-16le' ) . createDoc ( )
339+ assert . strictEqual (
340+ document . encoding ,
341+ 'utf16le' ,
342+ `document encoding is ${ document . encoding } instead of utf16le` ,
343+ )
344+ } )
345+
346+ test ( 'charset (utf-16be)' , async ( ) => {
347+ const document = await withSetting ( 'charset' , 'utf-16be' ) . createDoc ( )
348+ assert . strictEqual (
349+ document . encoding ,
350+ 'utf16be' ,
351+ `document encoding is ${ document . encoding } instead of utf16be` ,
352+ )
353+ } )
354+
355+ test ( 'charset (latin1)' , async ( ) => {
356+ const document = await withSetting ( 'charset' , 'latin1' ) . createDoc ( )
357+ assert . strictEqual (
358+ document . encoding ,
359+ 'iso88591' ,
360+ `document encoding is ${ document . encoding } instead of iso88591` ,
361+ )
362+ } )
318363} )
319364
320365function withSetting (
@@ -327,11 +372,13 @@ function withSetting(
327372) {
328373 return {
329374 async getText ( ) {
330- return ( await createDoc ( options . contents , options . fileName ) ) . getText ( )
375+ return (
376+ await this . createDoc ( options . contents , options . fileName )
377+ ) . getText ( )
331378 } ,
332379 saveText ( text : string ) {
333380 return new Promise < string > ( async resolve => {
334- const doc = await createDoc ( options . contents , options . fileName )
381+ const doc = await this . createDoc ( options . contents , options . fileName )
335382 workspace . onDidChangeTextDocument ( doc . save )
336383 workspace . onDidSaveTextDocument ( savedDoc => {
337384 assert . strictEqual ( savedDoc . isDirty , false , 'dirty saved doc' )
@@ -346,15 +393,15 @@ function withSetting(
346393 )
347394 } )
348395 } ,
349- }
350- async function createDoc ( contents = '' , name = 'test' ) {
351- const uri = await utils . createFile (
352- contents ,
353- getFixturePath ( [ rule , value , name ] ) ,
354- )
355- const doc = await workspace . openTextDocument ( uri )
356- await window . showTextDocument ( doc )
357- await wait ( 50 ) // wait for EditorConfig to apply new settings
358- return doc
396+ async createDoc ( contents = '' , name = 'test' ) {
397+ const uri = await utils . createFile (
398+ contents ,
399+ getFixturePath ( [ rule , value , name ] ) ,
400+ )
401+ const doc = await workspace . openTextDocument ( uri )
402+ await window . showTextDocument ( doc )
403+ await wait ( 50 ) // wait for EditorConfig to apply new settings
404+ return doc
405+ } ,
359406 }
360407}
0 commit comments