Compare commits

...

2 Commits

Author SHA1 Message Date
518373c2bb test: dispatch contract 2026-03-09 22:04:30 +01:00
1d66f31e19 refactor: pub things for testing purposes 2026-03-09 22:04:15 +01:00
2 changed files with 25 additions and 3 deletions

View File

@@ -12,7 +12,7 @@ fn get_line(prompt: String) -> String
@external(erlang, "erlang", "halt")
fn halt(code: Int) -> Nil
type Command {
pub type Command {
Command(name: String, description: String, run: fn(List(Command)) -> Nil)
}
@@ -41,7 +41,7 @@ fn exit(_cmds: List(Command)) -> Nil {
halt(0)
}
fn build_commands() -> List(Command) {
pub fn build_commands() -> List(Command) {
[
Command("clean", "delete history", clean),
Command("help", "show this help", help),
@@ -50,7 +50,7 @@ fn build_commands() -> List(Command) {
]
}
fn commands_dict(
pub fn commands_dict(
cmds: List(Command),
) -> dict.Dict(String, fn(List(Command)) -> Nil) {
list.fold(cmds, dict.new(), fn(acc, cmd) {

View File

@@ -1,4 +1,26 @@
import gleam/dict
import gleeunit
import gleeunit/should
import simple_repl
pub fn command_lookup_test() {
let commands =
simple_repl.build_commands()
|> simple_repl.commands_dict
let has_help = case dict.get(commands, "help") {
Ok(_) -> True
Error(_) -> False
}
let has_unknown = case dict.get(commands, "foo") {
Ok(_) -> True
Error(_) -> False
}
has_help |> should.equal(True)
has_unknown |> should.equal(False)
}
pub fn main() -> Nil {
gleeunit.main()