| author | kleing | 
| Wed, 15 Oct 2008 00:18:43 +0200 | |
| changeset 28598 | cb5f98e2e187 | 
| parent 28020 | 1ff5167592ba | 
| child 29606 | fedb8be05f24 | 
| permissions | -rw-r--r-- | 
| 21637 | 1 | (* Title: Pure/ProofGeneral/pgip_tests.ML | 
| 2 | ID: $Id$ | |
| 3 | Author: David Aspinall | |
| 4 | ||
| 5 | A test suite for the PGIP abstraction code (in progress). | |
| 21940 | 6 | Run to provide some mild insurance against breakage in Isabelle here. | 
| 21637 | 7 | *) | 
| 8 | ||
| 9 | (** pgip_types.ML **) | |
| 10 | ||
| 11 | local | |
| 12 | fun asseq_p toS a b = | |
| 13 | if a=b then () | |
| 14 |     else error("PGIP test: expected these two values to be equal:\n" ^
 | |
| 28020 | 15 | (toS a) ^"\n and: \n" ^ (toS b)) | 
| 21637 | 16 | |
| 26541 | 17 | val asseqx = asseq_p XML.string_of | 
| 21637 | 18 | val asseqs = asseq_p I | 
| 19 | val asseqb = asseq_p (fn b=>if b then "true" else "false") | |
| 20 | ||
| 21 | open PgipTypes; | |
| 22 | in | |
| 23 | ||
| 26541 | 24 | val _ = asseqx (pgiptype_to_xml Pgipnull) (XML.parse "<pgipnull/>"); | 
| 25 | val _ = asseqx (pgiptype_to_xml Pgipbool) (XML.parse "<pgipbool/>"); | |
| 26 | val _ = asseqx (pgiptype_to_xml (Pgipint (NONE,NONE))) (XML.parse "<pgipint/>"); | |
| 27 | val _ = asseqx (pgiptype_to_xml (Pgipint (SOME 5,SOME 7))) (XML.parse "<pgipint min='5' max='7'/>"); | |
| 28 | val _ = asseqx (pgiptype_to_xml (Pgipint (NONE,SOME 7))) (XML.parse "<pgipint max='7'/>"); | |
| 29 | val _ = asseqx (pgiptype_to_xml (Pgipint (SOME ~5,NONE))) (XML.parse "<pgipint min='-5'/>"); | |
| 30 | val _ = asseqx (pgiptype_to_xml Pgipstring) (XML.parse "<pgipstring/>"); | |
| 31 | val _ = asseqx (pgiptype_to_xml (Pgipconst "radio1")) (XML.parse "<pgipconst name='radio1'/>"); | |
| 21637 | 32 | val _ = asseqx (pgiptype_to_xml (Pgipchoice [Pgipdtype (SOME "the best choice",Pgipbool)])) | 
| 26541 | 33 | (XML.parse "<pgipchoice><pgipbool descr='the best choice'/></pgipchoice>"); | 
| 21637 | 34 | |
| 35 | val _ = asseqs (pgval_to_string (read_pgval Pgipbool "true")) "true"; | |
| 36 | val _ = asseqs (pgval_to_string (read_pgval Pgipbool "false")) "false"; | |
| 37 | val _ = asseqs (pgval_to_string (read_pgval (Pgipint(NONE,NONE)) "-37")) "-37"; | |
| 38 | val _ = asseqs (pgval_to_string (read_pgval Pgipnat "45")) "45"; | |
| 39 | val _ = asseqs (pgval_to_string (read_pgval Pgipstring "stringvalue")) "stringvalue"; | |
| 40 | ||
| 41 | local | |
| 42 | val choices = Pgipchoice [Pgipdtype (NONE,Pgipbool), Pgipdtype (NONE,Pgipnat), | |
| 28020 | 43 | Pgipdtype (NONE,Pgipnull), Pgipdtype (NONE,Pgipconst "foo")] | 
| 21637 | 44 | in | 
| 45 | val _ = asseqs (pgval_to_string (read_pgval choices "45")) "45"; | |
| 46 | val _ = asseqs (pgval_to_string (read_pgval choices "foo")) "foo"; | |
| 47 | val _ = asseqs (pgval_to_string (read_pgval choices "true")) "true"; | |
| 48 | val _ = asseqs (pgval_to_string (read_pgval choices "")) ""; | |
| 49 | val _ = (asseqs (pgval_to_string (read_pgval choices "-37")) "-37"; | |
| 28020 | 50 | error "pgip_tests: should fail") handle PGIP _ => () | 
| 21637 | 51 | end | 
| 52 | ||
| 53 | val _ = asseqx (haspref {name="provewithgusto",descr=SOME "use energetic proofs",
 | |
| 28020 | 54 | default=SOME "true", pgiptype=Pgipbool}) | 
| 26541 | 55 | (XML.parse "<haspref name='provewithgusto' descr='use energetic proofs' default='true'><pgipbool/></haspref>"); | 
| 21637 | 56 | end | 
| 57 | ||
| 58 | ||
| 59 | (** pgip_input.ML **) | |
| 60 | local | |
| 61 | ||
| 26541 | 62 | fun e str = case XML.parse str of | 
| 28020 | 63 | (XML.Elem args) => args | 
| 64 |               | _ => error("Expected to get an XML Element")
 | |
