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