summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/webtbs/tw19610.pp
blob: fe60d85d7a1243b26d1a5de95f34b76dfb23d184 (plain)
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
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
{ Source provided for Free Pascal bug report 19610 }
{ Submitted by Reinier Olislagers on 20120920 }
{
Note: the tests here are somewhat more extensive than the original bug report.
They are aimed at confirming interoperability between Delphi and FPC sdf formats
The basis for the tests is therefore Delphi's handling.

The only exception are the Put tests, which also accept results that are always
quoted. As Get_StrictDelimTrueSafeQuote and Get_StrictDelimFalseSafeQuote prove,
always quoting output leads to correct/the same input.
The advantage of this is that having strictdelimiter on or off does not matter
and the output format is more unambiguous (i.e. more compatible with RFC4180
for CSV).

On Delphi, rename to .dpr.

Tests successfully completed on:
Turbo Delphi 2006 (Reinier Olislagers)
Delphi 2007 (OBones)
Delphi XE (Marco van de Voort, OBones)
Delphi XE2 Win32 (OBones)
Delphi XE2 Win64 (OBones)
}
{
    This file is part of the Free Pascal packages.
    Copyright (c) 1999-2012 by the Free Pascal development team

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}
{$apptype console}
{$ifdef fpc}
  {$mode objfpc}{$H+}
{$endif fpc}
program tw19610;

uses Classes, SysUtils;

{$ifndef fpc}
//Delphi
const
  LineEnding=#13+#10;
{$endif}

function Get_StrictDelimFalse:boolean;
// Test if input works with Delphi-compatible sdf output
// Strictdelimiter:=false (default) when processing the delimitedtext
//
// Mainly check if reading quotes is according to Delphi sdf specs and works.
// Based on del4.zip in bug 19610
const
  // Matches del4.zip in bug 19610:
  DelimText='normal_string;"quoted_string";"quoted;delimiter";"quoted and space";"""quoted_and_starting_quote";"""quoted, starting quote, and space";"quoted_with_tab'+#9+'character";"quoted_multi'+LineEnding+
    'line";  UnquotedSpacesInfront;UnquotedSpacesAtTheEnd   ;  "Spaces before quoted string"';
  TestName='tw19610.Get_StrictDelimFalse';
var
  TestSL: TStringList;
  Expected: TStringList;
  i: integer;
