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