summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/keymap-drawer/tests/default.nix
blob: 7c94185c41f5a5a70a883bca7f22deadf3de42c3 (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
{
  lib,
  fetchFromGitHub,
  runCommand,
  stdenv,
  testers,

  keymap-drawer,
  yamllint,
}:
let
  runKeymapDrawer =
    name:
    runCommand "keymap-drawer-${name}" {
      nativeBuildInputs = [ keymap-drawer ];
    };

  MattSturgeon-example = fetchFromGitHub {
    owner = "MattSturgeon";
    repo = "glove80-config";
    rev = "d55267dd26593037256b35a5d6ebba0f75541da5";
    hash = "sha256-MV6cNpgHBuaGvpu2aR1aBNMpwPnDqOSbGf+2ykxocP4=";
    nonConeMode = true;
    sparseCheckout = [
      "config"
      "img"
    ];
  };

  # MattSturgeon's example requires MDI icons
  mdi = fetchFromGitHub {
    owner = "Templarian";
    repo = "MaterialDesign-SVG";
    tag = "v7.4.47";
    hash = "sha256-NoSSRT1ID38MT70IZ+7h/gMVCNsjNs3A2RX6ePGwuQ0=";
  };
in
{
  dump-config = runKeymapDrawer "dump-config" ''
    keymap dump-config --output "$out"

    if [ ! -s "$out" ]; then
      >&2 echo 'Expected `dump-config` to have content.'
      exit 1
    fi

    ${lib.getExe yamllint} --strict --config-data relaxed "$out"
  '';

  parse-zmk = testers.testEqualContents {
    assertion = "keymap parse --zmk-keymap produces expected YAML";
    expected = "${MattSturgeon-example}/img/glove80.yaml";
    actual = runKeymapDrawer "parse" ''
      keymap \
        --config ${MattSturgeon-example}/config/keymap_drawer.yaml \
        parse --zmk-keymap ${MattSturgeon-example}/config/glove80.keymap \
        --output "$out"
    '';
    checkMetadata = stdenv.buildPlatform.isLinux;
  };

  draw = testers.testEqualContents {
    assertion = "keymap draw produces expected SVG";
    expected = "${MattSturgeon-example}/img/glove80.svg";
    actual = runKeymapDrawer "draw" ''
      ${lib.optionalString stdenv.buildPlatform.isLinux ''
        export XDG_CACHE_HOME="$PWD/cache"
        glyphs="$XDG_CACHE_HOME/keymap-drawer/glyphs"
      ''}
      ${lib.optionalString stdenv.buildPlatform.isDarwin ''
        export HOME="$PWD/home"
        glyphs="$HOME/Library/Caches/keymap-drawer/glyphs"
      ''}
      mkdir -p "$glyphs"

      # Unpack MDI icons into the cache
      for file in ${mdi}/svg/*
      do
        ln -s "$file" "$glyphs/mdi:$(basename "$file")"
      done

      keymap \
        --config ${MattSturgeon-example}/config/keymap_drawer.yaml \
        draw ${MattSturgeon-example}/img/glove80.yaml \
        --output "$out"
    '';
    checkMetadata = stdenv.buildPlatform.isLinux;
  };
}