AtlatestRepositorysigil-app

sigil-app / tree / testtest-keys.sgl

1;;; The key symbol table: every name a program can bind resolves to a GLFW
2;;; code without a window, and a name that is no key answers #f. The
3;;; codes are GLFW's (glfw3.h): F1 290, PAGE_UP 266, HOME 268, INSERT 260,
4;;; DELETE 261, RIGHT_SHIFT 344, COMMA 44, PERIOD 46, GRAVE_ACCENT 96,
5;;; KP_0 320, KP_ENTER 335.
6
7(import (sigil test)
8 (sigil desktop))
9
10(define (check group pairs)
11 (test-group group
12 (for-each (lambda (p)
13 (test (car p)
14 (assert-equal (cdr p) (key-code (string->symbol (car p))))))
15 pairs)))
17(check "key-code: the 0.10.0 names"
18 '(("a" . 65) ("0" . 48) ("space" . 32) ("return" . 257) ("escape" . 256)
19 ("left" . 263) ("shift" . 340) ("ctrl" . 341)))
21(check "key-code: the 0.10.1 names"
22 '(("f1" . 290) ("f7" . 296) ("f12" . 301)
23 ("page-up" . 266) ("page-down" . 267) ("home" . 268) ("end" . 269)
24 ("insert" . 260) ("delete" . 261)
25 ("right-shift" . 344) ("right-ctrl" . 345) ("right-alt" . 346)
26 ("comma" . 44) ("," . 44) ("period" . 46) ("." . 46) ("slash" . 47)
27 ("semicolon" . 59) ("apostrophe" . 39) ("minus" . 45) ("equal" . 61)
28 ("left-bracket" . 91) ("right-bracket" . 93) ("backslash" . 92)
29 ("grave" . 96) ("`" . 96)
30 ("kp-0" . 320) ("kp-9" . 329) ("kp-enter" . 335)))
32(check "key-code: no key"
33 '(("bogus" . #f) ("f0" . #f) ("f26" . #f) ("f1x" . #f) ("kp-x" . #f) ("page" . #f)))
35(test-group "key-code: not a symbol"
36 (test "a string is no key" (assert-equal #f (key-code "a"))))
38;; 0.10.2: the wheel. Without a window there is no wheel; the natives answer
39;; 0.0 (a float), so a program can read them every frame unconditionally.
40(test-group "mouse-wheel: readable without a window"
41 (test "vertical travel is 0.0 with no window" (assert-equal 0.0 (mouse-wheel)))
42 (test "horizontal travel is 0.0 with no window" (assert-equal 0.0 (mouse-wheel-x)))
43 (test "both answer numbers" (assert-true (and (number? (mouse-wheel)) (number? (mouse-wheel-x))))))