begin
  result:=true;
  //Expected values:
  Expected:=TStringList.Create;
  TestSL:=TStringList.Create;
  try
    Expected.Add('normal_string');
    Expected.Add('quoted_string');
    Expected.Add('quoted;delimiter');
    Expected.Add('quoted and space');
    Expected.Add('"quoted_and_starting_quote');
    Expected.Add('"quoted, starting quote, and space');
    Expected.Add('quoted_with_tab'+#9+'character');
    Expected.Add('quoted_multi'+LineEnding+
      'line');
    Expected.Add('UnquotedSpacesInfront');
    Expected.Add('UnquotedSpacesAtTheEnd');
    Expected.Add('Spaces before quoted string');

    TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
    TestSL.StrictDelimiter:=false;
    TestSL.DelimitedText:=DelimText;
    //Test:
    if Expected.Count<>TestSL.Count then
    begin
      writeln('');
      writeln(TestName+': failed: count mismatch: '+
      inttostr(TestSL.Count)+' test strings; '+inttostr(Expected.Count)+' expected strings.');
    end;

    for i:=0 to TestSL.Count-1 do
    begin
      if (Expected.Count>i) and (TestSL[i]<>Expected[i]) then
      begin
        writeln('');
        writeln(TestName+': failed: result:');
        writeln('*'+TestSL[i]+'*');
        writeln('while expected was:');
        writeln('*'+Expected[i]+'*');
        result:=false;
      end;
    end;
  finally
    Expected.Free;
    TestSL.Free;
  end;
end;

function Get_StrictDelimTrue:boolean;
// Test if input works with Delphi-compatible sdf output
// Strictdelimiter:=true when processing the delimitedtext
//
// Mainly check if reading quotes is according to Delphi sdf specs and works.
// Based on del4.zip in bug 19610
const
  // Matches del4.zip in bug 19610:
  DelimText='normal_string;"quoted_string";"quoted;delimiter";"quoted and space";"""quoted_and_starting_quote";"""quoted, starting quote, and space";"quoted_with_tab'+#9+'character";"quoted_multi'+LineEnding+
    'line";  UnquotedSpacesInfront;UnquotedSpacesAtTheEnd   ;  "Spaces before quoted string"';
  TestName='tw19610.Get_StrictDelimTrue';
var
  TestSL: TStringList;
  Expected: TStringList;
  i: integer;
begin
  result:=true;
  //Expected values:
  Expected:=TStringList.Create;
  TestSL:=TStringList.Create;
  try
    Expected.Add('normal_string');
    Expected.Add('quoted_string');
    Expected.Add('quoted;delimiter');
    Expected.Add('quoted and space');
    Expected.Add('"quoted_and_starting_quote');
    Expected.Add('"quoted, starting quote, and space');
    Expected.Add('quoted_with_tab'+#9+'character');
    Expected.Add('quoted_multi'+LineEnding+
      'line');
    Expected.Add('  UnquotedSpacesInfront');
    Expected.Add('UnquotedSpacesAtTheEnd   ');
    Expected.Add('  "Spaces before quoted string"');

    TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
    TestSL.StrictDelimiter:=true;
    TestSL.DelimitedText:=DelimText;
    //Test:
    if Expected.Count<>TestSL.Count then
    begin
      writeln('');
      writeln(TestName+': failed: count mismatch: '+
      inttostr(TestSL.Count)+' test strings; '+inttostr(Expected.Count)+' expected strings.');
    end;
    for i:=0 to TestSL.Count-1 do
    begin
      if (Expected.Count>i) and (TestSL[i]<>Expected[i]) then
      begin
        writeln('');
        writeln(TestName+': failed: result:');
        writeln('*'+TestSL[i]+'*');
        writeln('while expected was:');
        writeln('*'+Expected[i]+'*');
        result:=false;
      end;
    end;
  finally
    Expected.Free;
    TestSL.Free;
  end;
end;

function Get_StrictDelimFalseCornerCases:boolean;
// Test if input works with Delphi-compatible sdf output
// Strictdelimiter:=false (default) when processing the delimitedtext
//
// Has some corner cases that Delphi produces but are not evident from their
// documentation
// Based on del4.zip in bug 19610
const
  // Matches del4.zip in bug 19610:
  DelimText='"Spaces after quoted string"   ;';
  TestName='tw19610.Get_StrictDelimFalseCornerCases';
var
  TestSL: TStringList;
  Expected: TStringList;
  i: integer;
begin
  result:=true;
  //Expected values:
  Expected:=TStringList.Create;
  TestSL:=TStringList.Create;
  try
    Expected.Add('Spaces after quoted string');
    Expected.Add('');

    TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
    TestSL.StrictDelimiter:=false;
    TestSL.DelimitedText:=DelimText;
    //Test:
    if Expected.Count<>TestSL.Count then
    begin
      writeln('');
      writeln(TestName+': failed: count mismatch: '+
      inttostr(TestSL.Count)+' test strings; '+inttostr(Expected.Count)+' expected strings.');
    end;
    for i:=0 to TestSL.Count-1 do
    begin
      if (Expected.Count>i) and (TestSL[i]<>Expected[i]) then
      begin
        writeln('');
        writeln(TestName+': failed: result:');
        writeln('*'+TestSL[i]+'*');
        writeln('while expected was:');
        writeln('*'+Expected[i]+'*');
        result:=false;
      end;
    end;
  finally
    Expected.Free;
    TestSL.Free;
  end;
end;

function Get_StrictDelimTrueCornerCases:boolean;
// Test if input works with Delphi-compatible sdf output
// Strictdelimiter:=true when processing the delimitedtext
//
// Has some corner cases that Delphi produces but are not evident from their
// documentation
// Based on del4.zip in bug 19610
const
  // Matches del4.zip in bug 19610:
  DelimText='"Spaces after quoted string"   ;';
  TestName='tw19610.Get_StrictDelimTrueCornerCases';
var
  TestSL: TStringList;
  Expected: TStringList;
  i: integer;
begin
  result:=true;
  //Expected values:
  Expected:=TStringList.Create;
  TestSL:=TStringList.Create;
  try
    // With delimiter true, we get 2 extra empty lines, also some spaces
    Expected.Add('Spaces after quoted string');
    Expected.Add('   ');
    Expected.Add('');

    TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
    TestSL.StrictDelimiter:=true;
    TestSL.DelimitedText:=DelimText;
    //Test:
    if Expected.Count<>TestSL.Count then
    begin
      writeln('');
      writeln(TestName+': failed: count mismatch: '+
      inttostr(TestSL.Count)+' test strings; '+inttostr(Expected.Count)+' expected strings.');
    end;
    for i:=0 to TestSL.Count-1 do
    begin
      if (Expected.Count>i) and (TestSL[i]<>Expected[i]) then
      begin
        writeln('');
        writeln(TestName+': failed: result:');
        writeln('*'+TestSL[i]+'*');
        writeln('while expected was:');
        writeln('*'+Expected[i]+'*');
        result:=false;
      end;
    end;
  finally
    Expected.Free;
    TestSL.Free;
  end;
end;

function Get_StrictDelimTrueSafeQuote:boolean;
// Test if input works with sdf output that has always been quoted
// Delphi accepts this input even though it does not write it by default
// This is a more unambiguous format than unquoted
// Strictdelimiter:=true when processing the delimitedtext
//
const
  DelimText='"normal_string";"""quoted_string""";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"string_with_tab'+#9+'character";"multi'+LineEnding+
    'line";"  SpacesInfront";"SpacesAtTheEnd   ";"  ""Spaces before quoted string"""';
  TestName='tw19610.Get_StrictDelimTrueSafeQuote';
var
  TestSL: TStringList;
  Expected: TStringList;
  i: integer;
begin
  result:=true;
  //Expected values:
  Expected:=TStringList.Create;
  TestSL:=TStringList.Create;
  try
    Expected.Add('normal_string');
    Expected.Add('"quoted_string"');
    Expected.Add('"quoted;delimiter"');
    Expected.Add('"quoted and space"');
    Expected.Add('"starting_quote');
    Expected.Add('string_with_tab'+#9+'character');
    Expected.Add('multi'+LineEnding+
      'line');
    Expected.Add('  SpacesInfront');
    Expected.Add('SpacesAtTheEnd   ');
    Expected.Add('  "Spaces before quoted string"');

    TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
    TestSL.StrictDelimiter:=true;
    TestSL.DelimitedText:=DelimText;
    //Test:
    if Expected.Count<>TestSL.Count then
    begin
      writeln('');
      writeln(TestName+': failed: count mismatch: '+
      inttostr(TestSL.Count)+' test strings; '+inttostr(Expected.Count)+' expected strings.');
    end;
    for i:=0 to TestSL.Count-1 do
    begin
      if (Expected.Count>i) and (TestSL[i]<>Expected[i]) then
      begin
        writeln('');
        writeln(TestName+': failed: result:');
        writeln('*'+TestSL[i]+'*');
        writeln('while expected was:');
        writeln('*'+Expected[i]+'*');
        result:=false;
      end;
    end;
  finally
    Expected.Free;
    TestSL.Free;
  end;
end;

function Get_StrictDelimFalseSafeQuote:boolean;
// Test if input works with sdf output that has always been quoted
// Delphi accepts this input even though it does not write it by default
// This is a more unambiguous format than unquoted
// Strictdelimiter:=false when processing the delimitedtext
//
const
  DelimText='"normal_string";"""quoted_string""";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"string_with_tab'+#9+'character";"multi'+LineEnding+
    'line";"  SpacesInfront";"SpacesAtTheEnd   ";"  ""Spaces before quoted string"""';
  TestName='tw19610.Get_StrictDelimTrueSafeQuote';
var
  TestSL: TStringList;
  Expected: TStringList;
  i: integer;
begin
  result:=true;
  //Expected values:
  Expected:=TStringList.Create;
  TestSL:=TStringList.Create;
  try
    Expected.Add('normal_string');
    Expected.Add('"quoted_string"');
    Expected.Add('"quoted;delimiter"');
    Expected.Add('"quoted and space"');
    Expected.Add('"starting_quote');
    Expected.Add('string_with_tab'+#9+'character');
    Expected.Add('multi'+LineEnding+
      'line');
    Expected.Add('  SpacesInfront');
    Expected.Add('SpacesAtTheEnd   ');
    Expected.Add('  "Spaces before quoted string"');

    TestSL.Delimiter:=';'; //Match example in bug 19610, del4.zip
    TestSL.StrictDelimiter:=false;
    TestSL.DelimitedText:=DelimText;
    //Test:
    if Expected.Count<>TestSL.Count then
    begin
      writeln('');
      writeln(TestName+': failed: count mismatch: '+
      inttostr(TestSL.Count)+' test strings; '+inttostr(Expected.Count)+' expected strings.');
    end;
    for i:=0 to TestSL.Count-1 do
    begin
      if (Expected.Count>i) and (TestSL[i]<>Expected[i]) then
      begin
        writeln('');
        writeln(TestName+': failed: result:');
        writeln('*'+TestSL[i]+'*');
        writeln('while expected was:');
        writeln('*'+Expected[i]+'*');
        result:=false;
      end;
    end;
  finally
    Expected.Free;
    TestSL.Free;
  end;
end;

function Get_Commatext:boolean;
// Test if input works with Delphi-compatible commatext
const
  CommaText='normal_string,"quoted_string","quoted,delimiter","quoted and space","""quoted_and_starting_quote","""quoted, starting quote, and space","quoted_with_tab'+#9+'character","quoted_multi'+LineEnding+
    'line","  UnquotedSpacesInfront","UnquotedSpacesAtTheEnd   ","  ""Spaces before quoted string"""';
  TestName='tw19610.Get_Commatext';
var
  TestSL: TStringList;
  Expected: TStringList;
  i: integer;
begin
  result:=true;
  //Expected values:
  Expected:=TStringList.Create;
  TestSL:=TStringList.Create;
  try
    Expected.Add('normal_string');
    Expected.Add('quoted_string');
    Expected.Add('quoted,delimiter');
    Expected.Add('quoted and space');
    Expected.Add('"quoted_and_starting_quote');
    Expected.Add('"quoted, starting quote, and space');
    Expected.Add('quoted_with_tab'+#9+'character');
    Expected.Add('quoted_multi'+LineEnding+
      'line');
    Expected.Add('  UnquotedSpacesInfront');
    Expected.Add('UnquotedSpacesAtTheEnd   ');
    Expected.Add('  "Spaces before quoted string"');

    TestSL.CommaText:=CommaText;
    //Test:
    if Expected.Count<>TestSL.Count then
    begin
      writeln('');
      writeln(TestName+': failed: count mismatch: '+
      inttostr(TestSL.Count)+' test strings; '+inttostr(Expected.Count)+' expected strings.');
    end;

    for i:=0 to TestSL.Count-1 do
    begin
      if (Expected.Count>i) and (TestSL[i]<>Expected[i]) then
      begin
        writeln('');
        writeln(TestName+': failed: result:');
        writeln('*'+TestSL[i]+'*');
        writeln('while expected was:');
        writeln('*'+Expected[i]+'*');
        result:=false;
      end;
    end;
  finally
    Expected.Free;
    TestSL.Free;
  end;
end;


function Put_StrictDelimFalse:boolean;
// Test if conversion stringlist=>delimitedtext gives the right data
// (right in this case: what Delphi outputs)
// Strictdelimiter:=false when processing the delimitedtext
const
  Expected='normal_string;"""quoted_string""";"just;delimiter";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"single""quote";"""""quoted starting quote and space""";"with_tab'+#9+'character";"multi'+LineEnding+
    'line";"   UnquotedSpacesInfront";"UnquotedSpacesAtTheEnd  ";"  ""Spaces before quoted string"""';
  //If we choose to output the "safely quoted" version, we need to test for it:
  //Though this version is not the same output as Delphi, it leads to the
  //same input if imported again (see Get_StrictDelimFalseSafeQuote for corresponding tests)
  ExpectedSafeQuote='"normal_string";"""quoted_string""";"just;delimiter";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"single""quote";"""""quoted starting quote and space""";"with_tab'+#9+'character";"multi'+LineEnding+
    'line";"   UnquotedSpacesInfront";"UnquotedSpacesAtTheEnd  ";"  ""Spaces before quoted string"""';
  TestName='tw19610.Put_StrictDelimFalse';
var
  TestSL: TStringList;
begin
  result:=true;
  TestSL:=TStringList.Create;
  try
    TestSL.Add('normal_string');
    TestSL.Add('"quoted_string"');
    TestSL.Add('just;delimiter');
    TestSL.Add('"quoted;delimiter"');
    TestSL.Add('"quoted and space"');
    TestSL.Add('"starting_quote');
    TestSL.Add('single"quote');
    TestSL.Add('""quoted starting quote and space"');
    TestSL.Add('with_tab'+#9+'character');
    TestSL.Add('multi'+LineEnding+
      'line');
    TestSL.Add('   UnquotedSpacesInfront');
    TestSL.Add('UnquotedSpacesAtTheEnd  ');
    TestSL.Add('  "Spaces before quoted string"');

    TestSL.Delimiter:=';';
    TestSL.StrictDelimiter:=false;
    if (TestSL.DelimitedText<>Expected) and (TestSL.DelimitedText<>ExpectedSafeQuote) then
    begin
      writeln('');
      writeln(TestName+': failed: result:');
      writeln('*'+TestSL.DelimitedText+'*');
      writeln('while expected was:');
      writeln('*'+Expected+'*');
      writeln('- or, with safe quote output:');
      writeln('*'+ExpectedSafeQuote+'*');
      result:=false
    end;
  finally
    TestSL.Free;
  end;
end;

function Put_StrictDelimTrue:boolean;
// Test if conversion stringlist=>delimitedtext gives the right data
// (right in this case: what Delphi outputs)
// Strictdelimiter:=true when processing the delimitedtext
const
  Expected='normal_string;"""quoted_string""";"just;delimiter";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"single""quote";"""""quoted starting quote and space""";with_tab'+#9+'character;multi'+LineEnding+
    'line;   UnquotedSpacesInfront;UnquotedSpacesAtTheEnd  ;"  ""Spaces before quoted string"""';
  //If we choose to output the "safely quoted" version, we need to test for it:
  //Though this version is not the same output as Delphi, it leads to the
  //same input if imported again (see Get_StrictDelimTrueSafeQuote for corresponding tests)
  ExpectedSafeQuote='"normal_string";"""quoted_string""";"just;delimiter";"""quoted;delimiter""";"""quoted and space""";"""starting_quote";"single""quote";"""""quoted starting quote and space""";"with_tab'+#9+'character";"multi'+LineEnding+
    'line";"   UnquotedSpacesInfront";"UnquotedSpacesAtTheEnd  ";"  ""Spaces before quoted string"""';
  TestName='tw19610.Put_StrictDelimTrue';
var
  TestSL: TStringList;
begin
  result:=true;
  TestSL:=TStringList.Create;
  try
    TestSL.Add('normal_string');
    TestSL.Add('"quoted_string"');
    TestSL.Add('just;delimiter');
    TestSL.Add('"quoted;delimiter"');
    TestSL.Add('"quoted and space"');
    TestSL.Add('"starting_quote');
    TestSL.Add('single"quote');
    TestSL.Add('""quoted starting quote and space"');
    TestSL.Add('with_tab'+#9+'character');
    TestSL.Add('multi'+LineEnding+
      'line');
    TestSL.Add('   UnquotedSpacesInfront');
    TestSL.Add('UnquotedSpacesAtTheEnd  ');
    TestSL.Add('  "Spaces before quoted string"');

    TestSL.Delimiter:=';';
    TestSL.StrictDelimiter:=true;
    if (TestSL.DelimitedText<>Expected) and (TestSL.DelimitedText<>ExpectedSafeQuote) then
    begin
      writeln('');
      writeln(TestName+': failed: result:');
      writeln('*'+TestSL.DelimitedText+'*');
      writeln('while expected was:');
      writeln('*'+Expected+'*');
      writeln('- or, with safe quote output:');
      writeln('*'+ExpectedSafeQuote+'*');
      result:=false
    end;
  finally
    TestSL.Free;
  end;
end;

function GetPut_StrictDelimFalse:boolean;
// Test if conversion stringlist=>delimitedtext=>stringlist gives identical data
// Strictdelimiter:=false (default) when processing the delimitedtext
const
  TestName='tw19610.GetPut_StrictDelimFalse';
var
  TestSL: TStringList;
  ResultSL: TStringList;
  i: integer;
begin
  result:=true;
  ResultSL:=TStringList.Create;
  TestSL:=TStringList.Create;
  try
    TestSL.Add('normal_string');
    TestSL.Add('"quoted_string"');
    TestSL.Add('"quoted;delimiter"');
    TestSL.Add('"quoted and space"');
    TestSL.Add('"starting_quote');
    TestSL.Add('""quoted, starting quote, and space"');
    TestSL.Add('with_tab'+#9+'character');
    TestSL.Add('multi'+LineEnding+
      'line');
    TestSL.Add('   UnquotedSpacesInfront');
    TestSL.Add('UnquotedSpacesAtTheEnd  ');
    TestSL.Add('  "Spaces before quoted string"');

    TestSL.Delimiter:=';';
    TestSL.StrictDelimiter:=false;
    ResultSL.Delimiter:=';';
    ResultSL.StrictDelimiter:=false;
    ResultSL.DelimitedText:=TestSL.DelimitedText;
    //Test:
    if ResultSL.Count<>TestSL.Count then
    begin
      writeln('');
      writeln(TestName+': failed: count mismatch: '+
      inttostr(TestSL.Count)+' test strings; '+inttostr(ResultSL.Count)+' expected strings.');
    end;

    for i:=0 to TestSL.Count-1 do
    begin
      if (ResultSL.Count>i) and (TestSL[i]<>ResultSL[i]) then
      begin
        writeln('');
        writeln(TestName+': failed: result:');
        writeln('*'+TestSL[i]+'*');
        writeln('while expected was:');
        writeln('*'+ResultSL[i]+'*');
        result:=false;
      end;
    end;
  finally
    ResultSL.Free;
    TestSL.Free;
  end;
end;

function GetPut_StrictDelimTrue:boolean;
// Test if conversion stringlist=>delimitedtext=>stringlist gives identical data
// Strictdelimiter:=true when processing the delimitedtext
const
  TestName='tw19610.GetPut_StrictDelimTrue';
var
  TestSL: TStringList;
  ResultSL: TStringList;
  i: integer;
begin
  result:=true;
  ResultSL:=TStringList.Create;
  TestSL:=TStringList.Create;
  try
    TestSL.Add('normal_string');
    TestSL.Add('"quoted_string"');
    TestSL.Add('"quoted;delimiter"');
    TestSL.Add('"quoted and space"');
    TestSL.Add('"starting_quote');
    TestSL.Add('""quoted, starting quote, and space"');
    TestSL.Add('with_tab'+#9+'character');
    TestSL.Add('multi'+LineEnding+
      'line');
    TestSL.Add('   UnquotedSpacesInfront');
    TestSL.Add('UnquotedSpacesAtTheEnd  ');
    TestSL.Add('  "Spaces before quoted string"');

    TestSL.Delimiter:=';';
    TestSL.StrictDelimiter:=false;
    ResultSL.Delimiter:=';';
    ResultSL.StrictDelimiter:=true;
    ResultSL.DelimitedText:=TestSL.DelimitedText;
    //Test:
    if ResultSL.Count<>TestSL.Count then
    begin
      writeln('');
      writeln(TestName+': failed: count mismatch: '+
      inttostr(TestSL.Count)+' test strings; '+inttostr(ResultSL.Count)+' expected strings.');
    end;

    for i:=0 to TestSL.Count-1 do
    begin
      if (ResultSL.Count>i) and (TestSL[i]<>ResultSL[i]) then
      begin
        writeln('');
        writeln(TestName+': failed: result:');
        writeln('*'+TestSL[i]+'*');
        writeln('while expected was:');
        writeln('*'+ResultSL[i]+'*');
        result:=false;
      end;
    end;
  finally
    ResultSL.Free;
    TestSL.Free;
  end;
end;

var
  FailCount: integer;
begin
  FailCount:=0;
  // The Get_... tests load in delimitedtext and test the resulting stringlist:
  if not(Get_StrictDelimFalse) then FailCount:=FailCount+1;
  if not(Get_StrictDelimTrue) then FailCount:=FailCount+1;
  if not(Get_StrictDelimFalseCornerCases) then FailCount:=FailCount+1;
  if not(Get_StrictDelimTrueCornerCases) then FailCount:=FailCount+1;
  if not(Get_StrictDelimTrueSafeQuote) then FailCount:=FailCount+1;
  if not(Get_StrictDelimFalseSafeQuote) then FailCount:=FailCount+1;

  if not(Get_CommaText) then FailCount:=FailCount+1;

  // The Put_... tests load strings and test the resulting delimitedtext:
  if not(Put_StrictDelimFalse) then FailCount:=FailCount+1;
  if not(Put_StrictDelimTrue) then FailCount:=FailCount+1;

  // Test writing to delimitedtext and reading from delimitedtext:
  if not(GetPut_StrictDelimFalse) then FailCount:=FailCount+1;
  if not(GetPut_StrictDelimTrue) then FailCount:=FailCount+1;

  // Indicate success or failure to test framework:
  if FailCount=0 then
  begin
    writeln('');
    writeln('tw19610: sdf tests succeeded.');
  end
  else
  begin
    writeln('');
    writeln('tw19610: sdf test(s) failed. Number of failed test group(s): '+inttostr(FailCount));
  end;

  halt(FailCount);
end.