@@ -25,9 +25,49 @@ describe('bson-csv', () => {
25
25
expect ( bsonCSV . Boolean . fromString ( 'true' ) ) . to . equal ( true ) ;
26
26
expect ( bsonCSV . Boolean . fromString ( 'TRUE' ) ) . to . equal ( true ) ;
27
27
} ) ;
28
+ it ( 'should serialize as a string' , ( ) => {
29
+ expect ( serialize ( { value : false } ) ) . to . deep . equal ( {
30
+ value : 'false'
31
+ } ) ;
32
+
33
+ expect ( serialize ( { value : true } ) ) . to . deep . equal ( {
34
+ value : 'true'
35
+ } ) ;
36
+ } ) ;
37
+ it ( 'should not auto-convert other values' , ( ) => {
38
+ expect ( serialize ( { value : 'false' } ) ) . to . deep . equal ( {
39
+ value : 'false'
40
+ } ) ;
41
+ expect ( serialize ( { value : 'FALSE' } ) ) . to . deep . equal ( {
42
+ value : 'FALSE'
43
+ } ) ;
44
+ expect ( serialize ( { value : 'true' } ) ) . to . deep . equal ( {
45
+ value : 'true'
46
+ } ) ;
47
+ expect ( serialize ( { value : 'TRUE' } ) ) . to . deep . equal ( {
48
+ value : 'TRUE'
49
+ } ) ;
50
+ expect ( serialize ( { value : '0' } ) ) . to . deep . equal ( {
51
+ value : '0'
52
+ } ) ;
53
+ expect ( serialize ( { value : '1' } ) ) . to . deep . equal ( {
54
+ value : '1'
55
+ } ) ;
56
+ } ) ;
28
57
} ) ;
29
58
describe ( 'Number' , ( ) => {
30
- it ( 'should work' , ( ) => {
59
+ it ( 'should serialize numbers as strings' , ( ) => {
60
+ expect ( serialize ( { value : 0 } ) ) . to . deep . equal ( {
61
+ value : '0'
62
+ } ) ;
63
+ expect ( serialize ( { value : 1 } ) ) . to . deep . equal ( {
64
+ value : '1'
65
+ } ) ;
66
+ expect ( serialize ( { value : - 1.35 } ) ) . to . deep . equal ( {
67
+ value : '-1.35'
68
+ } ) ;
69
+ } ) ;
70
+ it ( 'should deserialize numbers from strings' , ( ) => {
31
71
expect ( bsonCSV . Number . fromString ( '1' ) ) . to . equal ( 1 ) ;
32
72
} ) ;
33
73
} ) ;
@@ -47,29 +87,6 @@ describe('bson-csv', () => {
47
87
'Date of Transfer' : '2017-01-13T00:00:00Z'
48
88
} ) ;
49
89
} ) ;
50
- } ) ;
51
- describe ( 'Undefined' , ( ) => {
52
- it ( 'should serialize as a string' , ( ) => {
53
- expect ( serialize ( { value : undefined } ) ) . to . deep . equal ( {
54
- value : 'undefined'
55
- } ) ;
56
- } ) ;
57
- } ) ;
58
- describe ( 'Null' , ( ) => {
59
- it ( 'should serialize as a string' , ( ) => {
60
- expect ( serialize ( { value : null } ) ) . to . deep . equal ( {
61
- value : 'null'
62
- } ) ;
63
- } ) ;
64
- } ) ;
65
- describe ( 'RegExp' , ( ) => {
66
- it ( 'should serialize as a string' , ( ) => {
67
- expect ( serialize ( { value : / ^ m o n g o d b / } ) ) . to . deep . equal ( {
68
- value : '/^mongodb/'
69
- } ) ;
70
- } ) ;
71
- } ) ;
72
- describe ( 'Date' , ( ) => {
73
90
it ( 'should detect value:<Date> as Date' , ( ) => {
74
91
expect (
75
92
detectType ( new Date ( '2020-03-19T20:02:48.406Z' ) )
@@ -92,6 +109,27 @@ describe('bson-csv', () => {
92
109
} ) ;
93
110
} ) ;
94
111
} ) ;
112
+ describe ( 'Undefined' , ( ) => {
113
+ it ( 'should serialize as a string' , ( ) => {
114
+ expect ( serialize ( { value : undefined } ) ) . to . deep . equal ( {
115
+ value : 'undefined'
116
+ } ) ;
117
+ } ) ;
118
+ } ) ;
119
+ describe ( 'Null' , ( ) => {
120
+ it ( 'should serialize as a string' , ( ) => {
121
+ expect ( serialize ( { value : null } ) ) . to . deep . equal ( {
122
+ value : 'null'
123
+ } ) ;
124
+ } ) ;
125
+ } ) ;
126
+ describe ( 'RegExp' , ( ) => {
127
+ it ( 'should serialize as a string' , ( ) => {
128
+ expect ( serialize ( { value : / ^ m o n g o d b / } ) ) . to . deep . equal ( {
129
+ value : '/^mongodb/'
130
+ } ) ;
131
+ } ) ;
132
+ } ) ;
95
133
describe ( 'Array' , ( ) => {
96
134
it ( 'should serialize as a string of extended JSON' , ( ) => {
97
135
expect (
@@ -127,25 +165,6 @@ describe('bson-csv', () => {
127
165
} ) ;
128
166
} ) ;
129
167
} ) ;
130
- describe ( 'Boolean' , ( ) => {
131
- it ( 'should serialize as a string' , ( ) => {
132
- expect ( serialize ( { value : false } ) ) . to . deep . equal ( {
133
- value : 'false'
134
- } ) ;
135
-
136
- expect ( serialize ( { value : true } ) ) . to . deep . equal ( {
137
- value : 'true'
138
- } ) ;
139
- } ) ;
140
- it ( 'should serialize as normalized string' , ( ) => {
141
- expect ( serialize ( { value : 'FALSE' } ) ) . to . deep . equal ( {
142
- value : 'false'
143
- } ) ;
144
- expect ( serialize ( { value : 'TRUE' } ) ) . to . deep . equal ( {
145
- value : 'true'
146
- } ) ;
147
- } ) ;
148
- } ) ;
149
168
} ) ;
150
169
describe ( 'bson' , ( ) => {
151
170
describe ( 'ObjectID' , ( ) => {
0 commit comments