1 |
{$apptype console}
|
2 |
|
3 |
{ Copyright (C) 2009 Bas Steendijk and Peter Green
|
4 |
For conditions of distribution and use, see copyright notice in zlib_license.txt
|
5 |
which is included in the package
|
6 |
----------------------------------------------------------------------------- }
|
7 |
|
8 |
|
9 |
program testreadtxt2;
|
10 |
uses readtxt2, classes;
|
11 |
|
12 |
var
|
13 |
t: treadtxt;
|
14 |
f: file;
|
15 |
procedure writestring(var f: file; s : string);
|
16 |
begin
|
17 |
blockwrite(f,s[1],length(s));
|
18 |
end;
|
19 |
|
20 |
begin
|
21 |
assignfile(f,'mixed.txt');
|
22 |
rewrite(f,1);
|
23 |
writestring(f,'DOS'#13#10);
|
24 |
writestring(f,'UNIX'#10);
|
25 |
writestring(f,'MAC'#13);
|
26 |
writestring(f,'UNIX'#10);
|
27 |
writestring(f,'NONE');
|
28 |
closefile(f);
|
29 |
|
30 |
writeln('reading test file in default mode (all line endings treated as line endings)');
|
31 |
t := treadtxt.createf('mixed.txt');
|
32 |
if t.readline = 'DOS' then writeln('DOS success') else writeln('DOS fail');
|
33 |
if t.readline = 'UNIX' then writeln('UNIX success') else writeln('UNIX fail');
|
34 |
if t.readline = 'MAC' then writeln('MAC success') else writeln('MAC fail');
|
35 |
if t.readline = 'UNIX' then writeln('UNIX success') else writeln('UNIX fail');
|
36 |
if t.readline = 'NONE' then writeln('NONE success') else writeln('NONE fail');
|
37 |
t.destroy;
|
38 |
|
39 |
writeln('reading test file with only CR treated as a line ending');
|
40 |
t := treadtxt.createf('mixed.txt');
|
41 |
t.allowedeol := eoltype_cr;
|
42 |
if t.readline = 'DOS' then writeln('DOS success') else writeln('DOS fail');
|
43 |
if t.readline = #10'UNIX'#10'MAC' then writeln('LF+UNIX+LF+MAC success') else writeln('LF+UNIX+LF+MAC fail');
|
44 |
if t.readline = 'UNIX'#10'NONE' then writeln('UNIX+LF+NONE success') else writeln('UNIX+LF+NONE fail');
|
45 |
t.destroy;
|
46 |
|
47 |
writeln('reading test file with only LF treated as a line ending');
|
48 |
t := treadtxt.createf('mixed.txt');
|
49 |
t.allowedeol := eoltype_lf;
|
50 |
if t.readline = 'DOS'#13 then writeln('DOS+CR success') else writeln('DOS+CR fail');
|
51 |
if t.readline = 'UNIX' then writeln('UNIX success') else writeln('UNIX fail');
|
52 |
if t.readline = 'MAC'#13'UNIX' then writeln('MAC+CR+UNIX success') else writeln('MAC+CR+UNIX fail');
|
53 |
if t.readline = 'NONE' then writeln('NONE success') else writeln('NONE fail');
|
54 |
t.destroy;
|
55 |
|
56 |
writeln('reading test file with only CRLF treated as a line ending');
|
57 |
t := treadtxt.createf('mixed.txt');
|
58 |
t.allowedeol := eoltype_crlf;
|
59 |
if t.readline = 'DOS' then writeln('DOS success') else writeln('DOS fail');
|
60 |
if t.readline = 'UNIX'#10'MAC'#13'UNIX'#10'NONE' then writeln('UNIX+LF+MAC+CR+UNIX+LF+NONE success') else writeln('UNIX+LF+MAC+CR+UNIX+LF+NONE fail');
|
61 |
t.destroy;
|
62 |
|
63 |
|
64 |
{$ifdef mswindows}
|
65 |
//make things a little easier to test in the delphi GUI
|
66 |
readln;
|
67 |
{$endif}
|
68 |
end.
|