123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583 |
- program tstr;
- uses
- jdk15;
- {$macro on}
- {$define write:=JLSystem.fout.print}
- {$define writeln:=JLSystem.fout.println}
- {$ifdef fpc}
- {$ifndef ver1_0}
- {$define haswidestring}
- {$endif}
- {$else}
- {$ifndef ver70}
- {$define haswidestring}
- {$endif}
- {$endif}
- procedure test_shortstr;
- type
- tlocalstring = shortstring;
- var
- l: longint;
- c: cardinal;
- f: real;
- i: int64;
- q: qword;
- s: tlocalstring;
- len: byte;
- frac: word;
- longval : longint;
- procedure check(const ss: tlocalstring);
- begin
- if s <> ss then
- begin
- writeln('error!');
- halt(1);
- end;
- end;
- begin
- writeln('testing str(<value>,shortstring)...');
- l := -1;
- str(l,s);
- check('-1');
- str(l:0,s);
- check('-1');
- str(l:1,s);
- check('-1');
- str(l:2,s);
- check('-1');
- str(l:3,s);
- check(' -1');
- len := 4;
- str(l:len,s);
- check(' -1');
- c := 10;
- str(c,s);
- check('10');
- str(c:0,s);
- check('10');
- str(c:1,s);
- check('10');
- str(c:2,s);
- check('10');
- str(c:3,s);
- check(' 10');
- { for more in-depth tests of str_real, see ../tstreal[1,2].pp }
- f := -1.12345;
- {$IFOPT E-}
- str(f,s);
- if (sizeof(extended) = 10) or
- (sizeof(extended) = 12) then
- check('-1.12345000000000E+000')
- else if sizeof(extended) = 8 then
- check('-1.12345000000000E+000')
- else
- check('error, not yet implemented!!!!');
- {$endif}
- { the number of exponents depends on the maaping of the real type }
- if sizeof(real) = 8 then
- begin
- str(f:0,s);
- check('-1.1E+000');
- str(f:1,s);
- check('-1.1E+000');
- str(f:2,s);
- check('-1.1E+000');
- str(f:3,s);
- check('-1.1E+000');
- str(f:4,s);
- check('-1.1E+000');
- end
- else
- begin
- str(f:0,s);
- check('-1.1E+00');
- str(f:1,s);
- check('-1.1E+00');
- str(f:2,s);
- check('-1.1E+00');
- str(f:3,s);
- check('-1.1E+00');
- str(f:4,s);
- check('-1.1E+00');
- end;
- str(f:0:0,s);
- check('-1');
- str(f:0:1,s);
- check('-1.1');
- str(f:0:2,s);
- check('-1.12');
- str(f:1:0,s);
- check('-1');
- str(f:1:1,s);
- check('-1.1');
- str(f:5:0,s);
- check(' -1');
- str(f:5:1,s);
- check(' -1.1');
- str(f:5:2,s);
- check('-1.12');
- len := 6;
- frac := 2;
- str(f:len:frac,s);
- check(' -1.12');
- i := -1;
- str(i,s);
- check('-1');
- str(i:0,s);
- check('-1');
- str(i:1,s);
- check('-1');
- str(i:2,s);
- check('-1');
- str(i:3,s);
- check(' -1');
- i:=655536;
- str(i,s);
- check('655536');
- str(i:0,s);
- check('655536');
- str(i:1,s);
- check('655536');
- str(i:2,s);
- check('655536');
- str(i:3,s);
- check('655536');
- longval:=1;
- i:=int64(longval) shl 33;
- str(i,s);
- check('8589934592');
- str(i:0,s);
- check('8589934592');
- str(i:1,s);
- check('8589934592');
- str(i:2,s);
- check('8589934592');
- str(i:3,s);
- check('8589934592');
- q := 10;
- str(q,s);
- check('10');
- str(q:0,s);
- check('10');
- str(q:1,s);
- check('10');
- str(q:2,s);
- check('10');
- str(q:3,s);
- check(' 10');
- q:=655536;
- str(q,s);
- check('655536');
- str(q:0,s);
- check('655536');
- str(q:1,s);
- check('655536');
- str(q:2,s);
- check('655536');
- str(q:3,s);
- check('655536');
- longval:=1;
- q:=qword(longval) shl 33;
- str(q,s);
- check('8589934592');
- str(q:0,s);
- check('8589934592');
- str(q:1,s);
- check('8589934592');
- str(q:2,s);
- check('8589934592');
- str(q:3,s);
- check('8589934592');
- end;
- (*
- procedure test_ansistr;
- type
- tlocalstring = ansistring;
- var
- l: longint;
- c: cardinal;
- f: real;
- i: int64;
- q: qword;
- s: tlocalstring;
- len: shortint;
- frac: smallint;
- longval : longint;
- procedure check(const ss: tlocalstring);
- begin
- if s <> ss then
- begin
- writeln('error!');
- halt(1);
- end;
- end;
- begin
- writeln('testing str(<value>,ansistring)...');
- l := -1;
- str(l,s);
- check('-1');
- str(l:0,s);
- check('-1');
- str(l:1,s);
- check('-1');
- str(l:2,s);
- check('-1');
- str(l:3,s);
- check(' -1');
- len := 4;
- str(l:len,s);
- check(' -1');
- c := 10;
- str(c,s);
- check('10');
- str(c:0,s);
- check('10');
- str(c:1,s);
- check('10');
- str(c:2,s);
- check('10');
- str(c:3,s);
- check(' 10');
- { for more in-depth tests of str_real, see ../tstreal[1,2].pp }
- f := -1.12345;
- {$IFOPT E-}
- str(f,s);
- if (sizeof(extended) = 10) or
- (sizeof(extended) = 12) then
- check('-1.12345000000000E+000')
- else if sizeof(extended) = 8 then
- check('-1.12345000000000E+000')
- else
- check('error, not yet implemented!!!!');
- {$endif}
- { the number of exponents depends on the maaping of the real type }
- if sizeof(real) = 8 then
- begin
- str(f:0,s);
- check('-1.1E+000');
- str(f:1,s);
- check('-1.1E+000');
- str(f:2,s);
- check('-1.1E+000');
- str(f:3,s);
- check('-1.1E+000');
- str(f:4,s);
- check('-1.1E+000');
- end
- else
- begin
- str(f:0,s);
- check('-1.1E+00');
- str(f:1,s);
- check('-1.1E+00');
- str(f:2,s);
- check('-1.1E+00');
- str(f:3,s);
- check('-1.1E+00');
- str(f:4,s);
- check('-1.1E+00');
- end;
- str(f:0:0,s);
- check('-1');
- str(f:0:1,s);
- check('-1.1');
- str(f:0:2,s);
- check('-1.12');
- str(f:1:0,s);
- check('-1');
- str(f:1:1,s);
- check('-1.1');
- str(f:5:0,s);
- check(' -1');
- str(f:5:1,s);
- check(' -1.1');
- str(f:5:2,s);
- check('-1.12');
- len := 6;
- frac := 2;
- str(f:len:frac,s);
- check(' -1.12');
- i := -1;
- str(i,s);
- check('-1');
- str(i:0,s);
- check('-1');
- str(i:1,s);
- check('-1');
- str(i:2,s);
- check('-1');
- str(i:3,s);
- check(' -1');
- i:=655536;
- str(i,s);
- check('655536');
- str(i:0,s);
- check('655536');
- str(i:1,s);
- check('655536');
- str(i:2,s);
- check('655536');
- str(i:3,s);
- check('655536');
- longval:=1;
- i:=int64(longval) shl 33;
- str(i,s);
- check('8589934592');
- str(i:0,s);
- check('8589934592');
- str(i:1,s);
- check('8589934592');
- str(i:2,s);
- check('8589934592');
- str(i:3,s);
- check('8589934592');
- q := 10;
- str(q,s);
- check('10');
- str(q:0,s);
- check('10');
- str(q:1,s);
- check('10');
- str(q:2,s);
- check('10');
- str(q:3,s);
- check(' 10');
- q:=655536;
- str(q,s);
- check('655536');
- str(q:0,s);
- check('655536');
- str(q:1,s);
- check('655536');
- str(q:2,s);
- check('655536');
- str(q:3,s);
- check('655536');
- longval:=1;
- q:=qword(longval) shl 33;
- str(q,s);
- check('8589934592');
- str(q:0,s);
- check('8589934592');
- str(q:1,s);
- check('8589934592');
- str(q:2,s);
- check('8589934592');
- str(q:3,s);
- check('8589934592');
- end;
- *)
- {$ifdef haswidestring}
- procedure test_widestr;
- type
- tlocalstring = widestring;
- var
- l: longint;
- c: cardinal;
- f: real;
- i: int64;
- q: qword;
- s: tlocalstring;
- len: longint;
- frac: cardinal;
- longval : longint;
- procedure check(const ss: tlocalstring);
- begin
- if s <> ss then
- begin
- writeln('error!');
- halt(1);
- end;
- end;
- begin
- writeln('testing str(<value>,widestring)...');
- l := -1;
- str(l,s);
- check('-1');
- str(l:0,s);
- check('-1');
- str(l:1,s);
- check('-1');
- str(l:2,s);
- check('-1');
- str(l:3,s);
- check(' -1');
- len := 4;
- str(l:len,s);
- check(' -1');
- c := 10;
- str(c,s);
- check('10');
- str(c:0,s);
- check('10');
- str(c:1,s);
- check('10');
- str(c:2,s);
- check('10');
- str(c:3,s);
- check(' 10');
- { for more in-depth tests of str_real, see ../tstreal[1,2].pp }
- f := -1.12345;
- {$IFOPT E-}
- str(f,s);
- if sizeof(extended) = 10 then
- check('-1.12345000000000E+000')
- else if sizeof(extended) = 8 then
- check('-1.12345000000000E+000')
- else
- check('error, not yet implemented!!!!');
- {$endif}
- { the number of exponents depends on the maaping of the real type }
- if sizeof(real) = 8 then
- begin
- str(f:0,s);
- check('-1.1E+000');
- str(f:1,s);
- check('-1.1E+000');
- str(f:2,s);
- check('-1.1E+000');
- str(f:3,s);
- check('-1.1E+000');
- str(f:4,s);
- check('-1.1E+000');
- end
- else
- begin
- str(f:0,s);
- check('-1.1E+00');
- str(f:1,s);
- check('-1.1E+00');
- str(f:2,s);
- check('-1.1E+00');
- str(f:3,s);
- check('-1.1E+00');
- str(f:4,s);
- check('-1.1E+00');
- end;
- str(f:0:0,s);
- check('-1');
- str(f:0:1,s);
- check('-1.1');
- str(f:0:2,s);
- check('-1.12');
- str(f:1:0,s);
- check('-1');
- str(f:1:1,s);
- check('-1.1');
- str(f:5:0,s);
- check(' -1');
- str(f:5:1,s);
- check(' -1.1');
- str(f:5:2,s);
- check('-1.12');
- len := 6;
- frac := 2;
- str(f:len:frac,s);
- check(' -1.12');
- i := -1;
- str(i,s);
- check('-1');
- str(i:0,s);
- check('-1');
- str(i:1,s);
- check('-1');
- str(i:2,s);
- check('-1');
- str(i:3,s);
- check(' -1');
- i:=655536;
- str(i,s);
- check('655536');
- str(i:0,s);
- check('655536');
- str(i:1,s);
- check('655536');
- str(i:2,s);
- check('655536');
- str(i:3,s);
- check('655536');
- longval:=1;
- i:=int64(longval) shl 33;
- str(i,s);
- check('8589934592');
- str(i:0,s);
- check('8589934592');
- str(i:1,s);
- check('8589934592');
- str(i:2,s);
- check('8589934592');
- str(i:3,s);
- check('8589934592');
- q := 10;
- str(q,s);
- check('10');
- str(q:0,s);
- check('10');
- str(q:1,s);
- check('10');
- str(q:2,s);
- check('10');
- str(q:3,s);
- check(' 10');
- q:=655536;
- str(q,s);
- check('655536');
- str(q:0,s);
- check('655536');
- str(q:1,s);
- check('655536');
- str(q:2,s);
- check('655536');
- str(q:3,s);
- check('655536');
- longval:=1;
- q:=qword(longval) shl 33;
- str(q,s);
- check('8589934592');
- str(q:0,s);
- check('8589934592');
- str(q:1,s);
- check('8589934592');
- str(q:2,s);
- check('8589934592');
- str(q:3,s);
- check('8589934592');
- end;
- {$endif haswidestring}
- begin
- test_shortstr;
- // test_ansistr;
- {$ifdef haswidestring}
- test_widestr;
- {$endif haswidestring}
- writeln('str tests successful!');
- end.
|