1
- import { assert } from "https://deno.land/[email protected] /_util/assert.ts" ;
2
1
import {
3
2
decodeBigint ,
4
3
decodeBigintArray ,
7
6
decodeBox ,
8
7
decodeCircle ,
9
8
decodeDate ,
9
+ decodeDatetime ,
10
10
decodeFloat ,
11
11
decodeInt ,
12
12
decodeJson ,
@@ -19,15 +19,15 @@ import {
19
19
import { assertEquals , assertThrows } from "./test_deps.ts" ;
20
20
21
21
Deno . test ( "decodeBigint" , function ( ) {
22
- assertEquals ( decodeBigint ( "18014398509481984" ) , 18014399223381984n ) ;
22
+ assertEquals ( decodeBigint ( "18014398509481984" ) , 18014398509481984n ) ;
23
23
} ) ;
24
24
25
25
Deno . test ( "decodeBigintArray" , function ( ) {
26
26
assertEquals (
27
27
decodeBigintArray (
28
- "{17365398509481972,9007199254740992,-10414398509481984}" ,
28
+ "{17365398509481972,9007199254740992,-10414398509481984}"
29
29
) ,
30
- [ 17365398509481972n , 9007199254740992n , - 10414398509481984n ] ,
30
+ [ 17365398509481972n , 9007199254740992n , - 10414398509481984n ]
31
31
) ;
32
32
} ) ;
33
33
@@ -50,19 +50,37 @@ Deno.test("decodeBoolean", function () {
50
50
51
51
Deno . test ( "decodeBooleanArray" , function ( ) {
52
52
assertEquals ( decodeBooleanArray ( "{True,0,T}" ) , [ true , false , true ] ) ;
53
- assertEquals ( decodeBooleanArray ( "{no,Y,1}" ) , [ false , false , false ] ) ;
53
+ assertEquals ( decodeBooleanArray ( "{no,Y,1}" ) , [ false , true , true ] ) ;
54
54
} ) ;
55
55
56
56
Deno . test ( "decodeBox" , function ( ) {
57
57
assertEquals ( decodeBox ( "(12.4,2),(33,4.33)" ) , {
58
58
a : { x : "12.4" , y : "2" } ,
59
59
b : { x : "33" , y : "4.33" } ,
60
60
} ) ;
61
-
61
+ let testValue = "(12.4,2)" ;
62
+ assertThrows (
63
+ ( ) => decodeBox ( testValue ) ,
64
+ Error ,
65
+ `Invalid Box: "${ testValue } ". Box must have only 2 point, 1 given.`
66
+ ) ;
67
+ testValue = "(12.4,2),(123,123,123),(9303,33)" ;
68
+ assertThrows (
69
+ ( ) => decodeBox ( testValue ) ,
70
+ Error ,
71
+ `Invalid Box: "${ testValue } ". Box must have only 2 point, 3 given.`
72
+ ) ;
73
+ testValue = "(0,0),(123,123,123)" ;
74
+ assertThrows (
75
+ ( ) => decodeBox ( testValue ) ,
76
+ Error ,
77
+ `Invalid Box: "${ testValue } " : Invalid Point: "(123,123,123)". Points must have only 2 coordinates, 3 given.`
78
+ ) ;
79
+ testValue = "(0,0),(100,r100)" ;
62
80
assertThrows (
63
- ( ) => decodeBox ( "(12.4,2)" ) ,
81
+ ( ) => decodeBox ( testValue ) ,
64
82
Error ,
65
- " Invalid Box value: `(12.4,2)`" ,
83
+ ` Invalid Box: " ${ testValue } " : Invalid Point: "(100,r100)". Coordinate "r100" must be a valid number.`
66
84
) ;
67
85
} ) ;
68
86
@@ -71,16 +89,32 @@ Deno.test("decodeCircle", function () {
71
89
point : { x : "12.4" , y : "2" } ,
72
90
radius : "3.5" ,
73
91
} ) ;
92
+ let testValue = "<(c21 23,2),3.5>" ;
93
+ assertThrows (
94
+ ( ) => decodeCircle ( testValue ) ,
95
+ Error ,
96
+ `Invalid Circle: "${ testValue } " : Invalid Point: "(c21 23,2)". Coordinate "c21 23" must be a valid number.`
97
+ ) ;
98
+ testValue = "<(33,2),mn23 3.5>" ;
99
+ assertThrows (
100
+ ( ) => decodeCircle ( testValue ) ,
101
+ Error ,
102
+ `Invalid Circle: "${ testValue } ". Circle radius "mn23 3.5" must be a valid number.`
103
+ ) ;
74
104
} ) ;
75
105
76
106
Deno . test ( "decodeDate" , function ( ) {
77
- assertEquals ( decodeDate ( "2021-08-01" ) , new Date ( "2021-08-01" ) ) ;
107
+ assertEquals ( decodeDate ( "2021-08-01" ) , new Date ( "2021-08-01 00:00:00-00 " ) ) ;
78
108
} ) ;
79
109
80
110
Deno . test ( "decodeDatetime" , function ( ) {
81
111
assertEquals (
82
- decodeDate ( "1997-12-17 07:37:16-08" ) ,
83
- new Date ( "1997-12-17 07:37:16-08" ) ,
112
+ decodeDatetime ( "2021-08-01" ) ,
113
+ new Date ( "2021-08-01 00:00:00-00" )
114
+ ) ;
115
+ assertEquals (
116
+ decodeDatetime ( "1997-12-17 07:37:16-08" ) ,
117
+ new Date ( "1997-12-17 07:37:16-08" )
84
118
) ;
85
119
} ) ;
86
120
@@ -97,31 +131,63 @@ Deno.test("decodeInt", function () {
97
131
Deno . test ( "decodeJson" , function ( ) {
98
132
assertEquals (
99
133
decodeJson (
100
- '{"key_1": "MY VALUE", "key_2": null, "key_3": 10, "key_4": {"subkey_1": true}}' ,
134
+ '{"key_1": "MY VALUE", "key_2": null, "key_3": 10, "key_4": {"subkey_1": true, "subkey_2": ["1",2] }}'
101
135
) ,
102
136
{
103
137
key_1 : "MY VALUE" ,
104
138
key_2 : null ,
105
139
key_3 : 10 ,
106
- key_4 : { subkey_1 : true } ,
107
- } ,
140
+ key_4 : { subkey_1 : true , subkey_2 : [ "1" , 2 ] } ,
141
+ }
108
142
) ;
109
- assertEquals ( decodeJson ( "{ 'eqw' ; ddd}" ) , null ) ;
143
+ assertThrows ( ( ) => decodeJson ( "{ 'eqw' ; ddd}" ) ) ;
110
144
} ) ;
111
145
112
146
Deno . test ( "decodeLine" , function ( ) {
113
- assertEquals ( decodeLine ( "{100,50,350}" ) , { a : "100" , b : "50" , c : "350" } ) ;
147
+ assertEquals ( decodeLine ( "{100,50,0}" ) , { a : "100" , b : "50" , c : "0" } ) ;
148
+ let testValue = "{100,50,0,100}" ;
149
+ assertThrows (
150
+ ( ) => decodeLine ( "{100,50,0,100}" ) ,
151
+ Error ,
152
+ `Invalid Line: "${ testValue } ". Line in linear equation format must have 3 constants, 4 given.`
153
+ ) ;
154
+ testValue = "{100,d3km,0}" ;
155
+ assertThrows (
156
+ ( ) => decodeLine ( testValue ) ,
157
+ Error ,
158
+ `Invalid Line: "${ testValue } ". Line constant "d3km" must be a valid number.`
159
+ ) ;
114
160
} ) ;
115
161
116
162
Deno . test ( "decodeLineSegment" , function ( ) {
117
163
assertEquals ( decodeLineSegment ( "((100,50),(350,350))" ) , {
118
164
a : { x : "100" , y : "50" } ,
119
165
b : { x : "350" , y : "350" } ,
120
166
} ) ;
167
+ let testValue = "((100,50),(r344,350))" ;
121
168
assertThrows (
122
- ( ) => decodeLineSegment ( "((100,50))" ) ,
169
+ ( ) => decodeLineSegment ( testValue ) ,
123
170
Error ,
124
- "Invalid LineSegment value: `((100,50))`" ,
171
+ `Invalid Line Segment: "${ testValue } " : Invalid Point: "(r344,350)". Coordinate "r344" must be a valid number.`
172
+
173
+ ) ;
174
+ testValue = "((100),(r344,350))" ;
175
+ assertThrows (
176
+ ( ) => decodeLineSegment ( testValue ) ,
177
+ Error ,
178
+ `Invalid Line Segment: "${ testValue } " : Invalid Point: "(100)". Points must have only 2 coordinates, 1 given.`
179
+ ) ;
180
+ testValue = "((100,50))" ;
181
+ assertThrows (
182
+ ( ) => decodeLineSegment ( testValue ) ,
183
+ Error ,
184
+ `Invalid Line Segment: "${ testValue } ". Line segments must have only 2 point, 1 given.`
185
+ ) ;
186
+ testValue = "((100,50),(350,350),(100,100))" ;
187
+ assertThrows (
188
+ ( ) => decodeLineSegment ( testValue ) ,
189
+ Error ,
190
+ `Invalid Line Segment: "${ testValue } ". Line segments must have only 2 point, 3 given.`
125
191
) ;
126
192
} ) ;
127
193
@@ -130,22 +196,56 @@ Deno.test("decodePath", function () {
130
196
{ x : "100" , y : "50" } ,
131
197
{ x : "350" , y : "350" } ,
132
198
] ) ;
199
+ assertEquals ( decodePath ( "[(1,10),(2,20),(3,30)]" ) , [
200
+ { x : "1" , y : "10" } ,
201
+ { x : "2" , y : "20" } ,
202
+ { x : "3" , y : "30" } ,
203
+ ] ) ;
204
+ let testValue = "((100,50),(350,kjf334))" ;
133
205
assertThrows (
134
- ( ) => decodePath ( "((100,50))" ) ,
206
+ ( ) => decodePath ( testValue ) ,
135
207
Error ,
136
- "Invalid Path value: `((100,50))`" ,
208
+ `Invalid Path: "${ testValue } " : Invalid Point: "(350,kjf334)". Coordinate "kjf334" must be a valid number.`
209
+ ) ;
210
+ testValue = "((100,50,9949))" ;
211
+ assertThrows (
212
+ ( ) => decodePath ( testValue ) ,
213
+ Error ,
214
+ `Invalid Path: "${ testValue } " : Invalid Point: "(100,50,9949)". Points must have only 2 coordinates, 3 given.`
137
215
) ;
138
216
} ) ;
139
217
140
218
Deno . test ( "decodePoint" , function ( ) {
141
- assertEquals ( decodePoint ( "(10.5,50.8)" ) , { x : "10.5" , y : "50.8" } ) ;
219
+ assertEquals ( decodePoint ( "(10.555,50.8)" ) , { x : "10.555" , y : "50.8" } ) ;
220
+ let testValue = "(1000)" ;
221
+ assertThrows (
222
+ ( ) => decodePoint ( testValue ) ,
223
+ Error ,
224
+ `Invalid Point: "${ testValue } ". Points must have only 2 coordinates, 1 given.`
225
+ ) ;
226
+ testValue = "(100.100,50,350)" ;
142
227
assertThrows (
143
- ( ) => decodePoint ( "(100.100,50,350)" ) ,
228
+ ( ) => decodePoint ( testValue ) ,
144
229
Error ,
145
- "Invalid Point value: `(100,50,350)`" ,
230
+ `Invalid Point: "${ testValue } ". Points must have only 2 coordinates, 3 given.`
231
+ ) ;
232
+ testValue = "(1,r344)" ;
233
+ assertThrows (
234
+ ( ) => decodePoint ( testValue ) ,
235
+ Error ,
236
+ `Invalid Point: "${ testValue } ". Coordinate "r344" must be a valid number.`
237
+ ) ;
238
+ testValue = "(cd 213ee,100)" ;
239
+ assertThrows (
240
+ ( ) => decodePoint ( testValue ) ,
241
+ Error ,
242
+ `Invalid Point: "${ testValue } ". Coordinate "cd 213ee" must be a valid number.`
146
243
) ;
147
244
} ) ;
148
245
149
246
Deno . test ( "decodeTid" , function ( ) {
150
- assertEquals ( decodeTid ( "(19714398509481984,5n)" ) , [ 19714398509481984n , 5n ] ) ;
247
+ assertEquals ( decodeTid ( "(19714398509481984,29383838509481984)" ) , [
248
+ 19714398509481984n ,
249
+ 29383838509481984n ,
250
+ ] ) ;
151
251
} ) ;
0 commit comments