Compare commits
2 Commits
216c10273b
...
518373c2bb
| Author | SHA1 | Date | |
|---|---|---|---|
| 518373c2bb | |||
| 1d66f31e19 |
@@ -12,7 +12,7 @@ fn get_line(prompt: String) -> String
|
|||||||
@external(erlang, "erlang", "halt")
|
@external(erlang, "erlang", "halt")
|
||||||
fn halt(code: Int) -> Nil
|
fn halt(code: Int) -> Nil
|
||||||
|
|
||||||
type Command {
|
pub type Command {
|
||||||
Command(name: String, description: String, run: fn(List(Command)) -> Nil)
|
Command(name: String, description: String, run: fn(List(Command)) -> Nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ fn exit(_cmds: List(Command)) -> Nil {
|
|||||||
halt(0)
|
halt(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_commands() -> List(Command) {
|
pub fn build_commands() -> List(Command) {
|
||||||
[
|
[
|
||||||
Command("clean", "delete history", clean),
|
Command("clean", "delete history", clean),
|
||||||
Command("help", "show this help", help),
|
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),
|
cmds: List(Command),
|
||||||
) -> dict.Dict(String, fn(List(Command)) -> Nil) {
|
) -> dict.Dict(String, fn(List(Command)) -> Nil) {
|
||||||
list.fold(cmds, dict.new(), fn(acc, cmd) {
|
list.fold(cmds, dict.new(), fn(acc, cmd) {
|
||||||
|
|||||||
@@ -1,4 +1,26 @@
|
|||||||
|
import gleam/dict
|
||||||
import gleeunit
|
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 {
|
pub fn main() -> Nil {
|
||||||
gleeunit.main()
|
gleeunit.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user