| 21637 | 65 | |
| 66 | open PgipInput; | |
| 22164 | 67 | open PgipTypes; | 
| 22407 | 68 | open PgipIsabelle; | 
| 21637 | 69 | |
| 70 | fun asseqi a b = | |
| 21940 | 71 | if input (e a) = b then () | 
| 21637 | 72 |     else error("PGIP test: expected two inputs to be equal, for input:\n" ^ a)
 | 
| 73 | ||
| 74 | in | |
| 75 | ||
| 76 | val _ = asseqi "<askpgip/>" (SOME (Askpgip())); | |
| 77 | val _ = asseqi "<askpgml/>" (SOME (Askpgml())); | |
| 78 | val _ = asseqi "<askconfig/>" (SOME (Askconfig())); | |
| 23436 
343e84195e2c
Remove dedicated flag setting elements in favour of setproverflag.
 aspinall parents: 
22407diff
changeset | 79 | (* FIXME: new tests: | 
| 22083 | 80 | val _ = asseqi "<pgmlsymbolson/>" (SOME (Pgmlsymbolson())); | 
| 81 | val _ = asseqi "<pgmlsymbolsoff/>" (SOME (Pgmlsymbolsoff())); | |
| 82 | val _ = asseqi "<startquiet/>" (SOME (Startquiet())); | |
| 83 | val _ = asseqi "<stopquiet/>" (SOME (Stopquiet())); | |
| 23436 
343e84195e2c
Remove dedicated flag setting elements in favour of setproverflag.
 aspinall parents: 
22407diff
changeset | 84 | *) | 
| 22164 | 85 | val _ = asseqi "<askrefs thyname='foo' objtype='theory'/>" (SOME (Askrefs {url=NONE, thyname=SOME "foo",
 | 
| 28020 | 86 | objtype=SOME ObjTheory,name=NONE})); | 
| 21637 | 87 | val _ = asseqi "<otherelt/>" NONE; | 
| 88 | ||
| 89 | end | |
| 90 | ||
| 21867 | 91 | (** pgip_markup.ML **) | 
| 92 | local | |
| 93 | open PgipMarkup | |
| 94 | in | |
| 95 | val _ = () | |
| 96 | end | |
| 97 | ||
| 98 | ||
| 21637 | 99 | (** pgip_output.ML **) | 
| 100 | local | |
| 101 | open PgipOutput | |
| 102 | in | |
| 103 | val _ = () | |
| 104 | end | |
| 105 | ||
| 21867 | 106 | |
| 25275 | 107 | (** pgip_parser.ML **) | 
| 21867 | 108 | local | 
| 109 | open PgipMarkup | |
| 25275 | 110 | open PgipParser | 
| 22407 | 111 | open PgipIsabelle | 
| 112 | ||
| 21867 | 113 | fun asseqp a b = | 
| 25275 | 114 | if pgip_parser Position.none a = b then () | 
| 21867 | 115 |     else error("PGIP test: expected two parses to be equal, for input:\n" ^ a)
 | 
| 116 | ||
| 117 | in | |
| 118 | val _ = | |
| 119 | asseqp "theory A imports Bthy Cthy Dthy begin" | |
| 120 | [Opentheory | |
| 121 |          {text = "theory A imports Bthy Cthy Dthy begin",
 | |
| 24192 
4eccd4bb8b64
PGIP change: thyname is optional in opentheory, markup even in case of header parse failure
 aspinall parents: 
23798diff
changeset | 122 | thyname = SOME "A", | 
| 22407 | 123 | parentnames = ["Bthy", "Cthy", "Dthy"]}, | 
| 124 |      Openblock {metavarid=NONE,name=NONE,objtype=SOME ObjTheoryBody}];
 | |
| 21867 | 125 | |
| 126 | val _ = | |
| 127 | asseqp "end" | |
| 22407 | 128 |    [Closeblock {}, Closetheory {text = "end"}];
 | 
| 21867 | 129 | |
| 130 | end |