@@ -9,7 +9,13 @@ import * as assert from 'assert';
99import URI from 'vs/base/common/uri' ;
1010import * as types from 'vs/workbench/api/common/extHostTypes' ;
1111
12- suite ( 'PluginHostTypes' , function ( ) {
12+ function assertToJSON ( a : any , expected : any ) {
13+ const raw = JSON . stringify ( a ) ;
14+ const actual = JSON . parse ( raw ) ;
15+ assert . deepEqual ( actual , expected ) ;
16+ }
17+
18+ suite ( 'ExtHostTypes' , function ( ) {
1319
1420 test ( 'Disposable' , function ( ) {
1521
@@ -47,6 +53,14 @@ suite('PluginHostTypes', function() {
4753 assert . throws ( ( ) => pos . character = - 1 ) ;
4854 assert . throws ( ( ) => pos . line = 12 ) ;
4955
56+ let [ line , character ] = pos . toJSON ( ) ;
57+ assert . equal ( line , 0 ) ;
58+ assert . equal ( character , 0 ) ;
59+ } ) ;
60+
61+ test ( 'Position, toJSON' , function ( ) {
62+ let pos = new types . Position ( 4 , 2 ) ;
63+ assertToJSON ( pos , [ 4 , 2 ] )
5064 } ) ;
5165
5266 test ( 'Position, isBefore(OrEqual)?' , function ( ) {
@@ -133,6 +147,12 @@ suite('PluginHostTypes', function() {
133147 assert . throws ( ( ) => range . start = new types . Position ( 0 , 3 ) ) ;
134148 } ) ;
135149
150+ test ( 'Range, toJSON' , function ( ) {
151+
152+ let range = new types . Range ( 1 , 2 , 3 , 4 ) ;
153+ assertToJSON ( range , [ [ 1 , 2 ] , [ 3 , 4 ] ] ) ;
154+ } ) ;
155+
136156 test ( 'Range, sorting' , function ( ) {
137157 // sorts start/end
138158 let range = new types . Range ( 1 , 0 , 0 , 0 ) ;
@@ -249,6 +269,7 @@ suite('PluginHostTypes', function() {
249269 let range = new types . Range ( 1 , 1 , 2 , 11 ) ;
250270 let edit = new types . TextEdit ( range , undefined ) ;
251271 assert . equal ( edit . newText , '' ) ;
272+ assertToJSON ( edit , { range : [ [ 1 , 1 ] , [ 2 , 11 ] ] , newText : '' } ) ;
252273
253274 edit = new types . TextEdit ( range , null ) ;
254275 assert . equal ( edit . newText , '' ) ;
@@ -268,17 +289,60 @@ suite('PluginHostTypes', function() {
268289 edit . set ( a , [ types . TextEdit . insert ( new types . Position ( 0 , 0 ) , 'fff' ) ] ) ;
269290 assert . ok ( edit . has ( a ) ) ;
270291 assert . equal ( edit . size , 1 ) ;
292+ assertToJSON ( edit , [ [ 'file://a.ts' , [ { range : [ [ 0 , 0 ] , [ 0 , 0 ] ] , newText : 'fff' } ] ] ] ) ;
271293
272294 edit . insert ( b , new types . Position ( 1 , 1 ) , 'fff' ) ;
273295 edit . delete ( b , new types . Range ( 0 , 0 , 0 , 0 ) ) ;
274296 assert . ok ( edit . has ( b ) ) ;
275297 assert . equal ( edit . size , 2 ) ;
298+ assertToJSON ( edit , [
299+ [ 'file://a.ts' , [ { range : [ [ 0 , 0 ] , [ 0 , 0 ] ] , newText : 'fff' } ] ] ,
300+ [ 'file://b.ts' , [ { range : [ [ 1 , 1 ] , [ 1 , 1 ] ] , newText : 'fff' } , { range : [ [ 0 , 0 ] , [ 0 , 0 ] ] , newText : '' } ] ]
301+ ] ) ;
276302
277303 edit . set ( b , undefined ) ;
278304 assert . ok ( edit . has ( b ) ) ;
279305 assert . equal ( edit . size , 2 ) ;
280306
281307 edit . set ( b , [ types . TextEdit . insert ( new types . Position ( 0 , 0 ) , 'ffff' ) ] ) ;
282308 assert . equal ( edit . get ( b ) . length , 1 ) ;
309+
310+ } ) ;
311+
312+ test ( 'toJSON & stringify' , function ( ) {
313+
314+ assertToJSON ( new types . Selection ( 3 , 4 , 2 , 1 ) , { start : [ 2 , 1 ] , end : [ 3 , 4 ] , anchor : [ 3 , 4 ] , active : [ 2 , 1 ] } ) ;
315+
316+ assertToJSON ( new types . Location ( types . Uri . file ( 'u.ts' ) , new types . Range ( 1 , 2 , 3 , 4 ) ) , { uri : 'file://u.ts' , range : [ [ 1 , 2 ] , [ 3 , 4 ] ] } ) ;
317+ assertToJSON ( new types . Location ( types . Uri . file ( 'u.ts' ) , new types . Position ( 3 , 4 ) ) , { uri : 'file://u.ts' , range : [ [ 3 , 4 ] , [ 3 , 4 ] ] } ) ;
318+
319+ let diag = new types . Diagnostic ( new types . Range ( 0 , 1 , 2 , 3 ) , 'hello' ) ;
320+ assertToJSON ( diag , { severity : 'Error' , message : 'hello' , range : [ [ 0 , 1 ] , [ 2 , 3 ] ] } ) ;
321+ diag . source = 'me'
322+ assertToJSON ( diag , { severity : 'Error' , message : 'hello' , range : [ [ 0 , 1 ] , [ 2 , 3 ] ] , source : 'me' } ) ;
323+
324+ assertToJSON ( new types . DocumentHighlight ( new types . Range ( 2 , 3 , 4 , 5 ) ) , { range : [ [ 2 , 3 ] , [ 4 , 5 ] ] , kind : 'Text' } ) ;
325+ assertToJSON ( new types . DocumentHighlight ( new types . Range ( 2 , 3 , 4 , 5 ) , types . DocumentHighlightKind . Read ) , { range : [ [ 2 , 3 ] , [ 4 , 5 ] ] , kind : 'Read' } ) ;
326+
327+ assertToJSON ( new types . SymbolInformation ( 'test' , types . SymbolKind . Boolean , new types . Range ( 0 , 1 , 2 , 3 ) ) , {
328+ name : 'test' ,
329+ kind : 'Boolean' ,
330+ location : {
331+ range : [ [ 0 , 1 ] , [ 2 , 3 ] ]
332+ }
333+ } ) ;
334+
335+ assertToJSON ( new types . CodeLens ( new types . Range ( 7 , 8 , 9 , 10 ) ) , { range : [ [ 7 , 8 ] , [ 9 , 10 ] ] } ) ;
336+ assertToJSON ( new types . CodeLens ( new types . Range ( 7 , 8 , 9 , 10 ) , { command : 'id' , title : 'title' } ) , {
337+ range : [ [ 7 , 8 ] , [ 9 , 10 ] ] ,
338+ command : { command : 'id' , title : 'title' }
339+ } ) ;
340+
341+ assertToJSON ( new types . CompletionItem ( 'complete' ) , { label : 'complete' } ) ;
342+
343+ let item = new types . CompletionItem ( 'complete' ) ;
344+ item . kind = types . CompletionItemKind . Interface
345+ assertToJSON ( item , { label : 'complete' , kind : 'Interface' } ) ;
346+
283347 } ) ;
284348} ) ;
0 commit comments