forked from opencalc/opencalc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu_test.lua
More file actions
115 lines (82 loc) · 2.64 KB
/
Copy pathmenu_test.lua
File metadata and controls
115 lines (82 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
--[[
opencalc - an open source calcualtor
Copyright (C) 2011 Richard Titmuss <richard@opencalc.me>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program in the file COPYING; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--]]
require "lunit"
require "view/lunit"
module("menu_textcase", lunit.testcase, package.seeall)
local ui = require("ui")
local Menu = require "menu"
local Sheet = require "sheet"
function newMenu()
local sheet = Sheet:new()
local submenu = {
{ "Red" },
{ "Green" },
{ "Blue" },
}
local items = {
{ "Size", "font_size", { 8, 10, 12, 14 }, def = 10 },
{ "Submenu", submenu },
{ "One" },
{ "Two" },
{ "Three" },
{ "Four" },
{ "Five" },
{ "Six" },
{ "Seven" },
{ "Eight" },
{ "Nine" },
{ "Ten" },
}
return Menu:new(sheet, items)
end
function menu_test()
local menu = newMenu()
assert_view_image("menu-001.png", menu)
assert_false(menu:event({ type = "keypress", key = "<move_left>" }))
end
function selection_test()
local menu = newMenu()
menu:event({ type = "keypress", key = "<move_right>" })
menu:event({ type = "keypress", key = "<move_right>" })
assert_view_image("menu-002.png", menu)
end
function typeahead_test()
local menu = newMenu()
menu:event({ type = "keypress", key = "t" })
assert_view_image("menu-003.png", menu)
menu:event({ type = "keypress", key = "w" })
assert_view_image("menu-004.png", menu)
menu:event({ type = "keypress", key = "<delete>" })
assert_view_image("menu-003.png", menu)
end
function promote_test()
local menu = newMenu()
assert_not_equal("Four", menu.menu[1].items[1][1])
menu:event({ type = "keypress", key = "four" })
menu:event({ type = "keypress", key = "=" })
assert_equal("Four", menu.menu[1].items[1][1])
end
function scroll_test()
local menu = newMenu()
menu.menu[1].selected = 1
assert_view_image("menu-001.png", menu)
menu.menu[1].selected = 3
assert_view_image("menu-006.png", menu)
menu.menu[1].selected = #menu.menu[1].items - 3
assert_view_image("menu-007.png", menu)
menu.menu[1].selected = #menu.menu[1].items
assert_view_image("menu-008.png", menu)
end