aboutsummaryrefslogtreecommitdiffstats
path: root/quantum/keymap_extras/sendstring_norman.h
blob: 4146e6ca7beb6ad8d01a551fef23058f3e0d7878 (plain)
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
/* Copyright 2019 Torben Hoffmann
 *
 * 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.  If not, see <http://www.gnu.org/licenses/>.
 */

// Sendstring lookup tables for Norman layouts

#pragma once

#include "keymap_norman.h"

// clang-format off

const uint8_t ascii_to_keycode_lut[128] PROGMEM = {
    // NUL   SOH      STX      ETX      EOT      ENQ      ACK      BEL
    XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
    // BS    TAB      LF       VT       FF       CR       SO       SI
    KC_BSPC, KC_TAB,  KC_ENT,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
    // DLE   DC1      DC2      DC3      DC4      NAK      SYN      ETB
    XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
    // CAN   EM       SUB      ESC      FS       GS       RS       US
    XXXXXXX, XXXXXXX, XXXXXXX, KC_ESC,  XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,

    //       !        "        #        $        %        &        '
    KC_SPC,  KC_1,    KC_QUOT, KC_3,    KC_4,    KC_5,    KC_7,    KC_QUOT,
    // (     )        *        +        ,        -        .        /
    KC_9,    KC_0,    KC_8,    KC_EQL,  KC_COMM, KC_MINS, KC_DOT,  KC_SLSH,
    // 0     1        2        3        4        5        6        7
    KC_0,    KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,
    // 8     9        :        ;        <        =        >        ?
    KC_8,    KC_9,    NM_SCLN, NM_SCLN, KC_COMM, KC_EQL,  KC_DOT,  KC_SLSH,
    // @     A        B        C        D        E        F        G
    KC_2,    NM_A,    NM_B,    NM_C,    NM_D,    NM_E,    NM_F,    NM_G,
    // H     I        J        K        L        M        N        O
    NM_H,    NM_I,    NM_J,    NM_K,    NM_L,    NM_M,    NM_N,    NM_O,
    // P     Q        R        S        T        U        V        W
    NM_P,    NM_Q,    NM_R,    NM_S,    NM_T,    NM_U,    NM_V,    NM_W,
    // X     Y        Z        [        \        ]        ^        _
    NM_X,    NM_Y,    NM_Z,    KC_LBRC, KC_BSLS, KC_RBRC, KC_6,    KC_MINS,
    // `     a        b        c        d        e        f        g
    KC_GRV,  NM_A,    NM_B,    NM_C,    NM_D,    NM_E,    NM_F,    NM_G,
    // h     i        j        k        l        m        n        o
    NM_H,    NM_I,    NM_J,    NM_K,    NM_L,    NM_M,    NM_N,    NM_O,
    // p     q        r        s        t        u        v        w
    NM_P,    NM_Q,    NM_R,    NM_S,    NM_T,    NM_U,    NM_V,    NM_W,
    // x     y        z        {        |        }        ~        DEL
    NM_X,    NM_Y,    NM_Z,    KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV,  KC_DEL
};
an>_dump(a) def test_quoting(self): a = filt.parse("~u 'foo ~u bar' ~u voing") assert a.lst[0].expr == "foo ~u bar" assert a.lst[1].expr == "voing" self._dump(a) a = filt.parse("~u foobar") assert a.expr == "foobar" a = filt.parse(r"~u 'foobar\"\''") assert a.expr == "foobar\"'" a = filt.parse(r'~u "foo \'bar"') assert a.expr == "foo 'bar" def test_nesting(self): a = filt.parse("(~u foobar & ~h voing)") assert a.lst[0].expr == "foobar" self._dump(a) def test_not(self): a = filt.parse("!~h test") assert a.itm.expr == "test" a = filt.parse("!(~u test & ~h bar)") assert a.itm.lst[0].expr == "test" self._dump(a) def test_binaryops(self): a = filt.parse("~u foobar | ~h voing") isinstance(a, filt.FOr) self._dump(a) a = filt.parse("~u foobar & ~h voing") isinstance(a, filt.FAnd) self._dump(a) def test_wideops(self): a = filt.parse("~hq 'header: qvalue'") assert isinstance(a, filt.FHeadRequest) self._dump(a) class uMatching(libpry.AutoTree): def req(self): conn = flow.ClientConnect(("one", 2222)) headers = flow.Headers() headers["header"] = ["qvalue"] return flow.Request( conn, "host", 80, "http", "GET", "/path", headers, "content_request" ) def resp(self): q = self.req() headers = flow.Headers() headers["header_response"] = ["svalue"] return flow.Response( q, 200, "message", headers, "content_response" ) def err(self): q = self.req() return flow.Error(q, "msg") def q(self, q, o): return filt.parse(q)(o) def test_fcontenttype(self): q = self.req() s = self.resp() assert not self.q("~t content", q) assert not self.q("~t content", s) q.headers["content-type"] = ["text/json"] assert self.q("~t json", q) assert self.q("~tq json", q) assert not self.q("~ts json", q) s.headers["content-type"] = ["text/json"] assert self.q("~t json", s) del s.headers["content-type"] s.request.headers["content-type"] = ["text/json"] assert self.q("~t json", s) assert self.q("~tq json", s) assert not self.q("~ts json", s) def test_freq_fresp(self): q = self.req() s = self.resp() assert self.q("~q", q) assert not self.q("~q", s) assert not self.q("~s", q) assert self.q("~s", s) def test_ferr(self): e = self.err() assert self.q("~e", e) def test_head(self): q = self.req() s = self.resp() assert not self.q("~h nonexistent", q) assert self.q("~h qvalue", q) assert self.q("~h header", q) assert self.q("~h 'header: qvalue'", q) assert self.q("~h 'header: qvalue'", s) assert self.q("~h 'header_response: svalue'", s) assert self.q("~hq 'header: qvalue'", s) assert not self.q("~hq 'header_response: svalue'", s) assert self.q("~hq 'header: qvalue'", q) assert not self.q("~hq 'header_request: svalue'", q) assert not self.q("~hs 'header: qvalue'", s) assert self.q("~hs 'header_response: svalue'", s) assert not self.q("~hs 'header: qvalue'", q) def test_body(self): q = self.req() s = self.resp() assert not self.q("~b nonexistent", q) assert self.q("~b content", q) assert self.q("~b response", s) assert self.q("~b content_request", s) assert self.q("~bq content", q) assert self.q("~bq content", s) assert not self.q("~bq response", q) assert not self.q("~bq response", s) assert not self.q("~bs content", q) assert self.q("~bs content", s) assert not self.q("~bs nomatch", s) assert not self.q("~bs response", q) assert self.q("~bs response", s) def test_method(self): q = self.req() s = self.resp() assert self.q("~m get", q) assert not self.q("~m post", q) assert not self.q("~m get", s) q.method = "" assert not self.q("~m get", q) def test_url(self): q = self.req() s = self.resp() assert self.q("~u host", q) assert self.q("~u host/path", q) assert not self.q("~u moo/path", q) assert self.q("~u host", s) assert self.q("~u host/path", s) assert not self.q("~u moo/path", s) def test_code(self): q = self.req() s = self.resp() assert not self.q("~c 200", q) assert self.q("~c 200", s) assert not self.q("~c 201", s) def test_and(self): s = self.resp() assert self.q("~c 200 & ~h head", s) assert not self.q("~c 200 & ~h nohead", s) assert self.q("(~c 200 & ~h head) & ~b content", s) assert not self.q("(~c 200 & ~h head) & ~b nonexistent", s) assert not self.q("(~c 200 & ~h nohead) & ~b content", s) def test_or(self): s = self.resp() assert self.q("~c 200 | ~h nohead", s) assert self.q("~c 201 | ~h head", s) assert not self.q("~c 201 | ~h nohead", s) assert self.q("(~c 201 | ~h nohead) | ~s", s) assert not self.q("(~c 201 | ~h nohead) | ~q", s) def test_not(self): s = self.resp() assert not self.q("! ~c 200", s) assert self.q("! ~c 201", s) assert self.q("!~c 201 !~c 202", s) assert not self.q("!~c 201 !~c 200", s) tests = [ uMatching(), uParsing() ]