-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sprintf.sql
More file actions
70 lines (48 loc) · 2.96 KB
/
test_sprintf.sql
File metadata and controls
70 lines (48 loc) · 2.96 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
set serveroutput on size 100000 format wrapped
declare
--
--
procedure cmp(test_no in number, format in varchar2, parms in &tq84_prefix.varchar2_t, expected in varchar2) is -- {
gotten varchar2(4000);
begin
gotten := &tq84_prefix.string_op.sprintf(format, parms);
if gotten != expected then
dbms_output.put_line('test ' || test_no || ' failed');
dbms_output.put_line(' gotten is: ' || gotten || '<');
dbms_output.put_line(' expected is: ' || expected || '<');
end if;
end cmp; -- }
begin
dbms_output.put_line('sprintf test');
-- Right aligning a string:
cmp( 1, 'String: %20s', &tq84_prefix.varchar2_t('hello world'), 'String: hello world');
-- Left aligning a string 12345678901234567890
cmp( 2, 'String: %-20s', &tq84_prefix.varchar2_t('hello world'), 'String: hello world ');
-- A left and a right aligned string ... 1234567890 1234567890 ...
cmp( 3, '... %10s %-10s ...', &tq84_prefix.varchar2_t('hello', 'world'), '... hello world ...');
-- Strings and null ... 12345 12345 12345 12345 ...
cmp( 4, '... %5s %5s %-5s %-5s ...', &tq84_prefix.varchar2_t('a', null, 'b', null), '... a b ...');
-- Numbers
cmp( 5, 'Numbers: %d,%d,%d' , &tq84_prefix.varchar2_t( 42, 0, -42), 'Numbers: 42,0,-42');
cmp( 6, 'Numbers: %d,%d,%d' , &tq84_prefix.varchar2_t( 42, null, -42), 'Numbers: 42,,-42' );
-- Right aligning numbers: 12345 12345 12345
cmp( 7, 'Numbers: %5d,%5d,%5d' , &tq84_prefix.varchar2_t( 42, 0, -42), 'Numbers: 42, 0, -42');
cmp( 8, 'Numbers: %5d,%5d,%5d' , &tq84_prefix.varchar2_t( 42, null, -42), 'Numbers: 42, , -42');
-- Left aligning numbers: 12345 12345 12345
cmp( 9, 'Numbers: %-5d,%-5d,%-5d' , &tq84_prefix.varchar2_t( 42, null, -42), 'Numbers: 42 , ,-42 ');
-- Fractions 12.12345
cmp(10, '1/3: %2.5d', &tq84_prefix.varchar2_t( 1/3), '1/3: .33333');
cmp(11, '1/3: %02.5d', &tq84_prefix.varchar2_t( 1/3), '1/3: 0.33333');
cmp(12, '1/3: %2.5d', &tq84_prefix.varchar2_t(-1/3), '1/3: -.33333');
cmp(13, '1/3: %02.5d', &tq84_prefix.varchar2_t(-1/3), '1/3: -0.33333');
-- Fractions with signs S12.12345
cmp(14, '1/3: %+2.5d', &tq84_prefix.varchar2_t( 1/3), '1/3: +.33333');
cmp(15, '1/3: %+02.5d', &tq84_prefix.varchar2_t( 1/3), '1/3: +0.33333');
cmp(16, '1/3: %+2.5d', &tq84_prefix.varchar2_t(-1/3), '1/3: -.33333');
cmp(17, '1/3: %+02.5d', &tq84_prefix.varchar2_t(-1/3), '1/3: -0.33333');
-- Recognizition of the %
cmp(18, '%d %% of %d is: %d', &tq84_prefix.varchar2_t(7, 68, 68/100*7), '7 % of 68 is: 4.76');
-- Number doesn't fit the length
cmp(19, '... %4d ...', &tq84_prefix.varchar2_t(12345), '... #### ...');
end;
/