Skip to content

Commit

Permalink
why doesn't this work?
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Dargel committed May 24, 2021
1 parent 78f23c5 commit b22c736
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
5 changes: 2 additions & 3 deletions modules/lib/mozilla.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ with builtins;
else [{ name = path; value = val; }];
unPath = { name, value }: { inherit value; name = concatStringsSep "." name; };
normalize = ps: listToAttrs (map unPath (normalize' [] ps));
mkEntry = f: k: v: "${f}('${k}', ${toJSON v});";
unlines = concatStringsSep "\n";
mkEntry = f: k: v: "${f}('${k}', ${toJSON v});\n";
in {
inherit normalize mkEntry;
user-js = rec {

fromNormalized = ps: unlines (mapAttrsToList (mkEntry "user_pref") ps);
fromNormalized = ps: concatStrings (mapAttrsToList (mkEntry "user_pref") ps);

fromAttrs = ps: fromNormalized (normalize ps);

Expand Down
23 changes: 13 additions & 10 deletions tests/lib/types/mozilla-user-js.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,34 @@ with config.lib.mozilla.prefs;
config = {
tested.moz = {
"fromNormalized".text = user-js.fromNormalized {
"b.bool" = true;
"a.num" = 1;
"a.text" = "asdf";
"b.bool" = true;
};
"fromAttrs".text = user-js.fromAttrs {
b.bool = true;
a = {
num = 1;
text = "asdf";
bool = true;
};
};
};

home.file = config.tested.moz;
nmt.script = ''
nmt.script = let
expectedFile = pkgs.writeText "user.js" ''
user_pref('a.num', 1);
user_pref('a.text', "asdf");
user_pref('b.bool', true);
'';
in ''
${pkgs.hexdump}/bin/hexdump ${expectedFile} > expected.hex
for f in ${concatStringsSep " " (attrNames config.tested.moz)}
do
sort -d -o $f $out/tested/home-files/$f
assertFileContent $f ${
pkgs.writeText "user.js" ''
user_pref('b.bool', true);
user_pref('a.num', 1);
user_pref('a.text', "asdf");
''
}
${pkgs.hexdump}/bin/hexdump $f > $f.hex
diff -y $f.hex expected.hex
assertFileContent $f.hex expected.hex
done
'';
};
Expand Down

0 comments on commit b22c736

Please sign in to comment.