summaryrefslogtreecommitdiff
path: root/tests/tap_dance/tap_dance_layers/test_tap_dance_layers.cpp
blob: 8b736b19c63aa46cb70b5e5b35bd2387883edfc4 (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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
// Copyright 2022 Sergey Vlasov (@sigprof)
// SPDX-License-Identifier: GPL-2.0-or-later

#include "keyboard_report_util.hpp"
#include "keycode.h"
#include "test_common.hpp"
#include "action_tapping.h"
#include "test_keymap_key.hpp"
#include "tap_dance_defs.h"

using testing::_;
using testing::InSequence;

struct TapDanceKeyParams {
    std::string name;                  // Tap dance name (part of test name)
    uint16_t    keycode;               // Tap dance keycode (TD(n))
    uint16_t    expect_on_tap;         // Keycode for single tap
    uint16_t    expect_on_hold;        // Keycode for single hold (may be MO(1))
    uint16_t    expect_on_double_tap;  // Keycode for double tap (may be MO(1))
    uint16_t    expect_on_double_hold; // Keycode for double hold (may be MO(1))
};

struct OtherKeyLayerParams {
    uint16_t keycode;           // Keycode in the keymap
    uint16_t expect_on_press;   // Keycode to expect on press
    uint16_t expect_on_release; // Keycode to expect on release (may be KC_NO if none)
};

struct OtherKeyParams {
    std::string         name; // Other key name (part of test name)
    OtherKeyLayerParams l0;   // Keycodes for layer 0
    OtherKeyLayerParams l1;   // Keycodes for layer 1
};

typedef std::tuple<TapDanceKeyParams, OtherKeyParams> TapDanceLayersParams;

class TapDanceLayers : public ::testing::WithParamInterface<TapDanceLayersParams>, public TestFixture {
   protected:
    TapDanceKeyParams tap_dance;
    OtherKeyParams    other_key;

    std::unique_ptr<KeymapKey> key_td, key_td_l1, key_other, key_other_l1;

    void SetUp() override {
        std::tie(tap_dance, other_key) = GetParam();

        key_td       = std::make_unique<KeymapKey>(0, 1, 0, tap_dance.keycode);
        key_td_l1    = std::make_unique<KeymapKey>(1, 1, 0, KC_TRNS);
        key_other    = std::make_unique<KeymapKey>(0, 2, 0, other_key.l0.keycode);
        key_other_l1 = std::make_unique<KeymapKey>(1, 2, 0, other_key.l1.keycode);

        set_keymap({*key_td, *key_td_l1, *key_other, *key_other_l1});
    }
};

static const TapDanceKeyParams tap_dance_keys[] = {
    TapDanceKeyParams{
        "LayerMove",
        TD(TD_L_MOVE),
        KC_APP,
        KC_APP,
        MO(1),
        MO(1),
    },
    TapDanceKeyParams{
        "LayerToggle",
        TD(TD_L_TOGG),
        KC_APP,
        KC_APP,
        MO(1),
        MO(1),
    },
    TapDanceKeyParams{
        "CustomLT",
        TD(TD_LT_APP),
        KC_APP,
        MO(1),
        KC_RCTL,
        KC_RCTL,
    },
};

static const OtherKeyParams other_keys[] = {
    OtherKeyParams{
        "Builtin",
        OtherKeyLayerParams{KC_A, KC_A, KC_NO},
        OtherKeyLayerParams{KC_B, KC_B, KC_NO},
    },
    OtherKeyParams{
        "CustomFast",
        OtherKeyLayerParams{FAST_AB, KC_A, KC_B},
        OtherKeyLayerParams{FAST_CD, KC_C, KC_D},
    },
    OtherKeyParams{
        "CustomSlow",
        OtherKeyLayerParams{SLOW_AB, KC_A, KC_B},
        OtherKeyLayerParams{SLOW_CD, KC_C, KC_D},
    },
};

// clang-format off
INSTANTIATE_TEST_CASE_P(
    Layers,
    TapDanceLayers,
    ::testing::Combine(
        ::testing::ValuesIn(tap_dance_keys),
        ::testing::ValuesIn(other_keys)
    ),
    [](const ::testing::TestParamInfo<TapDanceLayersParams>& info) {
        return std::get<0>(info.param).name + std::get<1>(info.param).name;
    }
);
// clang-format on

// Test single tap of the tap dance key with tapping term delay after the tap.
TEST_P(TapDanceLayers, SingleTap) {
    TestDriver driver;
    InSequence s;

    // The tap of the tap dance key does not result in sending a report
    // immediately.
    EXPECT_NO_REPORT(driver);
    tap_key(*key_td);

    // After the tapping term expires, a tap event for the single tap keycode
    // is generated.
    idle_for(TAPPING_TERM - 1);
    EXPECT_REPORT(driver, (tap_dance.expect_on_tap));
    EXPECT_EMPTY_REPORT(driver);
    run_one_scan_loop();

    // Pressing the other key produces the reports for the layer 0 mapping of
    // that key.
    EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the other key produces the reports for the layer 0 mapping of
    // that key.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test single tap of the tap dance key without a delay between the tap dance
// key and the other key.
TEST_P(TapDanceLayers, SingleTapFast) {
    TestDriver driver;
    InSequence s;

    // The tap of the tap dance key does not result in sending a report
    // immediately.
    EXPECT_NO_REPORT(driver);
    tap_key(*key_td);

    // A quick press of the other key causes the tap event for the tap dance to
    // be sent before the press event for the other key, and the layer 0
    // mapping is used for the other key.
    EXPECT_REPORT(driver, (tap_dance.expect_on_tap));
    EXPECT_EMPTY_REPORT(driver);
    EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the other key produces the reports for the layer 0 mapping of
    // that key.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test single hold of the tap dance key with tapping term delay after the hold
// (test variant for tap dances which switch the layer on hold).
TEST_P(TapDanceLayers, SingleHoldLayer) {
    if (tap_dance.expect_on_hold != MO(1)) {
        // Do nothing - the SingleHoldKeycode test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the hold of the tap dance key.
    EXPECT_NO_REPORT(driver);
    key_td->press();
    run_one_scan_loop();

    // After the tapping term expires, the tap dance finishes and switches the
    // layer, but does not send a report.
    EXPECT_NO_REPORT(driver);
    idle_for(TAPPING_TERM);
    run_one_scan_loop();

    // Pressing the other key produces the reports for the layer 1 mapping of
    // that key.
    EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the tap dance key does not produce a report.
    EXPECT_NO_REPORT(driver);
    key_td->release();
    run_one_scan_loop();

    // Releasing the other key produces the report for the layer 1 mapping of
    // that key.
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test single hold of the tap dance key with tapping term delay after the hold
// (test variant for tap dances which send a keycode on single hold).
TEST_P(TapDanceLayers, SingleHoldKeycode) {
    if (tap_dance.expect_on_hold == MO(1)) {
        // Do nothing - the SingleHoldLayer test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the hold of the tap dance key.
    EXPECT_NO_REPORT(driver);
    key_td->press();
    run_one_scan_loop();

    // After the tapping term expires, the tap dance sends the report with the
    // hold keycode.
    EXPECT_NO_REPORT(driver);
    idle_for(TAPPING_TERM);
    EXPECT_REPORT(driver, (tap_dance.expect_on_hold));
    run_one_scan_loop();

    // Pressing the other key produces the reports for the layer 0 mapping of
    // that key.
    EXPECT_REPORT(driver, (tap_dance.expect_on_hold, other_key.l0.expect_on_press));
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (tap_dance.expect_on_hold));
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the tap dance key sends the release report for the
    // corresponding hold keycode.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    } else {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
    }
    key_td->release();
    run_one_scan_loop();

    // Releasing the other key produces the reports for the layer 0 mapping of
    // that key.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test single hold of the tap dance key without tapping term delay after the
// hold (test variant for tap dances which switch the layer on hold).
TEST_P(TapDanceLayers, SingleHoldFastLayer) {
    if (tap_dance.expect_on_hold != MO(1)) {
        // Do nothing - the SingleHoldFastKeycode test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the hold of the tap dance key.
    EXPECT_NO_REPORT(driver);
    key_td->press();
    run_one_scan_loop();

    // Pressing the other key produces the reports for the layer 1 mapping of
    // that key.
    EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the tap dance key does not produce a report.
    EXPECT_NO_REPORT(driver);
    key_td->release();
    run_one_scan_loop();

    // Releasing the other key produces the reports for the layer 1 mapping of
    // that key.
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test single hold of the tap dance key without tapping term delay after the hold
// (test variant for tap dances which send a keycode on single hold).
TEST_P(TapDanceLayers, SingleHoldFastKeycode) {
    if (tap_dance.expect_on_hold == MO(1)) {
        // Do nothing - the SingleHoldFastLayer test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the hold of the tap dance key.
    EXPECT_NO_REPORT(driver);
    key_td->press();
    run_one_scan_loop();

    // Pressing the other key produces first the report for the tap dance hold
    // keycode, and then the reports for the layer 0 mapping of the other key.
    EXPECT_REPORT(driver, (tap_dance.expect_on_hold));
    EXPECT_REPORT(driver, (tap_dance.expect_on_hold, other_key.l0.expect_on_press));
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (tap_dance.expect_on_hold));
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the tap dance key sends a release report for the corresponding
    // hold keycode.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    } else {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
    }
    key_td->release();
    run_one_scan_loop();

    // Releasing the other key produces the report for the layer 0 mapping of
    // that key.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test double tap of the tap dance key with tapping term delay after the hold
// (test variant for tap dances which switch the layer on double tap).
TEST_P(TapDanceLayers, DoubleTapLayer) {
    if (tap_dance.expect_on_double_tap != MO(1)) {
        // Do nothing - the DoubleTapKeycode test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the double tap of the tap dance
    // key.
    EXPECT_NO_REPORT(driver);
    tap_key(*key_td);
    tap_key(*key_td);

    // After the tapping term this tap dance does not send a report too.
    EXPECT_NO_REPORT(driver);
    idle_for(TAPPING_TERM);
    run_one_scan_loop();

    // Pressing the other key produces the reports for the layer 1 mapping of
    // that key.
    EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the other key produces the report for the layer 1 mapping of
    // that key.
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test double tap of the tap dance key with tapping term delay after the hold
// (test variant for tap dances which send a keycode on double tap).
TEST_P(TapDanceLayers, DoubleTapKeycode) {
    if (tap_dance.expect_on_double_tap == MO(1)) {
        // Do nothing - the DoubleTapLayer test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the double tap of the tap dance
    // key.
    EXPECT_NO_REPORT(driver);
    tap_key(*key_td);
    tap_key(*key_td);

    // After the tapping term this tap dance sends the double tap keycode.
    idle_for(TAPPING_TERM - 1);
    EXPECT_REPORT(driver, (tap_dance.expect_on_double_tap));
    EXPECT_EMPTY_REPORT(driver);
    run_one_scan_loop();

    // Pressing the other key produces the reports for the layer 0 mapping of
    // that key.
    EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the other key produces the report for the layer 0 mapping of
    // that key.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test double tap of the tap dance key without tapping term delay after the
// hold (test variant for tap dances which switch the layer on double tap).
TEST_P(TapDanceLayers, DoubleTapFastLayer) {
    if (tap_dance.expect_on_double_tap != MO(1)) {
        // Do nothing - the DoubleTapFastKeycode test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the double tap of the tap dance
    // key.
    EXPECT_NO_REPORT(driver);
    tap_key(*key_td);
    tap_key(*key_td);

    // Pressing the other key produces the reports for the layer 1 mapping of
    // that key.
    EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the other key produces the report for the layer 1 mapping of
    // that key.
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test double tap of the tap dance key without tapping term delay after the
// hold (test variant for tap dances which send a keycode on double tap).
TEST_P(TapDanceLayers, DoubleTapFastKeycode) {
    if (tap_dance.expect_on_double_tap == MO(1)) {
        // Do nothing - the DoubleTapFastLayer test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the double tap of the tap dance
    // key.
    EXPECT_NO_REPORT(driver);
    tap_key(*key_td);
    tap_key(*key_td);

    // Pressing the other key produces first the report for the tap dance
    // double tap keycode, and then the reports for the layer 0 mapping of the
    // other key.
    EXPECT_REPORT(driver, (tap_dance.expect_on_double_tap));
    EXPECT_EMPTY_REPORT(driver);
    EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the other key produces the report for the layer 0 mapping of
    // that key.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test double hold of the tap dance key with tapping term delay after the hold
// (test variant for tap dances which switch the layer on double hold).
TEST_P(TapDanceLayers, DoubleHoldLayer) {
    if (tap_dance.expect_on_double_hold != MO(1)) {
        // Do nothing - the DoubleHoldKeycode test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the double hold of the tap dance
    // key.
    EXPECT_NO_REPORT(driver);
    tap_key(*key_td);
    key_td->press();
    run_one_scan_loop();

    // After the tapping term expires, the tap dance finishes and switches the
    // layer, but does not send a report.
    EXPECT_NO_REPORT(driver);
    idle_for(TAPPING_TERM);
    run_one_scan_loop();

    // Pressing the other key produces the reports for the layer 1 mapping of
    // that key.
    EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the tap dance key does not produce a report.
    EXPECT_NO_REPORT(driver);
    key_td->release();
    run_one_scan_loop();

    // Releasing the other key produces the report for the layer 1 mapping of
    // that key.
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test double hold of the tap dance key with tapping term delay after the hold
// (test variant for tap dances which send a keycode on double hold).
TEST_P(TapDanceLayers, DoubleHoldKeycode) {
    if (tap_dance.expect_on_double_hold == MO(1)) {
        // Do nothing - the DoubleHoldLayer test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the double hold of the tap dance
    // key.
    EXPECT_NO_REPORT(driver);
    tap_key(*key_td);
    key_td->press();
    run_one_scan_loop();

    // After the tapping term expires, the tap dance sends the report with the
    // double hold keycode.
    EXPECT_NO_REPORT(driver);
    idle_for(TAPPING_TERM);
    EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold));
    run_one_scan_loop();

    // Pressing the other key produces the reports for the layer 0 mapping of
    // that key.
    EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold, other_key.l0.expect_on_press));
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold));
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the tap dance key sends the release report for the
    // corresponding double hold keycode.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    } else {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
    }
    key_td->release();
    run_one_scan_loop();

    // Releasing the other key produces the reports for the layer 0 mapping of
    // that key.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test double hold of the tap dance key without tapping term delay after the
// hold (test variant for tap dances which switch the layer on double hold).
TEST_P(TapDanceLayers, DoubleHoldFastLayer) {
    if (tap_dance.expect_on_double_hold != MO(1)) {
        // Do nothing - the DoubleHoldFastKeycode test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the double hold of the tap dance
    // key.
    EXPECT_NO_REPORT(driver);
    tap_key(*key_td);
    key_td->press();
    run_one_scan_loop();

    // Pressing the other key produces the reports for the layer 1 mapping of
    // that key.
    EXPECT_REPORT(driver, (other_key.l1.expect_on_press));
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the tap dance key does not produce a report.
    EXPECT_NO_REPORT(driver);
    key_td->release();
    run_one_scan_loop();

    // Releasing the other key produces the reports for the layer 1 mapping of
    // that key.
    if (other_key.l1.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l1.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}

// Test double hold of the tap dance key without tapping term delay after the hold
// (test variant for tap dances which send a keycode on double hold).
TEST_P(TapDanceLayers, DoubleHoldFastKeycode) {
    if (tap_dance.expect_on_double_hold == MO(1)) {
        // Do nothing - the DoubleHoldFastLayer test would run instead.
        return;
    }

    TestDriver driver;
    InSequence s;

    // No report gets sent immediately after the double hold of the tap dance
    // key.
    EXPECT_NO_REPORT(driver);
    tap_key(*key_td);
    key_td->press();
    run_one_scan_loop();

    // Pressing the other key produces first the report for the tap dance
    // double hold keycode, and then the reports for the layer 0 mapping of the
    // other key.
    EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold));
    EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold, other_key.l0.expect_on_press));
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (tap_dance.expect_on_double_hold));
    }
    key_other->press();
    run_one_scan_loop();

    // Releasing the tap dance key sends a release report for the corresponding
    // double hold keycode.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_EMPTY_REPORT(driver);
    } else {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_press));
    }
    key_td->release();
    run_one_scan_loop();

    // Releasing the other key produces the report for the layer 0 mapping of
    // that key.
    if (other_key.l0.expect_on_release != KC_NO) {
        EXPECT_REPORT(driver, (other_key.l0.expect_on_release));
    }
    EXPECT_EMPTY_REPORT(driver);
    key_other->release();
    run_one_scan_loop();
}