From 5324dcc64cad1457c3978e9850f63a6b0f8dffeb Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Sun, 16 Mar 2008 10:22:38 +0100 Subject: [PATCH] Unit tests for CWEB --- test/expected_dir/cweb.w/c/blanks | 1 + test/expected_dir/cweb.w/c/code | 177 ++++++++ test/expected_dir/cweb.w/documentation/blanks | 1 + .../expected_dir/cweb.w/documentation/comment | 197 +++++++++ test/src_dir/cweb.w | 415 ++++++++++++++++++ test/unit/cweb_test.rb | 7 + 6 files changed, 798 insertions(+) create mode 100644 test/expected_dir/cweb.w/c/blanks create mode 100644 test/expected_dir/cweb.w/c/code create mode 100644 test/expected_dir/cweb.w/documentation/blanks create mode 100644 test/expected_dir/cweb.w/documentation/comment create mode 100644 test/src_dir/cweb.w create mode 100644 test/unit/cweb_test.rb diff --git a/test/expected_dir/cweb.w/c/blanks b/test/expected_dir/cweb.w/c/blanks new file mode 100644 index 0000000..19c7bdb --- /dev/null +++ b/test/expected_dir/cweb.w/c/blanks @@ -0,0 +1 @@ +16 \ No newline at end of file diff --git a/test/expected_dir/cweb.w/c/code b/test/expected_dir/cweb.w/c/code new file mode 100644 index 0000000..8004ca8 --- /dev/null +++ b/test/expected_dir/cweb.w/c/code @@ -0,0 +1,177 @@ +@d banner "This is MetaPost, Version 1.002" /* printed when \MP\ starts */ +@d metapost_version "1.002" +@d mplib_version "0.20" +@d version_string " (Cweb version 0.20)" +@d true 1 +@d false 0 +typedef struct MP_instance * MP; +typedef struct MP_options { +} MP_options; +#include +#include +#include +#include +#include +#include +#include /* for access() */ +#include /* for struct tm \& co */ +#include "mplib.h" +#include "mpmp.h" /* internal header */ +#include "mppsout.h" /* internal header */ +@h +#if !defined(__GNUC__) || (__GNUC__ < 2) +# define __attribute__(x) +#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */ +void __attribute__((noinline)) +mp_do_initialize ( MP mp) { +} +int mp_initialize (MP mp) { /* this procedure gets things started properly */ +mp->history=mp_fatal_error_stop; /* in case we quit during initialization */ +t_open_out; /* open the terminal for output */ +if ( mp->bad>0 ) { +char ss[256]; +snprintf(ss,256,"Ouch---my internal constants have been clobbered!\n" +"---case %i",(int)mp->bad); +do_fprintf(mp->err_out,(char *)ss); +return mp->history; +} +mp_do_initialize(mp); /* erase preloaded mem */ +if (mp->ini_version) { +} +mp_set_job_id(mp); +mp_init_map_file(mp, mp->troff_mode); +mp->history=mp_spotless; /* ready to go! */ +if (mp->troff_mode) { +mp->internal[mp_gtroffmode]=unity; +mp->internal[mp_prologues]=unity; +} +if ( mp->start_sym>0 ) { /* insert the `\&{everyjob}' symbol */ +mp->cur_sym=mp->start_sym; mp_back_input(mp); +} +return mp->history; +} +for (i=first_text_char;i<=last_text_char;i++) { +xord(chr(i))=0177; +} +for (i=0200;i<=0377;i++) { xord(xchr(i))=i;} +for (i=0;i<=0176;i++) { xord(xchr(i))=i;} +@d loc mp->cur_input.loc_field /* location of first unread character in |buffer| */ +boolean mp_init_terminal (MP mp) { /* gets the terminal input started */ +t_open_in; +if (mp->last!=0) { +loc = mp->first = 0; +return true; +} +while (1) { +wake_up_terminal; do_fprintf(mp->term_out,"**"); update_terminal; +if ( ! mp_input_ln(mp, mp->term_in ) ) { /* this shouldn't happen */ +do_fprintf(mp->term_out,"\n! End of file on the terminal... why?"); +return false; +} +loc=mp->first; +while ( (loc<(int)mp->last)&&(mp->buffer[loc]==' ') ) +incr(loc); +if ( loc<(int)mp->last ) { +return true; /* return unless the line was all blank */ +}; +do_fprintf(mp->term_out,"Please type the name of your input file.\n"); +} +} +boolean mp_init_terminal (MP mp) ; +mp_primitive(mp, "tracingtitles",internal_quantity,mp_tracing_titles); +mp_primitive(mp, "tracingequations",internal_quantity,mp_tracing_equations); +mp_primitive(mp, "tracingcapsules",internal_quantity,mp_tracing_capsules); +mp_primitive(mp, "tracingchoices",internal_quantity,mp_tracing_choices); +mp_primitive(mp, "tracingspecs",internal_quantity,mp_tracing_specs); +mp_primitive(mp, "tracingcommands",internal_quantity,mp_tracing_commands); +mp_primitive(mp, "tracingrestores",internal_quantity,mp_tracing_restores); +mp_primitive(mp, "tracingmacros",internal_quantity,mp_tracing_macros); +mp_primitive(mp, "tracingoutput",internal_quantity,mp_tracing_output); +mp_primitive(mp, "tracingstats",internal_quantity,mp_tracing_stats); +mp_primitive(mp, "tracinglostchars",internal_quantity,mp_tracing_lost_chars); +mp_primitive(mp, "tracingonline",internal_quantity,mp_tracing_online); +mp_primitive(mp, "year",internal_quantity,mp_year); +mp_primitive(mp, "month",internal_quantity,mp_month); +mp_primitive(mp, "day",internal_quantity,mp_day); +mp_primitive(mp, "time",internal_quantity,mp_time); +mp_primitive(mp, "charcode",internal_quantity,mp_char_code); +mp_primitive(mp, "charext",internal_quantity,mp_char_ext); +mp_primitive(mp, "charwd",internal_quantity,mp_char_wd); +mp_primitive(mp, "charht",internal_quantity,mp_char_ht); +mp_primitive(mp, "chardp",internal_quantity,mp_char_dp); +mp_primitive(mp, "charic",internal_quantity,mp_char_ic); +mp_primitive(mp, "designsize",internal_quantity,mp_design_size); +mp_primitive(mp, "pausing",internal_quantity,mp_pausing); +mp_primitive(mp, "showstopping",internal_quantity,mp_showstopping); +mp_primitive(mp, "fontmaking",internal_quantity,mp_fontmaking); +mp_primitive(mp, "linejoin",internal_quantity,mp_linejoin); +mp_primitive(mp, "linecap",internal_quantity,mp_linecap); +mp_primitive(mp, "miterlimit",internal_quantity,mp_miterlimit); +mp_primitive(mp, "warningcheck",internal_quantity,mp_warning_check); +mp_primitive(mp, "boundarychar",internal_quantity,mp_boundary_char); +mp_primitive(mp, "prologues",internal_quantity,mp_prologues); +mp_primitive(mp, "truecorners",internal_quantity,mp_true_corners); +mp_primitive(mp, "mpprocset",internal_quantity,mp_procset); +mp_primitive(mp, "troffmode",internal_quantity,mp_gtroffmode); +mp_primitive(mp, "defaultcolormodel",internal_quantity,mp_default_color_model); +mp_primitive(mp, "restoreclipcolor",internal_quantity,mp_restore_clip_color); +void mp_debug_help (MP mp) { /* routine to display various things */ +integer k; +int l,m,n; +char *aline; +size_t len; +while (1) { +wake_up_terminal; +mp_print_nl(mp, "debug # (-1 to exit):"); update_terminal; +m = 0; +aline = (mp->read_ascii_file)(mp->term_in, &len); +if (len) { sscanf(aline,"%i",&m); xfree(aline); } +if ( m<=0 ) +return; +n = 0 ; +aline = (mp->read_ascii_file)(mp->term_in, &len); +if (len) { sscanf(aline,"%i",&n); xfree(aline); } +switch (m) { +default: mp_print(mp, "?"); break; +} +} +} +case 1: mp_print_word(mp, mp->mem[n]); /* display |mem[n]| in all forms */ +break; +case 2: mp_print_int(mp, info(n)); +break; +case 3: mp_print_int(mp, link(n)); +break; +case 4: mp_print_int(mp, eq_type(n)); mp_print_char(mp, ':'); mp_print_int(mp, equiv(n)); +break; +case 5: mp_print_variable_name(mp, n); +break; +case 6: mp_print_int(mp, mp->internal[n]); +break; +case 7: mp_do_show_dependencies(mp); +break; +case 9: mp_show_token_list(mp, n,null,100000,0); +break; +case 10: mp_print_str(mp, n); +break; +case 11: mp_check_mem(mp, n>0); /* check wellformedness; print new busy locations if |n>0| */ +break; +case 12: mp_search_mem(mp, n); /* look for pointers to |n| */ +break; +case 13: +l = 0; +aline = (mp->read_ascii_file)(mp->term_in, &len); +if (len) { sscanf(aline,"%i",&l); xfree(aline); } +mp_print_cmd_mod(mp, n,l); +break; +case 14: for (k=0;k<=n;k++) mp_print_str(mp, mp->buffer[k]); +break; +case 15: mp->panicking=! mp->panicking; +break; +{ +if ( mp->filename_template!=0 ) delete_str_ref(mp->filename_template); +if ( length(mp->cur_exp)==0 ) mp->filename_template=0; +else { +mp->filename_template=mp->cur_exp; add_str_ref(mp->filename_template); +} +} diff --git a/test/expected_dir/cweb.w/documentation/blanks b/test/expected_dir/cweb.w/documentation/blanks new file mode 100644 index 0000000..410b14d --- /dev/null +++ b/test/expected_dir/cweb.w/documentation/blanks @@ -0,0 +1 @@ +25 \ No newline at end of file diff --git a/test/expected_dir/cweb.w/documentation/comment b/test/expected_dir/cweb.w/documentation/comment new file mode 100644 index 0000000..0f00dc8 --- /dev/null +++ b/test/expected_dir/cweb.w/documentation/comment @@ -0,0 +1,197 @@ +% Sample CWEB file, excerpts from the libmp source code +@* \[1] Introduction. +A large piece of software like \MP\ has inherent complexity that cannot +be reduced below a certain level of difficulty, although each individual +part is fairly simple by itself. The \.{WEB} language is intended to make +the algorithms as readable as possible, by reflecting the way the +individual program pieces fit together and by providing the +cross-references that connect different parts. Detailed comments about +what is going on, and about why things were done in certain ways, have +been liberally sprinkled throughout the program. These comments explain +features of the implementation, but they rarely attempt to explain the +\MP\ language itself, since the reader is supposed to be familiar with +{\sl The {\logos METAFONT\/}book} as well as the manual +@.WEB@> +@:METAFONTbook}{\sl The {\logos METAFONT\/}book@> +{\sl A User's Manual for MetaPost}, Computing Science Technical Report 162, +AT\AM T Bell Laboratories. +@ The present implementation is a preliminary version, but the possibilities +for new features are limited by the desire to remain as nearly compatible +with \MF\ as possible. +On the other hand, the \.{WEB} description can be extended without changing +the core of the program, and it has been designed so that such +extensions are not extremely difficult to make. +The |banner| string defined here should be changed whenever \MP\ +undergoes any modifications, so that it will be clear which version of +\MP\ might be the guilty party when a problem arises. +@^extensions to \MP@> +@^system dependencies@> +@ The external library header for \MP\ is |mplib.h|. It contains a +few typedefs and the header defintions for the externally used +fuctions. +The most important of the typedefs is the definition of the structure +|MP_options|, that acts as a small, configurable front-end to the fairly +large |MP_instance| structure. +@(mplib.h@>= +@ +@