Fix #4414: Add url for bug reporting page in bug_report
[maxima.git] / share / stringproc / rtest_stringproc.mac
blobb918847c78014d1b1f3c7aa92f2adb40aab0aa2f
1 (kill (all), 0);
2 0;
4 m : "text";
5 "text"$
6 stringp(m);
7 true;
8 l : sconcat("\"", "text", "\"");
9 ''(string("text"))$
10 stringp(l);
11 true;
12 c : "e";
13 "e"$
14 [charp(c), lcharp(c)];
15 [true, false]$
16 c : supcase(c);
17 "E"$
18 charp(c);
19 true$
20 control : "~2tAn atom: ~20t~a~%~2tand a list: ~20t~{~r ~}~%~2tand an integer: ~20t~d~%";
21 "~2tAn atom: ~20t~a~%~2tand a list: ~20t~{~r ~}~%~2tand an integer: ~20t~d~%"$
22 printf(false, control, 'true, [1, 2, 3], 42)$
23 "  An atom:          true
24   and a list:       one two three 
25   and an integer:   42
27 printf(false, "~a ~a ~4f ~a ~@r", "String", sym, bound, sqrt(12), 144), bound = 1.234;
28 "String sym 1.23 2*sqrt(3) CXLIV"$
29 printf(false, "~{~a ~}", ["one", 2, "THREE"]);
30 "one 2 THREE "$
31 printf(false, "~{~{~9,1f ~}~%~}", mat), mat = args(matrix([1.1, 2, 3.33], [4, 5, 6], [7, 8.88, 9]))$
32 "      1.1       2.0       3.3 
33       4.0       5.0       6.0 
34       7.0       8.9       9.0 
36 control : "~:(~r~) bird~p ~[is~;are~] singing.";
37 "~:(~r~) bird~p ~[is~;are~] singing."$
38 printf(false, control, n, n, if n = 1 then 1 else 2), n = 2;
39 "Two birds are singing."$
41 block([res:{},tmp],
42   for n from 0 thru 127 do (
43     tmp : ascii(n), 
44     if alphacharp(tmp) then res : adjoin (tmp, res) ), 
45   subsetp ({"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}, res) );
46 true;
48 block([res:{},tmp],
49   for n from 0 thru 127 do (
50     tmp : ascii(n), 
51     if constituent(tmp) then res : adjoin (tmp, res) ), 
52   subsetp ({"!","\"","#","$","%","&","'","(",")","*","+",",","-",".","/","0","1","2","3","4","5","6","7","8","9",":",";","<","=",">","?","@","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","[","\\","]","^","_","`","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","{","|","}","~"}, res) );
53 true;
55 charat("Lisp", 1);
56 "L"$
57 l : charlist("Lisp");
58 ["L","i","s","p"]$
59 l[1];
60 "L"$
61 cint("$");
62 36$
63 [cequal("e","E"),cequalignore("e","E")];
64 [false, true]$
65 [alphacharp("2"),alphanumericp("2")];
66 [false, true]$
67 [clessp("E","e"),clesspignore("E","e")];
68 [true, false]$
69 [lowercasep("e"),lowercasep("E")];
70 [true, false]$
72 2*parse_string ("1.234; 5.678");
73 2.468$
75 3*parse_string ("1/2");
76 3/2$
78 parse_string ("2.3e10");
79 2.3e10$
81 parse_string (".25e-1");
82 0.025$
84 2*parse_string ("2.3b1");
85 4.6b1$
87 parse_string (".25b-1");
88 2.5b-2$
90 parse_string ("foo");
91 foo$
93 parse_string ("foo;");
94 foo$
96 parse_string ("foo$;$;");
97 foo$
99 parse_string ("\"semicolon ; string\"");
100 "semicolon ; string"$
102 parse_string ("\"dollar $ string\"");
103 "dollar $ string"$
105 parse_string ("[2]");
106 [2];
108 parse_string ("(foo : 1234, expand ((foo + bar)^2))");
109 (foo : 1234, expand ((foo + bar)^2));
111 eval_string ("(foo : 1234, expand ((foo + bar)^2))");
112 bar^2 + 2468*bar + 1522756;
114 (kill (bar), parse_string ("bar (x) := x^2"), bar (7));
115 bar (7);
117 (eval_string ("bar (x) := x^2"), bar (7));
120 s : sconcat ("xx[", 3, "]:", expand((y + x)^3));
121 "xx[3]:y^3+3*x*y^2+3*x^2*y+x^3"$
122 scopy("Original");
123 "Original"$
124 [sequal("gnuplot","Gnuplot"),sequalignore("gnuplot","Gnuplot")];
125 [false, true]$
126 stringp(s);
127 true$
128 simplode(["xx[", 3, "]:", expand((y + x)^3 )]);
129 "xx[3]:y^3+3*x*y^2+3*x^2*y+x^3"$
130 simplode(charlist("stars"), " * ");
131 "s * t * a * r * s"$
132 simplode(["One", "more", "coffee."], " ");
133 "One more coffee."$
135 /* SF bug report #3329: "Simplode overlimited at Maxima with GCL" */
136 block ([l2: [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]],
137   simplode(l2,";"));
138 "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;\
139 28;29;30;31;32;33";
141 block ([l2: [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]],
142   simplode(l2));
143 "123456789101112131415161718192021222324252627\
144 282930313233";
146 simplode (flatten (makelist (["A", "B", "C", "D"], 50)), "-");
147 "A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D\
148 -A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D\
149 -A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D\
150 -A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D\
151 -A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D-A-B-C-D";
153 simplode (flatten (makelist (["A", "B", "C", "D"], 50)));
154 "ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
155 ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
156 ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
157 ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD\
158 ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD";
160 /* Bug #3439: Simplode output on empty list */
162 simplode ([], "");
165 /* This used to return the string "false" */
166 simplode ([], " ");
169 /* This used to return the symbol foo */
170 simplode (['foo]);
171 "foo"$
173 s : "A submarine.";
174 "A submarine."$
175 sconcat (substring(s, 1, 3), "yellow ", substring(s, 3));
176 "A yellow submarine."$
177 sinsert("hollow ", s, 3);
178 "A hollow submarine."$
179 sinvertcase("sInvertCase");
180 "SiNVERTcASE"$
181 smake(3, "w");
182 "www"$
183 smismatch("seven","seventh");
185 split("1.2   2.3   3.4   4.5");
186 ["1.2","2.3","3.4","4.5"]$
187 split("first;;third;fourth", ";", false);
188 ["first","","third","fourth"]$
189 sposition("e","seventh");
191 sremove("n't", "I don't like coffee.");
192 "I do like coffee."$
193 sremove("DO ", %, 'sequalignore);
194 "I like coffee."$
195 sreverse("einnegermitgazellezagtimregennie");
196 "einnegermitgazellezagtimregennie"$
198 /* SF bug report #3329: "Simplode overlimited at Maxima with GCL"
199  * (same bug in sreverse; ensure it works OK for long strings
200  */
201 sreverse ("dCBCba1A310acBaACAD0DB13dA2200c32AbADA0aB0cAa2D2aDB12AdABa030Ba03c3d0DbA\
202 3aBba2c00a10DA3C3AAa1a00bc1BCa33bBDb1da0baBBaAa01D11AA0adcaaB13323A33Ac3DCdcAC\
203 1131bCdB1d1BddaCaAD0Ab131bad2d30abBaca0D2bccd2Ccd2");
204 "2dcC2dccb2D0acaBba03d2dab131bA0DAaCaddB1d1BdCb1311CAcdCD3cA33A32331Baacd\
205 a0AA11D10aAaBBab0ad1bDBb33aCB1cb00a1aAA3C3AD01a00c2abBa3AbD0d3c30aB030aBAdA21B\
206 Da2D2aAc0Ba0ADAbA23c0022Ad31BD0DACAaBca013A1abCBCd";
208 ssearch("~s", "~{~S ~}~%", 'sequalignore);
210 ssearch ("foo", "bar");
211 false;
212 ssort("I don't like Mondays.");
213 "   '.IMaddeiklnnoosty"$
214 block([us_ascii_only:true], ssort("I don't like Mondays.", 'cgreaterpignore));
215 "ytsoonnMlkIiedda.'   "$   
217 /* SF bug report #3329: "Simplode overlimited at Maxima with GCL"
218  * (same bug in ssort; ensure it works OK for long strings
219  */
220 ssort ("fTgTgHZyfUfYOWTTWezffIITTfQxwWaWyTdaIfyeawITRfaTfywaIgWdePTefegfIaOeIWT\
221 WgOgHfOIddgOTdZIdIwwPTfOaIITeyygxdddTWdfyWOOOOTZPHfTHHydIaTTdTeggwwHZHWHTfeHfZ\
222 IOydPgTTeHORaweaZPIHaefHTgXaTwdTgZyOReTyfIaZZeZeyfPTHHZfWage");
223 "HHHHHHHHHHHHHHIIIIIIIIIIIIIIIIOOOOOOOOOOOOOPPPPPPQRRRTTTTTTTTTTTTTTTTTT\
224 TTTTTTTTTTUWWWWWWWWWWWXYZZZZZZZZZZZaaaaaaaaaaaaaaddddddddddddddeeeeeeeeeeeeeee\
225 efffffffffffffffffffffggggggggggggggwwwwwwwwwxxyyyyyyyyyyyyz";
227 ssubst("like", "hate", "I hate Thai food. I hate green tea.");
228 "I like Thai food. I like green tea."$
229 ssubst("Black", "Green", "Green light. Green tea. Greenwich.", 'sequal, 10, 20);
230 "Green light. Black tea. Greenwich."$
232 /* SF bug #3700, ssubst crashes with large number of substitutions
233    construct the long strings via concat
235 block([s:lreduce(concat,makelist("a",k,1,1400)), r:lreduce(concat,makelist("b",k,1,1400))],
236   sequal(r,ssubst("b","a",s))) $
237 true $
239 "  /* comment */  ";
240 "  /* comment */  "$
241 strim(" /*", %);
242 "comment"$
243 slength(%);
245 substring("substring", 4);
246 "string"$
247 substring(%, 4, 6);
248 "in"$
249 supcase("english", 1, 2);
250 "English"$
251 tokens("24 October 2005");
252 ["24","October","2005"]$
253 tokens("05-10-24", 'digitcharp);
254 ["05","10","24"]$
255 map(parse_string, %);
256 [5,10,24]$
258 (remvalue(m,l,c,control,foo,bar,s), 0);