1{
2 formats,
3 glibcLocales,
4 jdk,
5 lib,
6 stdenv,
7}:
8
9# This test primarily tests correct escaping.
10# See also testJavaProperties in
11# pkgs/pkgs-lib/tests/formats.nix, which tests
12# type coercions and is a bit easier to read.
13
14let
15 inherit (lib) concatStrings attrValues mapAttrs;
16
17 javaProperties = formats.javaProperties { };
18
19 input = {
20 foo = "bar";
21 "empty value" = "";
22 "typical.dot.syntax" = "com.sun.awt";
23 "" = "empty key's value";
24 "1" = "2 3";
25 "#" = "not a comment # still not";
26 "!" = "not a comment!";
27 "!a" = "still not! a comment";
28 "!b" = "still not ! a comment";
29 "dos paths" = "C:\\Program Files\\Nix For Windows\\nix.exe";
30 "a \t\nb" = " c";
31 "angry \t\nkey" = ''
32 multi
33 ${"\tline\r"}
34 space-
35 indented
36 trailing-space${" "}
37 trailing-space${" "}
38 value
39 '';
40 "this=not" = "bad";
41 "nor = this" = "bad";
42 "all stuff" = "foo = bar";
43 "unicode big brain" = "e = mc□";
44 "ütf-8" = "dûh";
45 # NB: Some editors (vscode) show this _whole_ line in right-to-left order
46 "الجبر" = "أكثر من مجرد أرقام";
47 };
48
49in
50stdenv.mkDerivation {
51 name = "pkgs.formats.javaProperties-test-${jdk.name}";
52 nativeBuildInputs = [
53 jdk
54 glibcLocales
55 ];
56
57 # technically should go through the type.merge first, but that's tested
58 # in tests/formats.nix.
59 properties = javaProperties.generate "example.properties" input;
60
61 # Expected output as printed by Main.java
62 passAsFile = [ "expected" ];
63 expected = concatStrings (
64 attrValues (
65 mapAttrs (key: value: ''
66 KEY
67 ${key}
68 VALUE
69 ${value}
70
71 '') input
72 )
73 );
74
75 src = lib.sourceByRegex ./. [
76 ".*\\.java"
77 ];
78 # On Linux, this can be C.UTF-8, but darwin + zulu requires en_US.UTF-8
79 LANG = "en_US.UTF-8";
80 buildPhase = ''
81 javac Main.java
82 '';
83 doCheck = true;
84 checkPhase = ''
85 cat -v $properties
86 java Main $properties >actual
87 diff -U3 $expectedPath actual
88 '';
89 installPhase = "touch $out";
90}