Commit 88d452c1 authored by Kim Nguyễn's avatar Kim Nguyễn
Browse files

Add more tests.

parent c3679d9a
......@@ -14,10 +14,28 @@
(rule (alias integers) (action (diff integers.exp integers.out)))
; end: integers.cd
; begin: lazy.cd
(rule (deps lazy.cd) (target lazy.cdo)
(action (with-accepted-exit-codes 0 (run cduce --compile %{deps}))))
(rule (deps lazy.cdo) (target lazy.out)
(action (ignore-stderr (with-stdout-to %{target} (with-accepted-exit-codes 0 (run cduce --run %{deps}))))))
(rule (alias lazy) (action (diff lazy.exp lazy.out)))
; end: lazy.cd
; begin: overloading.cd
(rule (deps overloading.cd) (target overloading.cdo)
(action (with-accepted-exit-codes 0 (run cduce --compile %{deps}))))
(rule (deps overloading.cdo) (target overloading.out)
(action (ignore-stderr (with-stdout-to %{target} (with-accepted-exit-codes 0 (run cduce --run %{deps}))))))
(rule (alias overloading) (action (diff overloading.exp overloading.out)))
; end: overloading.cd
(alias (name runtest)
(deps
(source_tree ../common)
(alias addrbook)
(alias integers)
(alias lazy)
(alias overloading)
))
let f =
let r = ref (`Cached,Int)| `None `None in
fun ([] : []) : Int =
match !r with
| (`Cached,x) -> x
| `None -> let x = (print "EVAL\n"; 10) in r := (`Cached,x); x;;
f [];;
f [];;
type Person = FPerson | MPerson
type FPerson = <person gender = "F" >[ Name Children (Tel | Email)?]
type MPerson = <person gender="M">[ Name Children (Tel | Email)?]
type Children = <children>[Person*]
type Name = <name>[ PCDATA ]
type Tel = <tel kind=?"home"|"work">['0'--'9'+ '-' '0'--'9'+]
type Email = <email>[PCDATA '@' PCDATA]
type Man = <man name=String>[ Sons Daughters ]
type Woman = <woman name=String>[ Sons Daughters ]
type Sons = <sons>[ Man* ]
type Daughters = <daughters>[ Woman* ]
let fun sort (MPerson -> Man ; FPerson -> Woman)
<person gender=g>[ <name>n <children>[(mc::MPerson | fc::FPerson)*]; _] ->
let tag = match g with "F" -> `woman | "M" -> `man in
let s = map mc with x -> sort x in
let d = map fc with x -> sort x in
<(tag) name=n>[ <sons>s <daughters>d ]
let fun sort2 (MPerson -> Man ; FPerson -> Woman)
<person gender=(("F" & (tag := `woman)) | (tag := `man))>[ <name>n <children>[(mc::MPerson | fc::FPerson)*]; _] ->
let s = map mc with x -> sort x in
let d = map fc with x -> sort x in
<(tag) name=n>[ <sons>s <daughters>d ]
let base : Person =
<person gender="M">[
<name>"Claude"
<children>[
<person gender="F">[
<name>"Véronique"
<children>[
<person gender="F">[
<name>"Ilaria"
<children>[]
]
]
<tel> "314-1592654"
]
]
];;
print (print_xml (sort2 base));;
(*
let fun contact(Person -> String)
| <person>[ _ _ ((<tel kind="work"> x) | (<email> x) | (<tel> x))] -> x
| _ ->"no contact";;
contact(
<person gender="F">[
<name>"Véronique"
<children>[
<person gender="F">[
<name>"Ilaria"
<children>[]
]
]
<tel> "314-1592654"
])
;;
contact base;;
(* compilation efficace avec _ a la place de person *)
let fun name (Person | Man | Woman -> String)
<person>[ <name>n ; _ ]
| <_ name=n>_ -> n;;
name base;;
name (sort base);;
transform [ base base ] with
<person>[ n <children>[Person]; _] -> [n]
| _ -> [];;
*)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment