feat: env.{add, inspect}

This commit is contained in:
Leni Aniva 2024-12-11 16:32:12 -08:00
parent 47b2fbe38d
commit 359b5f8d47
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
1 changed files with 34 additions and 0 deletions

View File

@ -271,6 +271,29 @@ class Server:
]
return units
def env_add(self, name: str, t: Expr, v: Expr, is_theorem: bool = True):
result = self.run('env.add', {
"name": name,
"type": t,
"value": v,
"isTheorem": is_theorem,
})
if "error" in result:
raise ServerError(result["desc"])
def env_inspect(
self,
name: str,
print_value: bool = False,
print_dependency: bool = False) -> dict:
result = self.run('env.inspect', {
"name": name,
"value": print_value,
"dependency": print_dependency,
})
if "error" in result:
raise ServerError(result["desc"])
return result
def get_version():
import subprocess
@ -446,6 +469,17 @@ class TestServer(unittest.TestCase):
state2 = server.goal_tactic(state1, goal_id=0, tactic="exact h")
self.assertTrue(state2.is_solved)
def test_env_add_inspect(self):
server = Server()
server.env_add(
name="mystery",
t="forall (n: Nat), Nat",
v="fun (n: Nat) => n + 1",
is_theorem=False,
)
inspect_result = server.env_inspect(name="mystery")
self.assertEqual(inspect_result['type'], {'pp': 'Nat → Nat', 'dependentMVars': []})
if __name__ == '__main__':
unittest.main()