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