@@ -58,10 +58,55 @@ suite("Extension Test Suite", () => {
58
58
assert . ok ( result . convertedText . includes ( '"age": 25' ) ) ;
59
59
} ) ;
60
60
61
- test ( "toJSON should handle invalid CSV" , async ( ) => {
62
- const invalidCsvText = "name,age\nJohn,30,\nJane,25" ;
63
- const result : ConversionResult = myExtension . toJSON ( invalidCsvText ) ;
64
- assert . strictEqual ( result . success , false ) ;
61
+ test ( "toCSV should handle empty JSON array" , async ( ) => {
62
+ const emptyJsonArray = "[]" ;
63
+ const result : ConversionResult = myExtension . toCSV ( emptyJsonArray ) ;
64
+ assert . strictEqual ( result . success , true ) ;
65
+ assert . strictEqual ( result . convertedLanguage , "csv" ) ;
66
+ assert . strictEqual ( result . convertedText , "" ) ;
67
+ } ) ;
68
+
69
+ test ( "toCSV should handle JSON with nested objects" , async ( ) => {
70
+ const nestedJson = '[{"name":"John","address":{"city":"New York"}}]' ;
71
+ const result : ConversionResult = myExtension . toCSV ( nestedJson ) ;
72
+ assert . strictEqual ( result . success , true ) ;
73
+ assert . strictEqual ( result . convertedLanguage , "csv" ) ;
74
+ assert . ok ( result . convertedText . includes ( "name,address.city" ) ) ;
75
+ assert . ok ( result . convertedText . includes ( "John,New York" ) ) ;
76
+ } ) ;
77
+
78
+ test ( "toJSON should handle CSV with missing values" , async ( ) => {
79
+ const csvWithMissingValues = "name,age\nJohn,\nJane,25" ;
80
+ const result : ConversionResult = myExtension . toJSON ( csvWithMissingValues ) ;
81
+ assert . strictEqual ( result . success , true ) ;
82
+ assert . strictEqual ( result . convertedLanguage , "json" ) ;
83
+ assert . ok ( result . convertedText . includes ( '"name": "John"' ) ) ;
84
+ assert . ok ( result . convertedText . includes ( '"age": null' ) ) ;
85
+ assert . ok ( result . convertedText . includes ( '"name": "Jane"' ) ) ;
86
+ assert . ok ( result . convertedText . includes ( '"age": 25' ) ) ;
87
+ } ) ;
88
+
89
+ test ( "toCSV should handle JSON with different data types" , async ( ) => {
90
+ const jsonWithDifferentTypes = '[{"name":"John","age":30,"isActive":true}]' ;
91
+ const result : ConversionResult = myExtension . toCSV ( jsonWithDifferentTypes ) ;
92
+ assert . strictEqual ( result . success , true ) ;
93
+ assert . strictEqual ( result . convertedLanguage , "csv" ) ;
94
+ assert . ok ( result . convertedText . includes ( "name,age,isActive" ) ) ;
95
+ assert . ok ( result . convertedText . includes ( "John,30,true" ) ) ;
96
+ } ) ;
97
+
98
+ test ( "toJSON should handle CSV with boolean values" , async ( ) => {
99
+ const csvWithBooleanValues =
100
+ "name,age,isActive\nJohn,30,true\nJane,25,false" ;
101
+ const result : ConversionResult = myExtension . toJSON ( csvWithBooleanValues ) ;
102
+ assert . strictEqual ( result . success , true ) ;
103
+ assert . strictEqual ( result . convertedLanguage , "json" ) ;
104
+ assert . ok ( result . convertedText . includes ( '"name": "John"' ) ) ;
105
+ assert . ok ( result . convertedText . includes ( '"age": 30' ) ) ;
106
+ assert . ok ( result . convertedText . includes ( '"isActive": true' ) ) ;
107
+ assert . ok ( result . convertedText . includes ( '"name": "Jane"' ) ) ;
108
+ assert . ok ( result . convertedText . includes ( '"age": 25' ) ) ;
109
+ assert . ok ( result . convertedText . includes ( '"isActive": false' ) ) ;
65
110
} ) ;
66
111
67
112
test ( "convertSelectedText should handle no active editor" , ( ) => {
0 commit comments