aboutsummaryrefslogtreecommitdiff
path: root/home-manager/tests/modules/programs/ne/passthroughs.nix
blob: 4c129e94489f82b89dd67c332989d8f0baa72c54 (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
{ config, lib, pkgs, ... }:

with lib;

let

  # Samples taken from the ne manual.
  keybindings = ''
    SEQ  "\x1b[1;5D"  14A
    KEY  14A          HELP
  '';

  menus = ''
    MENU "File"
    ITEM "Open...     ^O" Open
    ITEM "Close         " Close
    ITEM "DoIt          " Macro DoIt
  '';

  virtualExtensions = ''
    sh   1  ^#!\s*/.*\b(bash|sh|ksh|zsh)\s*
    csh  1  ^#!\s*/.*\b(csh|tcsh)\s*
    pl   1  ^#!\s*/.*\bperl\b
    py   1  ^#!\s*/.*\bpython[0-9]*\s*
    rb   1  ^#!\s*/.*\bruby\s*
    xml  1  ^<\?xml
  '';

  automaticPreferences = {
    nix = ''
      TAB 0
      TS 2
    '';
    js = ''
      TS 4
    '';
  };

  checkFile = filename: contents: ''
    assertFileExists home-files/.ne/${filename}
    assertFileContent home-files/.ne/${filename} ${
      builtins.toFile "checkFile" contents
    }
  '';

in {
  config = {
    programs.ne = {
      enable = true;
      inherit keybindings;
      inherit menus;
      inherit virtualExtensions;
      inherit automaticPreferences;
    };

    nixpkgs.overlays =
      [ (self: super: { ne = pkgs.writeScriptBin "dummy-ne" ""; }) ];

    nmt = {
      description = "Check that configuration files are correctly written";
      script = concatStringsSep "\n" [
        (checkFile ".keys" keybindings)
        (checkFile ".extensions" virtualExtensions)
        (checkFile ".menus" menus)

        # Generates a check command for each entry in automaticPreferences.
        (concatStringsSep "\n" (mapAttrsToList
          (extension: contents: checkFile "${extension}#ap" contents)
          automaticPreferences))
      ];
    };
  };
}