Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
I'm thinking one more block to test menus with '\0', and a test
for custom keypress and header functions, then we take a look at
the code coverage.
  • Loading branch information
mnemnion committed Mar 16, 2024
1 parent e09a0f6 commit 62f11fc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using ToggleMenus
using REPL
using Test
using Aqua
import ToggleMenus: cancel, header, keypress, move_down!, move_up!, numoptions, page_down!,
page_up!, pick, printmenu, scroll_wrap, selected, writeline, didcancelmenu

@testset "ToggleMenus.jl" begin
@testset "Code quality (Aqua.jl)" begin
Expand All @@ -28,5 +30,38 @@ using Aqua
@test menu1.selections == ['a', 'a', 'a']
@test menu1.cursor[] == 1
@test simpletemplate.header == "test menu 1"
template = ToggleMenuMaker("header", ['a', 'b', 'c'], ['🔴', '🔵', '🟢'], charset=:unicode)
menu = template("different header", [string(c) for c in 'a':'g'])
@test template.header == "header"
@test menu.header == "different header"
@test menu.cursor[] == 1
@test menu.cursor isa Base.RefValue{Int64}
@test (menu.cursor[] = move_down!(menu, menu.cursor[])) == 2
@test (menu.cursor[] = move_up!(menu, menu.cursor[])) == 1
@test (menu.cursor[] = page_down!(menu, menu.cursor[])) == 7
@test (menu.cursor[] = page_up!(menu, menu.cursor[])) == 1
keypress(menu, UInt32('\t'))
@test menu.selections[1] == 'b'
keypress(menu, UInt32('\t'))
@test menu.selections[1] == 'c'
keypress(menu, UInt32('\t'))
@test menu.selections[1] == 'a'
keypress(menu, UInt32('c'))
@test menu.selections[1] == 'c'
@test scroll_wrap(menu) == false
@test header(menu) == "different header"
@test numoptions(menu) == length(menu.options) == length(menu.selections)
normal_return = selected(menu)
for (idx, (selected, option)) in normal_return |> enumerate
@test selected == menu.selections[idx]
@test option == menu.options[idx]
end
@test didcancelmenu(normal_return) == false
cancel(menu)
cancel_return = selected(menu)
@test length(cancel_return) == 1
@test cancel_return[1][1] == '\0'
@test cancel_return[1][2] == ""
@test didcancelmenu(cancel_return) == true
end
end

0 comments on commit 62f11fc

Please sign in to comment.