PROGRAM test_dictionary (input, output); {-*-Mode: fundamental-mode}
uses dictionary;
var
  err_count: integer;
  d1, d2   : dic_handle_t;
  sym      : dic_sym;
  indx     : dic_indx;

procedure err;
begin err_count:= err_count+1; writeln ('Error ', err_count) end;

procedure write_symbol_table (handle : dic_handle_t);
var index: dic_indx;
begin
 for index:=1 to dic_last_indx (handle) do
     writeln (index:5, ' ', dic_symbol (handle, index))
end;

BEGIN
 err_count:= 0;
 writeln      ('Dictionary test');
 dic_new      (d1, true);

 sym:= 's1';    if dic_sym2indx (d1, sym, indx, create)  then else err;
 sym:= 's2';    if dic_sym2indx (d1, sym, indx, create)  then else err;
 sym:= 's3';    if dic_sym2indx (d1, sym, indx, create)  then else err;

 sym:= 's1';    if dic_sym2indx (d1, sym, indx, exist)   then else err;
 sym:= 's2';    if dic_sym2indx (d1, sym, indx, exist)   then else err;
 sym:= 's3';    if dic_sym2indx (d1, sym, indx, exist)   then else err;

 sym:= 's1';    if dic_sym2indx (d1, sym, indx, unknown) then else err;
 sym:= 's2';    if dic_sym2indx (d1, sym, indx, unknown) then else err;
 sym:= 's3';    if dic_sym2indx (d1, sym, indx, unknown) then else err;

 sym:= 's4';    if dic_sym2indx (d1, sym, indx, unknown) then else err;

 writeln ('d1 contents:'); write_symbol_table (d1);

 dic_write  (d1, 'dummy');
 dic_new    (d2, true);
 dic_read   (d2, 'dummy');
 writeln ('d2 contents:'); write_symbol_table (d2);

{dic_diagnostic (d1);}
 dic_dispose (d1);
 writeln ('Test End, Error count=', err_count)
END.
