-- @neyuki/hid sends real input, so these only cover what is checked before
-- the device is touched.
local hid = require("@neyuki/hid")
assert(hid.keyboard.isKey("a") and hid.keyboard.isKey("Enter"), "characters and names are keys")
assert(hid.keyboard.isKey("F12") and hid.keyboard.isKey("ctrl"), "function and modifier keys")
assert(not hid.keyboard.isKey("hyper"), "unknown names are rejected")
local function fails(f, ...)
local ok, err = try(f, ...)
assert(not ok, "expected an error")
return err
end
assert(fails(hid.keyboard.tap, "hyper") == "unknown key `hyper`", "tap checks the key")
assert(fails(hid.keyboard.tap, "a", -1) == "times must be a non-negative integer", "tap checks times")
assert(fails(hid.keyboard.combo) == "at least one key must be given", "combo needs keys")
assert(fails(hid.keyboard.combo, "ctrl+hyper") == "unknown key `hyper`", "combo strings are checked")
assert(fails(hid.keyboard.hold, "shift", 5) == "action must be a function", "hold needs a function")
assert(fails(hid.keyboard.write, 5) == "text must be a string", "write needs text")
assert(fails(hid.mouse.click, "fourth") == "unknown mouse button `fourth`", "click checks the button")
assert(fails(hid.mouse.move, 1) == "y must be provided", "move needs both coordinates")
assert(fails(hid.mouse.scroll, "down") == "amount must be a number", "scroll needs an amount")
assert(fails(hid.clipboard.set, nil) == "text must be provided", "clipboard needs text")
assert(table.isfrozen(hid) and table.isfrozen(hid.mouse), "the library is frozen")
print("[pass] hid")