home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / print / pret.tst < prev    next >
Encoding:
Text File  |  1988-05-03  |  12.6 KB  |  505 lines

  1. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2. --all.in
  3. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  4. -- tests pretty printer on a variety of constructs: context clause, package
  5. -- specification, private part, package body, record types, rep specs,
  6. -- package renames, generic instantiation, basic declarations, procedure body,
  7. -- stub, function body, exception handler, case, loop, block, selective wait
  8. with a; use a; with b; with c; with d;
  9.  
  10. package outermost is
  11. type t;
  12. private
  13. type t is array (1 .. 2) of natural;
  14. end;
  15.  
  16. package body outermost is
  17.  
  18. type psw is record sm:byte_mask; prot_key: integer range 0 .. 3;
  19. machine_state: state_Mask; end record;
  20.  
  21. for psw use record at mod 8; sm at 0*word range 0 .. 7;
  22.  prot_key at 0*word range 10 .. 11; machine_state at 0*word range 12 ..15;
  23.  end record;
  24.  
  25.  type x is record first : component; second : component;
  26.  end record;
  27.  
  28.  type y is array ( 1 ..   10)of integer;
  29.  
  30.  integer_object : integer; 
  31.  var1 : y;
  32.  var2 : t;
  33.  
  34. package z renames d;
  35. package apackage is new c(natural);
  36.  
  37. procedure first_procedure is
  38. procedure b is separate;
  39. function "=" return String is
  40. begin
  41. x;
  42. y;
  43. begin
  44. z(q);
  45. exception
  46. when invalid_q => put("Invalid q");
  47. when others => raise;
  48. end;
  49. return q;
  50. end;
  51.  
  52.  
  53.  
  54. begin
  55. case integer_object is 
  56. when 1 | 2 | 15 => null;
  57. when 3 =>
  58. b.put("integer_object is 3");
  59. when others => 
  60. loop integer_object := integer_object + 2; 
  61. if integer_object = 0 then
  62. b.put("integer_object is 0");
  63. elsif integer_object > 2 then
  64. if var2(integer_object) = 10 then
  65. b.switch(var2(integer_object));
  66. end if;
  67. b.put("integer_object is greater than 2");
  68. else
  69. b.switch(integer_Object);
  70. end if;
  71. exit when integer_object > 100; end loop;
  72. end case;
  73.  
  74. select accept a; or accept b; or delay 1.5; or when c => accept d; 
  75. or when d => accept e;
  76.     else i := 1; b := 2; end select;
  77.  
  78. end;
  79. end;
  80. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  81. --andthen.in
  82. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  83. -- tests spacing of tokens for "and then" and "or else"
  84. procedure x is
  85. begin
  86. if ((a and b) and then c) or else ((d or e) or else q) then
  87. b; else x; end if; end;
  88. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  89. --binop.in
  90. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  91. -- test binary vs. unary operators.
  92. procedure a is
  93. begin
  94.    a := + 1 -( - 3);
  95.    b := 1-3;
  96.    c := 1+3-(+2)+(-1);
  97. end;
  98. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  99. --blanks.in
  100. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  101. -- Tests that blanks in the source are printed
  102. procedure a is
  103.  
  104.  
  105. b : integer;
  106.  
  107. begin
  108. if a = b then
  109.  
  110.  
  111. if a = b then
  112. if a = b then
  113.  
  114. if a= b then
  115. fool
  116. ;
  117. end if; end if; end if; end if; end;  
  118. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  119. --closeid.in
  120. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  121. -- Tests that closing identifiers are printed out
  122.  
  123. -- test normal nesting
  124. package body a is package body b is end; end;
  125.  
  126. package body a is package body b is end b; end;
  127.  
  128. package body a is package b is end; end a;
  129.  
  130. package body x is procedure a is procedure b is begin null; end; begin null; 
  131. end; end;
  132.  
  133. procedure a is procedure b is begin null; end; begin null; end;
  134.  
  135. -- test nesting of blocks
  136. package body x is begin a:begin b:begin null; end; end; end;
  137.  
  138. package body x is begin a:begin b:begin null; end b; end; end;
  139.  
  140. package body x is begin a:begin b:begin null; end; end a; end;
  141.  
  142. package body x is begin begin b:begin null; end; end; end;
  143.  
  144. package body x is begin a:begin begin null; end; end; end;
  145.  
  146. package body x is begin begin begin null; end; end; end;
  147.  
  148. package body x is begin begin b:begin null; end b; end a; end;
  149.  
  150. package body x is begin begin begin null; end a; end b; end;
  151.  
  152. package body x is begin a:begin begin null; end b; end a; end;
  153.  
  154. package body x is begin a: begin begin null; end b; end; end;
  155.  
  156. -- test nesting of loops 
  157. package body x is begin a:loop b:loop null; end loop; end loop; end;
  158.  
  159. package body x is begin a:loop b:loop null; end loop b; end loop; end;
  160.  
  161. package body x is begin a:loop b:loop null; end loop; end loop a; end;
  162.  
  163. package body x is begin loop b:loop null; end loop; end loop; end;
  164.  
  165. package body x is begin a:loop loop null; end loop; end loop; end;
  166.  
  167. package body x is begin loop loop null; end loop; end loop; end;
  168.  
  169. package body x is begin loop b:loop null; end loop b; end loop a; end;
  170.  
  171. package body x is begin loop loop null; end loop a; end loop b; end;
  172.  
  173. package body x is begin a:loop loop null; end loop b; end loop a; end;
  174.  
  175. package body x is begin a:loop loop null; end loop b; end loop; end;
  176.  
  177. -- test nesting of loops and blocks
  178. package body x is begin a:begin b:loop null; end loop; end ; end;
  179.  
  180. package body x is begin a:loop b:loop begin null; end a; end loop b; end loop;
  181.  end;
  182.  
  183. package body x is begin begin a:loop b:loop null; end loop; end loop a; end;
  184. end;
  185.  
  186. -- test functions and procedures
  187.  
  188. function x return y is begin null; end;
  189.  
  190. procedure x is begin null; end;
  191.  
  192. function "=" return z is begin null; end;
  193.  
  194. procedure x is function "+" return y is begin null; end;begin null; end;
  195.  
  196. -- test separate units
  197.  
  198. procedure x is procedure y is separate; begin null; end;
  199.  
  200. function x return y is procedure y is separate; begin null;end;
  201.  
  202. function "-" return x is task body a is separate; begin null; end;
  203.  
  204. package body a is package body b is separate; begin null; end;
  205.  
  206. package body x is function y return z is separate; end;
  207.  
  208. package body x is procedure y is separate; end;
  209.  
  210. package body x is task body y is separate; end;
  211.  
  212. -- tasks
  213.  
  214. procedure x is task y is entry b; end; begin null; end;
  215.  
  216. package body a is task b; end;
  217.  
  218. package body x is task body y is begin null; end; begin null; end;
  219.  
  220. -- accepts
  221.  
  222. procedure s is begin select accept a; end select; end;
  223.  
  224. procedure s is begin select accept a do i := 1; end; end select; end;
  225. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  226. --colon.in
  227. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  228. -- tests lining up colons.  Tests that only sequences of object and number
  229. -- declaration are lined up
  230. procedure a is
  231. x : integer; -- comment
  232. xyz : constant := 2+3;
  233.  
  234. type y is array(1 .. 10)of integer;
  235. a,b,c: integer;
  236. xx, -- comment
  237. d  -- comment
  238. ,
  239. e : natural;
  240. subtype two is natural range 2 .. 2;
  241. f,g,h: integer;
  242. yy, -- comment
  243. atwentycharactername  -- comment
  244. ,
  245. i : natural;
  246.  
  247. begin
  248. j := k+1;
  249. end;
  250. procedure foo(i : integer; j : natural; k : positive);
  251.  
  252.  
  253. procedure foo( -- comment
  254. x : integer; -- comment
  255.  y : natural; -- comment
  256.  name : positive -- comment
  257. );
  258.  
  259. procedure foo(
  260. x : integer; -- comment
  261.  y : natural; -- comment
  262.  name : positive; -- comment
  263. name2:natural 
  264. );
  265. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  266. --comment.in
  267. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  268. -- test comments with formatting on or off.
  269. procedure a is -- test comments
  270. i : integer;-- another test
  271.       -- a comment
  272. begin-- another comment
  273. a := i;-- should put on next line (with preceding blank if formatting on)
  274. j := 2;
  275. end;
  276. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  277. --deepif.in
  278. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  279. -- tests nesting of very deep if statements (should stop indenting after a
  280. -- certain point.
  281. procedure longif is
  282. begin
  283. if a = b then
  284. if a = b then
  285. if a = b then
  286. if a = b then
  287. if a = b then
  288. if a = b then
  289. if a = b then
  290. if a = b then
  291. if a = b then
  292. if a = b then
  293. if a = b then
  294. if a = b then
  295. if a = b then
  296. if a = b then
  297. if a = b then
  298. if a = b then
  299. if a = b then
  300. if a = b then
  301. if a = b then
  302. if a = b then
  303. if a = b then
  304. if a = b then
  305. if a = b then
  306. if a = b then
  307. if a = b then
  308. if a = b then
  309. if a = b then
  310. if a = b then
  311. if a = b then
  312. if a = b then
  313. if a = b then
  314. if a = b then
  315. if a = b then
  316. if a = b then
  317. if a = b then
  318. if a = b then
  319. if a = b then
  320. if a = b then
  321. if a = b then
  322. if a = b then
  323. if a = b then
  324. if a = b then
  325. if a = b then
  326. if a = b then
  327. if a = b then
  328. if a = b then
  329. if a = b then
  330. if a = b then
  331. if a = b then
  332. if a = b then
  333. if a = b then
  334. if a = b then
  335. if a = b then
  336. if a = b then
  337. if a = b then
  338. if a = b then
  339. if a = b then
  340. if a = b then
  341. foo;
  342. end if;
  343. end if;
  344. end if;
  345. end if;
  346. end if;
  347. end if;
  348. end if;
  349. end if;
  350. end if;
  351. end if;
  352. end if;
  353. end if;
  354. end if;
  355. end if;
  356. end if;
  357. end if;
  358. end if;
  359. end if;
  360. end if;
  361. end if;
  362. end if;
  363. end if;
  364. end if;
  365. end if;
  366. end if;
  367. end if;
  368. end if;
  369. end if;
  370. end if;
  371. end if;
  372. end if;
  373. end if;
  374. end if;
  375. end if;
  376. end if;
  377. end if;
  378. end if;
  379. end if;
  380. end if;
  381. end if;
  382. end if;
  383. end if;
  384. end if;
  385. end if;
  386. end if;
  387. end if;
  388. end if;
  389. end if;
  390. end if;
  391. end if;
  392. end if;
  393. end if;
  394. end if;
  395. end if;
  396. end if;
  397. end if;
  398. end if;
  399. end if;
  400. end;
  401. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  402. --delim.in
  403. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  404. -- tests basic delimiters
  405. procedure foo (i: integer) is
  406. begin
  407. i := 4#3#;
  408. case a is
  409. when x | y | z =>
  410. put (%hi|#%%%);
  411. put (%a%%b%);
  412. put ("a""b");
  413.  put ("a%%b");
  414.   put (%a"b%);
  415.    put ("a%b");
  416.    put (%%%%);
  417.    put ("""");
  418.    put ("%");
  419.    put (%"%);
  420. end case;
  421. end;
  422. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  423. --depth.in
  424. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  425. -- contains several levels of nested units to test the DEPTH parameter
  426. with a;
  427. package a is
  428.  i : integer; j : integer;
  429.  package b is c : integer; d : integer;
  430.  procedure a; function b return String; 
  431.  package c is a : integer; private b : integer; end; end;
  432.  end;package body a is
  433. function "<" return x is
  434. procedure p is begin null; end;
  435. begin null; end;
  436. end;
  437. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  438. --error.in
  439. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  440. -- contains syntax error
  441. procedure b is
  442. begin
  443. q := 3
  444. end b;
  445. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  446. --generic.in
  447. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  448. -- tests indentation of generic specifications
  449. generic
  450. type elem is private;
  451. procedure exchange(u,v: in out elem);
  452.  
  453. generic type item is private; with function "*"(u,v: item) return
  454. item is <>; function squaring(x:item) return item;
  455.  
  456. generic type item is private; type vector is array(positive range <>) of
  457. item; with function sum (w,y:x) return item; package on_vectors is
  458. function sum(a,b:vector) return vector; function sigma(a:vector) return
  459. item; length_error:exception; end;
  460.  
  461. generic package a is n:integer; end ;
  462.  
  463. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  464. --multiple.in
  465. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  466. -- test multiple units in one file.
  467. procedure a is begin null; end; procedure b is begin null; end;
  468.     
  469. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  470. --task.in
  471. --::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  472. -- test task constructs
  473. package body b is
  474. begin
  475. -- selective wait tests, alternative is accept statement
  476. select accept a; end select;
  477. select accept a; or accept b; end select;
  478. select accept a; or accept b; or accept c; end select;
  479. select accept a; or accept b; or accept c; else i := 1; b := 2;end select;
  480. select accept a; or accept b; or when c => accept d; or when d => accept e;
  481.     end select;
  482. -- selective wait tests, alternative is delay statement
  483. select delay 1.5; end select;
  484. select delay 1.5; or delay 2.5; end select;
  485. select delay 1.5 ; or delay 2.5; or delay 3.5; end select;
  486. select delay 1.5; or delay 1.5; or delay 3.5; else i := 1; b := 2;end select;
  487. select delay 1.5; or delay 2.5; or when c => delay 4.5; or when d => delay 
  488. 60.0;    end select;
  489. -- selective wait tests, alternative is terminate alternative
  490. select terminate; end select;
  491. select terminate; or delay 2.5; end select;
  492. select terminate; or terminate; or terminate; end select;
  493. select terminate; or terminate; or when c => terminate; or when d => terminate;
  494. end select;
  495. -- conditional entry call tests
  496. select jk; else i := 1; j := 2; end select;
  497. select jk; i := 1; j := 2; else k :=1; end select;
  498. -- timed entry call tests
  499. select jk; or delay 2.5; end select;
  500. select jk; i := 1; j:=2; or delay 2.5;end select;
  501. select jk; or delay 2.5; i := 1; end select;
  502. select jk; i := 1; j := 2; or delay 2.5; i := 1; j := 2; end select;
  503. end;
  504.  
  505.