-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNeo-CSV-Tests.pck.st
More file actions
682 lines (605 loc) · 23 KB
/
Neo-CSV-Tests.pck.st
File metadata and controls
682 lines (605 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
'From Cuis7.0 [latest update: #6452] on 28 June 2024 at 11:55:38 am'!
'Description Please enter a description for this package'!
!provides: 'Neo-CSV-Tests' 1 3!
SystemOrganization addCategory: #'Neo-CSV-Tests'!
!classDefinition: #NeoCSVReaderTests category: #'Neo-CSV-Tests'!
TestCase subclass: #NeoCSVReaderTests
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Neo-CSV-Tests'!
!classDefinition: 'NeoCSVReaderTests class' category: #'Neo-CSV-Tests'!
NeoCSVReaderTests class
instanceVariableNames: ''!
!classDefinition: #NeoCSVWriterTests category: #'Neo-CSV-Tests'!
TestCase subclass: #NeoCSVWriterTests
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Neo-CSV-Tests'!
!classDefinition: 'NeoCSVWriterTests class' category: #'Neo-CSV-Tests'!
NeoCSVWriterTests class
instanceVariableNames: ''!
!classDefinition: #NeoNumberParserTests category: #'Neo-CSV-Tests'!
TestCase subclass: #NeoNumberParserTests
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Neo-CSV-Tests'!
!classDefinition: 'NeoNumberParserTests class' category: #'Neo-CSV-Tests'!
NeoNumberParserTests class
instanceVariableNames: ''!
!classDefinition: #NeoCSVTestObject category: #'Neo-CSV-Tests'!
Object subclass: #NeoCSVTestObject
instanceVariableNames: 'x y z'
classVariableNames: ''
poolDictionaries: ''
category: 'Neo-CSV-Tests'!
!classDefinition: 'NeoCSVTestObject class' category: #'Neo-CSV-Tests'!
NeoCSVTestObject class
instanceVariableNames: ''!
!NeoCSVReaderTests commentStamp: '<historical>' prior: 0!
I am NeoCSVReaderTests, a suite of unit tests for NeoCSVReader.
!
!NeoCSVWriterTests commentStamp: '<historical>' prior: 0!
I am NeoCSVWriterTests, a suite of unit tests for NeoCSVWriter.
!
!NeoNumberParserTests commentStamp: '<historical>' prior: 0!
I am NeoNumberParserTests the unit test suite for NeoNumberParser.!
!NeoCSVTestObject commentStamp: '<historical>' prior: 0!
I am NeoCSVTestObject.!
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 1/14/2014 23:20'!
testEmbeddedQuotes
self
assert: (NeoCSVReader on: '1,"x""y""z",3' readStream) upToEnd
equals: #(('1' 'x"y"z' '3'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:41:59'!
testEmptyConversions
| input |
input := (String crlfString join: #( '1,2.5,foo' ',,' )).
self
assert: ((NeoCSVReader on: input readStream)
addIntegerField;
addFloatField;
addField;
upToEnd)
equals: {
#( 1 2.5 'foo' ).
#( nil nil nil ) }! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:42:11'!
testEmptyConversionsTestObject
| input |
input := (String crlfString join: #( '1,2.5,foo' ',,' )).
self
assert: ((NeoCSVReader on: input readStream)
recordClass: NeoCSVTestObject;
addIntegerField: #x: ;
addFloatField: #y: ;
addField: #z: ;
upToEnd)
equals: {
NeoCSVTestObject x: 1 y: 2.5 z: 'foo'.
NeoCSVTestObject new }! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 5/13/2014 14:46'!
testEmptyFieldQuoted
self
assert: (NeoCSVReader on: '"1",,"3"' readStream) upToEnd
equals: #(('1' nil '3'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:47:01'!
testEmptyFieldSecondRecordQuoted
self
assert: (NeoCSVReader on: '"foo","bar"\"100",' withNewLines readStream) upToEnd
equals: #(('foo' 'bar')('100' nil))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:47:26'!
testEmptyFieldSecondRecordUnquoted
self
assert: (NeoCSVReader on: 'foo,bar\100,' withNewLines readStream) upToEnd
equals: #(('foo' 'bar')('100' nil))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 5/13/2014 14:47'!
testEmptyFieldUnquoted
self
assert: (NeoCSVReader on: '1,,3' readStream) upToEnd
equals: #(('1' nil '3'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:47:32'!
testEmptyFieldValue
self
assert: ((NeoCSVReader on: '"1",,3,"","5"' readStream)
emptyFieldValue: #empty;
upToEnd)
equals: #(('1' empty '3' empty '5')).
self
assert: ((NeoCSVReader on: '"1",,3,"","5"' readStream)
emptyFieldValue: '';
upToEnd)
equals: #(('1' '' '3' '' '5')).
self
assert: ((NeoCSVReader on: 'a,b,c\,,\"","",""\1,2,3\' withNewLines readStream)
emptyFieldValue: #empty;
upToEnd)
equals: #(('a' 'b' 'c')(empty empty empty)(empty empty empty)('1' '2' '3'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 5/13/2014 14:47'!
testEmptyLastFieldQuoted
self
assert: (NeoCSVReader on: '"1","2",""' readStream) upToEnd
equals: #(('1' '2' nil))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 5/13/2014 10:57'!
testEmptyLastFieldUnquoted
self
assert: (NeoCSVReader on: '1,2,' readStream) upToEnd
equals: #(('1' '2' nil))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:48:06'!
testNamedColumnsConfiguration
| input |
input := String crlfString join: #( '"x","y","z"' '100,200,300' '100,200,300' '100,200,300' '').
self
assert: ((NeoCSVReader on: input readStream)
namedColumnsConfiguration;
upToEnd)
equals: {
Dictionary newFromPairs: #(x '100' y '200' z '300').
Dictionary newFromPairs: #(x '100' y '200' z '300').
Dictionary newFromPairs: #(x '100' y '200' z '300') }! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 6/14/2012 19:57'!
testOneLineEmpty
self
assert: (NeoCSVReader on: '' readStream) upToEnd
equals: #()! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 6/14/2012 19:56'!
testOneLineOneFieldQuoted
self
assert: (NeoCSVReader on: '"1"' readStream) upToEnd
equals: #(('1'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 6/14/2012 19:55'!
testOneLineOneFieldUnquoted
self
assert: (NeoCSVReader on: '1' readStream) upToEnd
equals: #(('1'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 6/14/2012 18:58'!
testOneLineQuoted
self
assert: (NeoCSVReader on: '"1","2","3"' readStream) upToEnd
equals: #(('1' '2' '3'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 6/14/2012 18:57'!
testOneLineUnquoted
self
assert: (NeoCSVReader on: '1,2,3' readStream) upToEnd
equals: #(('1' '2' '3'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:48:13'!
testReadAsByteArrays
| input |
input := (String crlfString join: #( '1,2,3' '1,2,3' '1,2,3' '')).
self
assert: ((NeoCSVReader on: input readStream)
recordClass: ByteArray;
addIntegerField;
addIntegerField ;
addIntegerField;
upToEnd)
equals: {
#[1 2 3].
#[1 2 3].
#[1 2 3].}! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:48:21'!
testReadAsIntegerArrays
| input |
input := (String crlfString join: #( '100,200,300' '100,200,300' '100,200,300' '')).
self
assert: ((NeoCSVReader on: input readStream)
recordClass: IntegerArray;
addIntegerField;
addIntegerField ;
addIntegerField;
upToEnd)
equals: {
#(100 200 300) asIntegerArray.
#(100 200 300) asIntegerArray.
#(100 200 300) asIntegerArray }! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:48:25'!
testReadDictionaries
| input |
input := String crlfString join: #( '"x","y","z"' '100,200,300' '100,200,300' '100,200,300' '').
self
assert: ((NeoCSVReader on: input readStream)
skipHeader;
recordClass: Dictionary;
addIntegerFieldAt: #x ;
addIntegerFieldAt: #y ;
addIntegerFieldAt: #z ;
upToEnd)
equals: {
Dictionary newFromPairs: #(x 100 y 200 z 300).
Dictionary newFromPairs: #(x 100 y 200 z 300).
Dictionary newFromPairs: #(x 100 y 200 z 300) }! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:48:30'!
testReadHeader
| input |
input := (String crlfString join: #( '"x","y","z"' '100,200,300' '100,200,300' '100,200,300' '')).
self
assert: (NeoCSVReader on: input readStream) readHeader
equals: #('x' 'y' 'z')! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 7/23/2023 13:07:44'!
testReadHeaderUnicode
| input |
input := (UnicodeString newFrom: 'x,y,z
100,200,300
100,200,300
100,200,300').
self
assert: (NeoCSVReader on: input readStream) readHeader
equals: #('x' 'y' 'z')! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:48:34'!
testReadIntegers
| input |
input := (String crlfString join: #( '"x","y","z"' '100,200,300' '100,200,300' '100,200,300' '')).
self
assert: ((NeoCSVReader on: input readStream)
skipHeader;
addIntegerField;
addIntegerField ;
addIntegerField;
upToEnd)
equals: #((100 200 300)(100 200 300)(100 200 300))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:48:39'!
testReadIntegersReadingHeaderAfterFieldDefinitions
| input |
input := (String crlfString join: #( '"x","y","z"' '100,200,300' '100,200,300' '100,200,300' '')).
self
assert: ((NeoCSVReader on: input readStream)
addIntegerField;
addIntegerField ;
addIntegerField;
skipHeader;
upToEnd)
equals: #((100 200 300)(100 200 300)(100 200 300))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:48:46'!
testReadTestsObjects
| input |
input := (String crlfString join: #( '"x","y","z"' '100,200,300' '100,200,300' '100,200,300' '')).
self
assert: ((NeoCSVReader on: input readStream)
skipHeader;
recordClass: NeoCSVTestObject;
addIntegerField: #x: ;
addIntegerField: #y: ;
addIntegerField: #z: ;
upToEnd)
equals: {
NeoCSVTestObject example.
NeoCSVTestObject example.
NeoCSVTestObject example }! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:48:51'!
testReadTestsObjectsUsingBlockAccessors
| input |
input := (String crlfString join: #( '"x","y","z"' '100,200,300' '100,200,300' '100,200,300' '')).
self
assert: ((NeoCSVReader on: input readStream)
skipHeader;
recordClass: NeoCSVTestObject;
addIntegerField: [ :object :value | object x: value ];
addIntegerField: [ :object :value | object y: value ];
addIntegerField: [ :object :value | object z: value ];
upToEnd)
equals: {
NeoCSVTestObject example.
NeoCSVTestObject example.
NeoCSVTestObject example }! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:48:56'!
testReadTestsObjectsWithIgnoredField
| input |
input := (String crlfString join: #( '"x","y",''-'',"z"' '100,200,a,300' '100,200,b,300' '100,200,c,300' '')).
self
assert: ((NeoCSVReader on: input readStream)
skipHeader;
recordClass: NeoCSVTestObject;
addIntegerField: #x: ;
addIntegerField: #y: ;
addIgnoredField;
addIntegerField: #z: ;
upToEnd)
equals: {
NeoCSVTestObject example.
NeoCSVTestObject example.
NeoCSVTestObject example }! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:49:01'!
testReadWithIgnoredField
| input |
input := (String crlfString join: #( '1,2,a,3' '1,2,b,3' '1,2,c,3' '')).
self
assert: ((NeoCSVReader on: input readStream)
addIntegerField;
addIntegerField;
addIgnoredField;
addIntegerField;
upToEnd)
equals: {
#(1 2 3).
#(1 2 3).
#(1 2 3).}! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:49:05'!
testSimpleCrLfQuoted
| input |
input := (String crlfString join: #('"1","2","3"' '"4","5","6"' '"7","8","9"' '')).
self
assert: (NeoCSVReader on: input readStream) upToEnd
equals: #(('1' '2' '3')('4' '5' '6')('7' '8' '9'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:49:19'!
testSimpleCrLfUnquoted
| input |
input := (String crlfString join: #('1,2,3' '4,5,6' '7,8,9' '')).
self
assert: (NeoCSVReader on: input readStream) upToEnd
equals: #(('1' '2' '3')('4' '5' '6')('7' '8' '9'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:49:25'!
testSimpleCrQuoted
| input |
input := (String crString join: #('"1","2","3"' '"4","5","6"' '"7","8","9"' '')).
self
assert: (NeoCSVReader on: input readStream) upToEnd
equals: #(('1' '2' '3')('4' '5' '6')('7' '8' '9'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:49:57'!
testSimpleCrUnquoted
| input |
input := (String crString join: #('1,2,3' '4,5,6' '7,8,9' '')).
self
assert: (NeoCSVReader on: input readStream) upToEnd
equals: #(('1' '2' '3')('4' '5' '6')('7' '8' '9'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:50:02'!
testSimpleLfQuoted
| input |
input := (String lfString join: #('"1","2","3"' '"4","5","6"' '"7","8","9"' '')).
self
assert: (NeoCSVReader on: input readStream) upToEnd
equals: #(('1' '2' '3')('4' '5' '6')('7' '8' '9'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:50:07'!
testSimpleLfUnquoted
| input |
input := (String lfString join: #('1,2,3' '4,5,6' '7,8,9' '')).
self
assert: (NeoCSVReader on: input readStream) upToEnd
equals: #(('1' '2' '3')('4' '5' '6')('7' '8' '9'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:50:12'!
testSimpleSemiColonDelimited
| input |
input := (String crlfString join: #('1;2;3' '4;5;6' '7;8;9' '')).
self
assert: ((NeoCSVReader on: input readStream)
separator: $; ;
upToEnd)
equals: #(('1' '2' '3')('4' '5' '6')('7' '8' '9'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:50:16'!
testSimpleTabDelimited
| input |
input := (String crlfString join: #('1 2 3' '4 5 6' '7 8 9' '')).
self
assert: ((NeoCSVReader on: input readStream)
separator: Character tab ;
upToEnd)
equals: #(('1' '2' '3')('4' '5' '6')('7' '8' '9'))! !
!NeoCSVReaderTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:50:52'!
testSkippingEmptyRecords
| input output |
input := '1,2,3\\4,5,6\,,\7,8,9' withNewLines.
output := (NeoCSVReader on: input readStream)
select: [ :each | each notEmpty and: [ (each allSatisfy: #isNil) not ] ].
self assert: output equals: #(#('1' '2' '3') #('4' '5' '6') #('7' '8' '9')).
output := (NeoCSVReader on: input readStream)
emptyFieldValue: '';
select: [ :each | each notEmpty and: [ (each allSatisfy: #isEmpty) not ] ].
self assert: output equals: #(#('1' '2' '3') #('4' '5' '6') #('7' '8' '9'))! !
!NeoCSVWriterTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:51:06'!
testEmptyFieldValue
self
assert: (String streamContents: [ :stream |
(NeoCSVWriter on: stream)
nextPut: #(one two three);
nextPutAll: #( (1 2 nil) (4 nil 6) (nil 8 9)) ])
equals: (String crlfString join: #( '"one","two","three"' '"1","2",""' '"4","","6"' '"","8","9"' '')).
self
assert: (String streamContents: [ :stream |
(NeoCSVWriter on: stream)
emptyFieldValue: #empty;
nextPut: #(one two three);
nextPutAll: #( (1 2 empty) (4 empty 6) (empty 8 9)) ])
equals: (String crlfString join: #( '"one","two","three"' '"1","2",""' '"4","","6"' '"","8","9"' '')).
self
assert: (String streamContents: [ :stream |
(NeoCSVWriter on: stream)
emptyFieldValue: Object new;
nextPut: #(one two three);
nextPutAll: #( (1 2 nil) (4 nil 6) (nil 8 9)) ])
equals: (String crlfString join: #( '"one","two","three"' '"1","2","nil"' '"4","nil","6"' '"nil","8","9"' ''))! !
!NeoCSVWriterTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:51:10'!
testNamedColumnsConfiguration
self
assert: (String streamContents: [ :stream |
(NeoCSVWriter on: stream)
namedColumnsConfiguration: #(x y z);
nextPutAll: {
Dictionary newFromPairs: #(x 100 y 200 z 300).
Dictionary newFromPairs: #(x 400 y 500 z 600).
Dictionary newFromPairs: #(x 700 y 800 z 900) } ])
equals: (String crlfString join: #( '"x","y","z"' '"100","200","300"' '"400","500","600"' '"700","800","900"' ''))! !
!NeoCSVWriterTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:51:16'!
testObjectFieldsTestObjects
self
assert: (String streamContents: [ :stream |
(NeoCSVWriter on: stream)
nextPut: #(x y z);
addObjectFields: #(x y z);
nextPutAll: {
NeoCSVTestObject example.
NeoCSVTestObject example.
NeoCSVTestObject example } ])
equals: (String crlfString join: #( '"x","y","z"' '100,200,300' '100,200,300' '100,200,300' ''))! !
!NeoCSVWriterTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:51:23'!
testObjectFieldsTestObjectsExtra
self
assert: (String streamContents: [ :stream |
(NeoCSVWriter on: stream)
fieldWriter: #raw;
nextPut: #(x empty y constant z);
addObjectField: #x;
addEmptyField;
addObjectField: #y;
addConstantField: 'X';
addObjectField: #z;
nextPutAll: {
NeoCSVTestObject example.
NeoCSVTestObject example.
NeoCSVTestObject example } ])
equals: (String crlfString join: #(
'x,empty,y,constant,z'
'100,,200,X,300'
'100,,200,X,300'
'100,,200,X,300' ''))! !
!NeoCSVWriterTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:51:28'!
testObjectFieldsTestObjectsUsingBlockAccessors
self
assert: (String streamContents: [ :stream |
(NeoCSVWriter on: stream)
nextPut: #(x y z);
addObjectFields: {
[ :object | object x ].
[ :object | object y ].
[ :object | object z ] };
nextPutAll: {
NeoCSVTestObject example.
NeoCSVTestObject example.
NeoCSVTestObject example } ])
equals: (String crlfString join: #( '"x","y","z"' '100,200,300' '100,200,300' '100,200,300' ''))! !
!NeoCSVWriterTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:51:32'!
testRawFieldsDictionaries
self
assert: (String streamContents: [ :stream |
(NeoCSVWriter on: stream)
nextPut: #(x y z);
addRawFieldsAt: #(x y z);
nextPutAll: {
Dictionary newFromPairs: #(x 100 y 200 z 300).
Dictionary newFromPairs: #(x 400 y 500 z 600).
Dictionary newFromPairs: #(x 700 y 800 z 900) } ])
equals: (String crlfString join: #( '"x","y","z"' '100,200,300' '400,500,600' '700,800,900' ''))! !
!NeoCSVWriterTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:51:37'!
testRawFieldsTestObjects
self
assert: (String streamContents: [ :stream |
(NeoCSVWriter on: stream)
nextPut: #(x y z);
addRawFields: #(x y z);
nextPutAll: {
NeoCSVTestObject example.
NeoCSVTestObject example.
NeoCSVTestObject example } ])
equals: (String crlfString join: #( '"x","y","z"' '100,200,300' '100,200,300' '100,200,300' ''))! !
!NeoCSVWriterTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:51:41'!
testSimple
self
assert: (String streamContents: [ :stream |
(NeoCSVWriter on: stream)
nextPut: #(one two three);
nextPutAll: #( (1 2 3) (4 5 6) (7 8 9)) ])
equals: (String crlfString join: #( '"one","two","three"' '"1","2","3"' '"4","5","6"' '"7","8","9"' ''))! !
!NeoCSVWriterTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:51:46'!
testSimpleRaw
self
assert: (String streamContents: [ :stream |
(NeoCSVWriter on: stream)
fieldWriter: #raw;
nextPut: #(one two three);
nextPutAll: #( (1 2 3) (4 5 6) (7 8 9)) ])
equals: (String crlfString join: #( 'one,two,three' '1,2,3' '4,5,6' '7,8,9' ''))! !
!NeoCSVWriterTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:51:54'!
testWriteEmbeddedQuote
| header |
header := String streamContents: [ :out |
(NeoCSVWriter on: out)
nextPut: #(foo 'x"y"z') ].
self assert: header equals: '"foo","x""y""z"', String crlfString ! !
!NeoCSVWriterTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:52:02'!
testWriteHeader
| header |
header := String streamContents: [ :out |
(NeoCSVWriter on: out)
writeHeader: #(foo bar) ].
self assert: header equals: '"foo","bar"', String crlfString ! !
!NeoNumberParserTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 12/2/2012 17:02'!
testBinaryIntegers
self assert: (NeoNumberParser parse: '1111011' base: 2) equals: 123.
self assert: (NeoNumberParser parse: '-1111011' base: 2) equals: -123.
self assert: (NeoNumberParser parse: '0' base: 2) equals: 0.
! !
!NeoNumberParserTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 12/2/2012 17:03'!
testDecimalIntegers
self assert: (NeoNumberParser parse: '123') equals: 123.
self assert: (NeoNumberParser parse: '-123') equals: -123.
self assert: (NeoNumberParser parse: '0') equals: 0.
self assert: (NeoNumberParser parse: '12345678901234567890') equals: 12345678901234567890.
self assert: (NeoNumberParser parse: '00123ABC') equals: 123.
self assert: (NeoNumberParser parse: '-0') equals: 0.
! !
!NeoNumberParserTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 12/2/2012 17:42'!
testErrors
self should: [ NeoNumberParser parse: nil ] raise: Error.
self should: [ NeoNumberParser parse: '' ] raise: Error.
self should: [ NeoNumberParser parse: '.5' ] raise: Error.! !
!NeoNumberParserTests methodsFor: 'testing' stamp: 'hlsf 6/28/2024 11:55:26'!
testFloats
#('1.5' 1.5 '-1.5' -1.5 '0.0' 0.0 '3.14159' 3.14159 '1e3' 1000.0 '1e-2' 0.01)
pairsDo: [ :string :float |
self assert: (((NeoNumberParser parse: string) - float)) abs < 1e-10 ]! !
!NeoNumberParserTests methodsFor: 'testing' stamp: 'hjh 5/14/2015 20:06'!
testHexadecimalIntegers
self assert: (NeoNumberParser parse: '7B' base: 16) equals: 123.
"self assert: (NeoNumberParser parse: '7b' base: 16) equals: 123."
self assert: (NeoNumberParser parse: '-7B' base: 16) equals: -123.
"self assert: (NeoNumberParser parse: '-7b' base: 16) equals: -123."
self assert: (NeoNumberParser parse: '0' base: 16) equals: 0.
! !
!NeoNumberParserTests methodsFor: 'testing' stamp: 'SvenVanCaekenberghe 12/2/2012 17:02'!
testOctalIntegers
self assert: (NeoNumberParser parse: '173' base: 8) equals: 123.
self assert: (NeoNumberParser parse: '-173' base: 8) equals: -123.
self assert: (NeoNumberParser parse: '0' base: 8) equals: 0.
! !
!NeoCSVTestObject methodsFor: 'comparing' stamp: 'SvenVanCaekenberghe 6/16/2012 18:58'!
= anObject
self == anObject
ifTrue: [ ^ true ].
self class = anObject class
ifFalse: [ ^ false ].
^ x = anObject x
and: [
y = anObject y
and: [
z = anObject z ] ]! !
!NeoCSVTestObject methodsFor: 'comparing' stamp: 'SvenVanCaekenberghe 6/16/2012 18:58'!
hash
^ x hash bitXor: (y hash bitXor: z)! !
!NeoCSVTestObject methodsFor: 'accessing' stamp: 'SvenVanCaekenberghe 6/15/2012 22:40'!
x
^ x! !
!NeoCSVTestObject methodsFor: 'accessing' stamp: 'SvenVanCaekenberghe 6/15/2012 22:40'!
x: anObject
x := anObject! !
!NeoCSVTestObject methodsFor: 'accessing' stamp: 'SvenVanCaekenberghe 6/15/2012 22:40'!
y
^ y! !
!NeoCSVTestObject methodsFor: 'accessing' stamp: 'SvenVanCaekenberghe 6/15/2012 22:40'!
y: anObject
y := anObject! !
!NeoCSVTestObject methodsFor: 'accessing' stamp: 'SvenVanCaekenberghe 6/15/2012 22:40'!
z
^ z! !
!NeoCSVTestObject methodsFor: 'accessing' stamp: 'SvenVanCaekenberghe 6/15/2012 22:40'!
z: anObject
z := anObject! !
!NeoCSVTestObject class methodsFor: 'instance creation' stamp: 'SvenVanCaekenberghe 11/4/2012 19:40'!
example
^ self x: 100 y: 200 z: 300! !
!NeoCSVTestObject class methodsFor: 'instance creation' stamp: 'SvenVanCaekenberghe 11/4/2012 19:39'!
x: x y: y z: z
^ self new
x: x;
y: y;
z: z;
yourself! !