2023-12-05 19:07:00 -08:00
|
|
|
|
import LSpec
|
|
|
|
|
import Pantograph.Serial
|
2023-12-15 10:40:36 -08:00
|
|
|
|
import Pantograph.Environment
|
2024-01-16 13:29:30 -08:00
|
|
|
|
import Test.Common
|
2023-12-05 19:07:00 -08:00
|
|
|
|
|
2023-12-26 09:22:57 -08:00
|
|
|
|
namespace Pantograph.Test.Environment
|
2023-12-05 19:07:00 -08:00
|
|
|
|
|
|
|
|
|
open Pantograph
|
|
|
|
|
open Lean
|
|
|
|
|
|
2024-01-16 13:29:30 -08:00
|
|
|
|
deriving instance DecidableEq, Repr for Protocol.InductInfo
|
|
|
|
|
deriving instance DecidableEq, Repr for Protocol.EnvInspectResult
|
|
|
|
|
|
2023-12-05 19:07:00 -08:00
|
|
|
|
def test_symbol_visibility (env: Environment): IO LSpec.TestSeq := do
|
|
|
|
|
let entries: List (Name × Bool) := [
|
|
|
|
|
("Nat.add_comm".toName, false),
|
2023-12-08 16:17:16 -08:00
|
|
|
|
("Lean.Name".toName, true)
|
2023-12-05 19:07:00 -08:00
|
|
|
|
]
|
|
|
|
|
let suite := entries.foldl (λ suites (symbol, target) =>
|
|
|
|
|
let constant := env.constants.find! symbol
|
2023-12-15 10:40:36 -08:00
|
|
|
|
let test := LSpec.check symbol.toString ((Environment.is_symbol_unsafe_or_internal symbol constant) == target)
|
2023-12-05 19:07:00 -08:00
|
|
|
|
LSpec.TestSeq.append suites test) LSpec.TestSeq.done
|
|
|
|
|
return suite
|
|
|
|
|
|
2024-01-16 13:29:30 -08:00
|
|
|
|
def test_inspect (env: Environment): IO LSpec.TestSeq := do
|
|
|
|
|
let inner: CoreM LSpec.TestSeq := do
|
|
|
|
|
let args: Protocol.EnvInspect := { name := "Or" }
|
|
|
|
|
let result ← match ← Environment.inspect args (options := {}) with
|
|
|
|
|
| .ok result => pure $ result
|
|
|
|
|
| .error e => panic! s!"Error: {e.desc}"
|
|
|
|
|
--IO.println s!"{reprStr result.inductInfo?}"
|
|
|
|
|
let test := LSpec.check "Or" (result.inductInfo? == .some {
|
|
|
|
|
numParams := 2,
|
|
|
|
|
numIndices := 0,
|
|
|
|
|
all := ["Or"],
|
|
|
|
|
ctors := ["Or.inl", "Or.inr"],
|
|
|
|
|
})
|
|
|
|
|
return LSpec.TestSeq.append LSpec.TestSeq.done test
|
|
|
|
|
runCoreMSeq env inner
|
|
|
|
|
|
2023-12-05 19:07:00 -08:00
|
|
|
|
def suite: IO LSpec.TestSeq := do
|
|
|
|
|
let env: Environment ← importModules
|
|
|
|
|
(imports := #["Init"].map (λ str => { module := str.toName, runtimeOnly := false }))
|
|
|
|
|
(opts := {})
|
|
|
|
|
(trustLevel := 1)
|
|
|
|
|
|
2023-12-26 09:22:57 -08:00
|
|
|
|
return LSpec.group "Environment" $
|
2024-01-16 13:29:30 -08:00
|
|
|
|
(LSpec.group "Symbol visibility" (← test_symbol_visibility env)) ++
|
|
|
|
|
(LSpec.group "Inspect" (← test_inspect env))
|
2023-12-05 19:07:00 -08:00
|
|
|
|
|
2023-12-26 09:22:57 -08:00
|
|
|
|
end Pantograph.Test.Environment
|