Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pure] [lsp] Try to recover unit testing of pure interface #403

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lambdapi.opam
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ depends: [
"cmdliner" {>= "1.1.0"}
"stdlib-shims" {>= "0.1.0"}
"odoc" {with-doc}
# tests
"ppx_inline_test" { with-test }
]
build: [
["dune" "subst"] {dev}
Expand Down
2 changes: 2 additions & 0 deletions src/pure/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
(name pure)
(public_name lambdapi.pure)
(modules :standard)
(inline_tests (deps tests/foo.lp tests/lambdapi.pkg))
(preprocess (pps ppx_inline_test))
(libraries camlp-streams lambdapi.handle lambdapi.core)
(flags -w +3))
26 changes: 26 additions & 0 deletions src/pure/foo.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
constant symbol B : TYPE;

constant symbol true : B;
constant symbol false : B;

symbol neg : B → B;

rule neg true ↪ false;
rule neg false ↪ true;

constant symbol Prop : TYPE;

injective symbol P : Prop → TYPE;

constant symbol eq : B → B → Prop;
constant symbol refl b : P (eq b b);

constant symbol case (p : B → Prop) : P (p true) → P (p false) → Π b, P b;

opaque symbol notK : Π b, P (eq (neg (neg b)) b)
≔ begin
assume b;
apply case (λ b, eq (neg (neg b)) b)
{apply refl}
{apply refl}
end;
56 changes: 56 additions & 0 deletions src/pure/pure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,59 @@ let end_proof : proof_state -> command_result =

let get_symbols : state -> Term.sym Extra.StrMap.t =
fun (_, ss) -> ss.in_scope

(* Equality on *)
let test_file = "./tests/foo.lp"

let%test _ =
let st = initial_state test_file in
let (c,_) = parse_text st ~fname:test_file "constant symbol B : TYPE;" in
List.equal Command.equal c c

(* Equality not *)
let%test _ =
let st = initial_state test_file in
let (c,_) = parse_text st ~fname:test_file "constant symbol B : TYPE;" in
let (d,_) = parse_text st ~fname:test_file "constant symbol C : TYPE;" in
not (List.equal Command.equal c d)

(* Equality is not sensitive to whitespace *)
let%test _ =
let st = initial_state test_file in
let (c,_) = parse_text st ~fname:test_file "constant symbol B : TYPE;" in
let (d,_) = parse_text st ~fname:test_file " constant symbol B : TYPE; " in
List.equal Command.equal c d

(* More complex test stressing most commands *)
let%test _ =
let st = initial_state test_file in
let (c,_) = parse_text st ~fname:test_file
(* copied from tests/OK/foo.lp. keep in sync. *)
"constant symbol B : TYPE;

constant symbol true : B;
constant symbol false : B;

symbol neg : B → B;

rule neg true ↪ false;
rule neg false ↪ true;

constant symbol Prop : TYPE;

injective symbol P : Prop → TYPE;

constant symbol eq : B → B → Prop;
constant symbol refl b : P (eq b b);

constant symbol case (p : B → Prop) : P (p true) → P (p false) → Π b, P b;

opaque symbol notK : Π b, P (eq (neg (neg b)) b)
≔ begin
assume b;
apply case (λ b, eq (neg (neg b)) b)
{apply refl}
{apply refl}
end;
" in
List.equal Command.equal c c
26 changes: 26 additions & 0 deletions src/pure/tests/foo.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
constant symbol B : TYPE

constant symbol true : B
constant symbol false : B

symbol neg : B ⇒ B

rule neg true → false
rule neg false → true

constant symbol Prop : TYPE

injective symbol P : Prop ⇒ TYPE

constant symbol eq : B ⇒ B ⇒ Prop
constant symbol refl b : P (eq b b)

constant symbol case (p : B⇒Prop) : P (p true) ⇒ P (p false) ⇒ ∀b, P b

theorem notK : ∀b, P (eq (neg (neg b)) b)
proof
assume b
apply case (λb, eq (neg (neg b)) b)
apply refl
apply refl
qed
2 changes: 2 additions & 0 deletions src/pure/tests/lambdapi.pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package_name = tests
root_path = tests