@@ -13,8 +13,8 @@ var assert = require('assert');
1313var sorter = require ( '../lib/sort-json-core' ) ;
1414var JSON5 = require ( 'json5' ) ;
1515
16- suite ( 'Extension Tests' , function ( ) {
17- test ( 'normal js object asc' , function ( ) {
16+ suite ( 'Extension Tests' , function ( ) {
17+ test ( 'normal js object asc' , function ( ) {
1818 var jsObject = `{
1919 user: 'user',
2020 aaa: 'aaa',
@@ -35,7 +35,35 @@ suite('Extension Tests', function () {
3535 ) ;
3636 } ) ;
3737
38- test ( 'normal js object desc' , function ( ) {
38+ test ( 'Not js object' , function ( ) {
39+ var jsObject = `aaa: 1` ;
40+
41+ var result ;
42+ try {
43+ result = sorter . sort ( jsObject , 4 , JSON5 , [ 'asc' ] , { } ) ;
44+ } catch ( e ) {
45+ result = e ;
46+ }
47+
48+ assert . equal ( result , 'Please make sure your selected text is a JS obejct!' ) ;
49+ } ) ;
50+
51+ test ( 'Not js object 2' , function ( ) {
52+ var jsObject = `{test('normal js object desc', function() {
53+ var jsObject = '';
54+ }` ;
55+
56+ var result ;
57+ try {
58+ result = sorter . sort ( jsObject , 4 , JSON5 , [ 'asc' ] , { } ) ;
59+ } catch ( e ) {
60+ result = e ;
61+ }
62+
63+ assert . equal ( result , 'Please make sure your selected text is a JS obejct!' ) ;
64+ } ) ;
65+
66+ test ( 'normal js object desc' , function ( ) {
3967 var jsObject = `{
4068 user: 'user',
4169 aaa: 'aaa',
@@ -56,7 +84,7 @@ suite('Extension Tests', function () {
5684 ) ;
5785 } ) ;
5886
59- test ( 'normal js object indent 2' , function ( ) {
87+ test ( 'normal js object indent 2' , function ( ) {
6088 var jsObject = `{
6189 user: 'user',
6290 aaa: 'aaa',
@@ -77,7 +105,7 @@ suite('Extension Tests', function () {
77105 ) ;
78106 } ) ;
79107
80- test ( 'format js object' , function ( ) {
108+ test ( 'format js object' , function ( ) {
81109 var jsObject = `{
82110 user : 'user',
83111
@@ -99,7 +127,7 @@ suite('Extension Tests', function () {
99127 ) ;
100128 } ) ;
101129
102- test ( 'ES6 feature test' , function ( ) {
130+ test ( 'ES6 feature test' , function ( ) {
103131 var jsObject = `{
104132 user: 'user',
105133 aaa,
@@ -120,7 +148,7 @@ suite('Extension Tests', function () {
120148 ) ;
121149 } ) ;
122150
123- test ( 'Multi lines value test' , function ( ) {
151+ test ( 'Multi lines value test' , function ( ) {
124152 var jsObject = `{
125153 b: new String('b')
126154 .length,
@@ -138,7 +166,7 @@ suite('Extension Tests', function () {
138166 ) ;
139167 } ) ;
140168
141- test ( 'Auto add comma' , function ( ) {
169+ test ( 'Auto add comma' , function ( ) {
142170 var jsObject = `{
143171 b: 'b',
144172 a: 'a',
@@ -155,7 +183,7 @@ suite('Extension Tests', function () {
155183 ) ;
156184 } ) ;
157185
158- test ( 'Support line comments' , function ( ) {
186+ test ( 'Support line comments' , function ( ) {
159187 var jsObject = `{
160188 b: 2,
161189 // some comment
@@ -180,7 +208,7 @@ suite('Extension Tests', function () {
180208 ) ;
181209 } ) ;
182210
183- test ( 'Support line comments for indent 2' , function ( ) {
211+ test ( 'Support line comments for indent 2' , function ( ) {
184212 var jsObject = `{
185213 b: 2,
186214 // some comment
@@ -205,7 +233,7 @@ suite('Extension Tests', function () {
205233 ) ;
206234 } ) ;
207235
208- test ( 'Support line comments at the end of the object' , function ( ) {
236+ test ( 'Support line comments at the end of the object' , function ( ) {
209237 var jsObject = `{
210238 b: 2,
211239 // some comment
@@ -232,7 +260,7 @@ suite('Extension Tests', function () {
232260 ) ;
233261 } ) ;
234262
235- test ( "Support ' in string" , function ( ) {
263+ test ( "Support ' in string" , function ( ) {
236264 var jsObject = `{
237265 b: 'test \\'',
238266 c: 'test \\' test',
@@ -251,7 +279,7 @@ suite('Extension Tests', function () {
251279 ) ;
252280 } ) ;
253281
254- test ( 'Not change " in string ' , function ( ) {
282+ test ( 'Not change " in string ' , function ( ) {
255283 var jsObject = `{
256284 d: "\\" test",
257285 b: 'test " test',
@@ -274,7 +302,7 @@ suite('Extension Tests', function () {
274302 ) ;
275303 } ) ;
276304
277- test ( 'Support ES6 string key' , function ( ) {
305+ test ( 'Support ES6 string key' , function ( ) {
278306 var jsObject = `{
279307 'b': 'test',
280308 a: 1,
@@ -294,4 +322,4 @@ suite('Extension Tests', function () {
294322 }`
295323 ) ;
296324 } ) ;
297- } ) ;
325+ } ) ;
0 commit comments