Skip to content

Commit 51301fb

Browse files
committed
New tests for processoptions
1 parent ce9d25c commit 51301fb

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
% Barcode Writer in Pure PostScript
2+
% https://bwipp.terryburton.co.uk
3+
%
4+
% vim: set sw=4 sts=4 et:
5+
%
6+
% Copyright (c) 2004-2026 Terry Burton
7+
%
8+
9+
/processoptions dup /uk.co.terryburton.bwipp findresource cvx def
10+
11+
/setup {
12+
/stropt (default) def
13+
/boolopt false def
14+
/intopt 0 def
15+
/realopt 0.0 def
16+
} def
17+
18+
/ok_tmpl {
19+
{ 10 dict begin setup 0 exec end }
20+
dup 3 -1 roll 4 exch put
21+
true isEqual
22+
} def
23+
24+
/er_tmpl {
25+
{ 10 dict begin setup 0 exec end }
26+
dup 4 5 -1 roll put
27+
exch isError
28+
} def
29+
30+
31+
%
32+
% String input parsing
33+
%
34+
{ (stropt=hello) processoptions pop stropt (hello) eq } ok_tmpl
35+
{ (stropt=hello world) processoptions pop stropt (hello) eq } ok_tmpl
36+
{ (stropt=a boolopt) processoptions pop stropt (a) eq boolopt true eq and } ok_tmpl
37+
{ (intopt=1 realopt=2.5 stropt=foo) processoptions pop intopt 1 eq realopt 2.5 eq and stropt (foo) eq and } ok_tmpl
38+
39+
40+
%
41+
% Dict input
42+
%
43+
{ << /stropt (test) >> processoptions pop stropt (test) eq } ok_tmpl
44+
45+
46+
%
47+
% String type
48+
%
49+
{ (stropt=hello) processoptions pop stropt (hello) eq } ok_tmpl
50+
{ (stropt=123) processoptions pop stropt (123) eq } ok_tmpl
51+
{ (stropt=) processoptions pop stropt () eq } ok_tmpl
52+
{ (stropt= ) processoptions pop stropt () eq } ok_tmpl
53+
54+
55+
%
56+
% Boolean type
57+
%
58+
{ (boolopt) processoptions pop boolopt true eq } ok_tmpl
59+
{ << /boolopt true >> processoptions pop boolopt true eq } ok_tmpl
60+
{ << /boolopt false >> processoptions pop boolopt false eq } ok_tmpl
61+
62+
{ (boolopt=true) processoptions } /bwipp.invalidOptionType er_tmpl
63+
{ (boolopt=1) processoptions } /bwipp.invalidOptionType er_tmpl
64+
65+
66+
%
67+
% Integer type
68+
%
69+
{ (intopt=42) processoptions pop intopt 42 eq } ok_tmpl
70+
{ (intopt=-5) processoptions pop intopt -5 eq } ok_tmpl
71+
{ (intopt=0) processoptions pop intopt 0 eq } ok_tmpl
72+
73+
{ (intopt=3.5) processoptions } /bwipp.invalidOptionType er_tmpl
74+
{ (intopt=abc) processoptions } /bwipp.invalidOptionType er_tmpl
75+
{ (intopt=true) processoptions } /bwipp.invalidOptionType er_tmpl
76+
77+
78+
%
79+
% Real type
80+
%
81+
{ (realopt=3.14) processoptions pop realopt 3.14 eq } ok_tmpl
82+
{ (realopt=-2.5) processoptions pop realopt -2.5 eq } ok_tmpl
83+
{ (realopt=42) processoptions pop realopt 42.0 eq } ok_tmpl
84+
85+
{ (realopt=abc) processoptions } /bwipp.invalidOptionType er_tmpl
86+
{ (realopt=true) processoptions } /bwipp.invalidOptionType er_tmpl
87+
88+
89+
%
90+
% Unknown options (silently ignored)
91+
%
92+
{ (unknown=foo) processoptions pop true } ok_tmpl
93+
{ (unknown) processoptions pop true } ok_tmpl
94+
95+
96+
%
97+
% Meaningless (ignored)
98+
%
99+
{ (1=foo) processoptions pop true } ok_tmpl
100+
{ (1) processoptions pop true } ok_tmpl
101+
{ (=foo) processoptions pop true } ok_tmpl
102+

tests/ps_tests/test.ps

53 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)