use crate::coq;
use crate::isabelle;
use crate::lean;
use crate::proof::Proof;
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ProofFormat {
Coq,
Lean3,
Lean4,
Isabelle,
}
impl ProofFormat {
#[must_use]
pub fn extension(&self) -> &str {
match self {
ProofFormat::Coq => "v",
ProofFormat::Lean3 | ProofFormat::Lean4 => "lean",
ProofFormat::Isabelle => "thy",
}
}
#[must_use]
pub fn name(&self) -> &str {
match self {
ProofFormat::Coq => "Coq",
ProofFormat::Lean3 => "Lean 3",
ProofFormat::Lean4 => "Lean 4",
ProofFormat::Isabelle => "Isabelle/HOL",
}
}
#[must_use]
pub fn convert(&self, proof: &Proof) -> String {
match self {
ProofFormat::Coq => coq::export_to_coq(proof),
ProofFormat::Lean3 => lean::export_to_lean3(proof),
ProofFormat::Lean4 => lean::export_to_lean(proof),
ProofFormat::Isabelle => isabelle::export_to_isabelle(proof, "Proof"),
}
}
}
impl fmt::Display for ProofFormat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.name())
}
}
pub mod quick {
use super::*;
#[must_use]
pub fn to_coq(proof: &Proof) -> String {
ProofFormat::Coq.convert(proof)
}
#[must_use]
pub fn to_lean3(proof: &Proof) -> String {
ProofFormat::Lean3.convert(proof)
}
#[must_use]
pub fn to_lean(proof: &Proof) -> String {
ProofFormat::Lean4.convert(proof)
}
#[must_use]
pub fn to_isabelle(proof: &Proof) -> String {
ProofFormat::Isabelle.convert(proof)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_format_extension() {
assert_eq!(ProofFormat::Coq.extension(), "v");
assert_eq!(ProofFormat::Lean4.extension(), "lean");
assert_eq!(ProofFormat::Isabelle.extension(), "thy");
}
#[test]
fn test_format_name() {
assert_eq!(ProofFormat::Coq.name(), "Coq");
assert_eq!(ProofFormat::Lean3.name(), "Lean 3");
assert_eq!(ProofFormat::Isabelle.name(), "Isabelle/HOL");
}
#[test]
fn test_format_display() {
assert_eq!(ProofFormat::Coq.to_string(), "Coq");
assert_eq!(ProofFormat::Lean4.to_string(), "Lean 4");
}
#[test]
fn test_convert_to_coq() {
let mut proof = Proof::new();
proof.add_axiom("p");
let result = ProofFormat::Coq.convert(&proof);
assert!(!result.is_empty());
}
#[test]
fn test_convert_to_lean() {
let mut proof = Proof::new();
proof.add_axiom("p");
let result = ProofFormat::Lean4.convert(&proof);
assert!(!result.is_empty());
}
#[test]
fn test_convert_to_isabelle() {
let mut proof = Proof::new();
proof.add_axiom("p");
let result = ProofFormat::Isabelle.convert(&proof);
assert!(!result.is_empty());
}
#[test]
fn test_quick_conversion_coq() {
let mut proof = Proof::new();
proof.add_axiom("p");
let result = quick::to_coq(&proof);
assert!(!result.is_empty());
}
#[test]
fn test_quick_conversion_lean() {
let mut proof = Proof::new();
proof.add_axiom("p");
let result = quick::to_lean(&proof);
assert!(!result.is_empty());
}
#[test]
fn test_quick_conversion_isabelle() {
let mut proof = Proof::new();
proof.add_axiom("p");
let result = quick::to_isabelle(&proof);
assert!(!result.is_empty());
}
}