about summary refs log tree commit diff
path: root/pkgs/pkgs-lib/formats/java-properties/test/default.nix
blob: 4b3845c10296616a7ecc2c7055dc5e2735ee1d1d (plain) (blame)
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
{ fetchurl
, formats
, glibcLocales
, jdk
, lib
, stdenv
}:
let
  inherit (lib) concatStrings attrValues mapAttrs;

  javaProperties = formats.javaProperties { };

  input = {
    foo = "bar";
    "empty value" = "";
    "typical.dot.syntax" = "com.sun.awt";
    "" = "empty key's value";
    "1" = "2 3";
    "#" = "not a comment # still not";
    "!" = "not a comment!";
    "!a" = "still not! a comment";
    "!b" = "still not ! a comment";
    "dos paths" = "C:\\Program Files\\Nix For Windows\\nix.exe";
    "a \t\nb" = " c";
    "angry \t\nkey" = ''
      multi
      ${"\tline\r"}
       space-
        indented
      trailing-space${" "}
      trailing-space${"  "}
      value
    '';
    "this=not" = "bad";
    "nor = this" = "bad";
    "all stuff" = "foo = bar";
    "unicode big brain" = "e = mc□";
    "ütf-8" = "dûh";
    # NB: Some editors (vscode) show this _whole_ line in right-to-left order
    "الجبر" = "أكثر من مجرد أرقام";
  };

in
stdenv.mkDerivation {
  name = "pkgs.formats.javaProperties-test-${jdk.name}";
  nativeBuildInputs = [
    jdk
    glibcLocales
  ];

  # technically should go through the type.merge first, but that's tested
  # in tests/formats.nix.
  properties = javaProperties.generate "example.properties" input;

  # Expected output as printed by Main.java
  passAsFile = [ "expected" ];
  expected = concatStrings (attrValues (
    mapAttrs
      (key: value:
        ''
          KEY
          ${key}
          VALUE
          ${value}

        ''
      )
      input
  ));

  src = lib.sourceByRegex ./. [
    ".*\.java"
  ];
  LANG = "C.UTF-8";
  buildPhase = ''
    javac Main.java
  '';
  doCheck = true;
  checkPhase = ''
    cat -v $properties
    java Main $properties >actual
    diff -U3 $expectedPath actual
  '';
  installPhase = "touch $out";
}