mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-31 04:58:01 +00:00
bahaghari: update library arguments
It makes it confusing sometimes. Not worth keeping the design.
This commit is contained in:
parent
b25ed0989d
commit
66b35ea2c6
@ -10,7 +10,7 @@
|
|||||||
pkgs.lib.makeExtensible
|
pkgs.lib.makeExtensible
|
||||||
(self:
|
(self:
|
||||||
let
|
let
|
||||||
callLibs = file: import file { lib = self; inherit pkgs; };
|
callLibs = file: import file { inherit (pkgs) lib; inherit pkgs self; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
trivial = callLibs ./trivial.nix;
|
trivial = callLibs ./trivial.nix;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# A small utility library for manipulating hexadecimal numbers. It's made in 15
|
# A small utility library for manipulating hexadecimal numbers. It's made in 15
|
||||||
# minutes with a bunch of duct tape on it but it's working for its intended
|
# minutes with a bunch of duct tape on it but it's working for its intended
|
||||||
# purpose.
|
# purpose.
|
||||||
{ pkgs, lib }:
|
{ pkgs, lib, self }:
|
||||||
|
|
||||||
let
|
let
|
||||||
glyphList =
|
glyphList =
|
||||||
@ -24,7 +24,7 @@ let
|
|||||||
"F"
|
"F"
|
||||||
];
|
];
|
||||||
|
|
||||||
baseSet = lib.generateBaseDigitType glyphList;
|
baseSet = self.generateBaseDigitType glyphList;
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
/* Returns a convenient glyph set for creating your own conversion or
|
/* Returns a convenient glyph set for creating your own conversion or
|
||||||
@ -41,7 +41,7 @@ rec {
|
|||||||
=> [ "F" "10" "11" ]
|
=> [ "F" "10" "11" ]
|
||||||
*/
|
*/
|
||||||
range = first: last:
|
range = first: last:
|
||||||
builtins.map (n: baseSet.fromDec n) (pkgs.lib.lists.range first last);
|
builtins.map (n: baseSet.fromDec n) (lib.lists.range first last);
|
||||||
|
|
||||||
/* Checks if the given hex string is valid or not.
|
/* Checks if the given hex string is valid or not.
|
||||||
|
|
||||||
@ -77,13 +77,13 @@ rec {
|
|||||||
*/
|
*/
|
||||||
pad = n: hex:
|
pad = n: hex:
|
||||||
let
|
let
|
||||||
strLength = pkgs.lib.stringLength hex;
|
strLength = lib.stringLength hex;
|
||||||
reqWidth = n - strLength;
|
reqWidth = n - strLength;
|
||||||
components = pkgs.lib.genList (_: "0") reqWidth ++ [ hex ];
|
components = lib.genList (_: "0") reqWidth ++ [ hex ];
|
||||||
in
|
in
|
||||||
assert pkgs.lib.assertMsg (isHexString hex)
|
assert lib.assertMsg (isHexString hex)
|
||||||
"bahaghariLib.hex.pad: given hex number (${hex}) is not valid";
|
"bahaghariLib.hex.pad: given hex number (${hex}) is not valid";
|
||||||
if (reqWidth <= 0)
|
if (reqWidth <= 0)
|
||||||
then hex
|
then hex
|
||||||
else pkgs.lib.concatStringsSep "" components;
|
else lib.concatStringsSep "" components;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# A little math utility for common operations. Don't expect any high-level
|
# A little math utility for common operations. Don't expect any high-level
|
||||||
# mathematical operations nor godly optimizations expected from a typical math
|
# mathematical operations nor godly optimizations expected from a typical math
|
||||||
# library, it's just basic high school type of shit in all aspects.
|
# library, it's just basic high school type of shit in all aspects.
|
||||||
{ pkgs, lib }:
|
{ pkgs, lib, self }:
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
/* Returns the absolute value of the given number.
|
/* Returns the absolute value of the given number.
|
||||||
@ -53,7 +53,7 @@ rec {
|
|||||||
=> true
|
=> true
|
||||||
*/
|
*/
|
||||||
isWithinRange = min: max: number:
|
isWithinRange = min: max: number:
|
||||||
(pkgs.lib.max number min) <= (pkgs.lib.min number max);
|
(lib.max number min) <= (lib.min number max);
|
||||||
|
|
||||||
/* Given a number, make it grow by given amount of percentage.
|
/* Given a number, make it grow by given amount of percentage.
|
||||||
A value of 100 should make the number doubled.
|
A value of 100 should make the number doubled.
|
||||||
@ -86,7 +86,7 @@ rec {
|
|||||||
let
|
let
|
||||||
res = grow number value;
|
res = grow number value;
|
||||||
in
|
in
|
||||||
pkgs.lib.min max (pkgs.lib.max res min);
|
lib.min max (lib.max res min);
|
||||||
|
|
||||||
/* Given a number, return its value by the given percentage.
|
/* Given a number, return its value by the given percentage.
|
||||||
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
{ pkgs, lib }:
|
{ pkgs, lib, self }:
|
||||||
|
|
||||||
# TODO: Remove the legacy scheme support once it is entirely removed in Tinted
|
# TODO: Remove the legacy scheme support once it is entirely removed in Tinted
|
||||||
# Theming standard.
|
# Theming standard.
|
||||||
let
|
let
|
||||||
isBaseX = i: palette:
|
isBaseX = i: palette:
|
||||||
let
|
let
|
||||||
paletteNames = pkgs.lib.attrNames palette;
|
paletteNames = lib.attrNames palette;
|
||||||
maxDigitLength = pkgs.lib.lists.length (pkgs.lib.toBaseDigits 10 i);
|
maxDigitLength = lib.lists.length (lib.toBaseDigits 10 i);
|
||||||
mkBaseAttr = hex: "base${lib.hex.pad maxDigitLength hex}";
|
mkBaseAttr = hex: "base${self.hex.pad maxDigitLength hex}";
|
||||||
schemeNames = builtins.map mkBaseAttr (lib.hex.range 0 (i - 1));
|
schemeNames = builtins.map mkBaseAttr (self.hex.range 0 (i - 1));
|
||||||
in
|
in
|
||||||
(pkgs.lib.count (name: pkgs.lib.elem name schemeNames) paletteNames) == i;
|
(lib.count (name: lib.elem name schemeNames) paletteNames) == i;
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
# TODO: Return a Nix object to generate a Tinted Theming color scheme from an
|
# TODO: Return a Nix object to generate a Tinted Theming color scheme from an
|
||||||
@ -105,7 +105,7 @@ rec {
|
|||||||
else null;
|
else null;
|
||||||
|
|
||||||
palette =
|
palette =
|
||||||
pkgs.lib.attrsets.removeAttrs scheme [ "author" "description" "scheme" ];
|
lib.attrsets.removeAttrs scheme [ "author" "description" "scheme" ];
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit (scheme) author;
|
inherit (scheme) author;
|
||||||
@ -113,8 +113,8 @@ rec {
|
|||||||
|
|
||||||
name = scheme.scheme;
|
name = scheme.scheme;
|
||||||
}
|
}
|
||||||
// pkgs.lib.optionalAttrs (scheme?description) { inherit (scheme) description; }
|
// lib.optionalAttrs (scheme?description) { inherit (scheme) description; }
|
||||||
// pkgs.lib.optionalAttrs (system != null) { inherit system; };
|
// lib.optionalAttrs (system != null) { inherit system; };
|
||||||
|
|
||||||
/* Imports a Base16 scheme. This also handles converting the legacy Base16
|
/* Imports a Base16 scheme. This also handles converting the legacy Base16
|
||||||
schema into the new one if it's detected. Take note, every single token
|
schema into the new one if it's detected. Take note, every single token
|
||||||
@ -139,9 +139,9 @@ rec {
|
|||||||
*/
|
*/
|
||||||
importScheme = yamlpath:
|
importScheme = yamlpath:
|
||||||
let
|
let
|
||||||
scheme = lib.importYAML yamlpath;
|
scheme = self.importYAML yamlpath;
|
||||||
in
|
in
|
||||||
assert pkgs.lib.assertMsg (isValidScheme scheme || isLegacyScheme scheme)
|
assert lib.assertMsg (isValidScheme scheme || isLegacyScheme scheme)
|
||||||
"bahaghariLib.tinted-theming.importScheme: given data is not a valid Tinted Theming scheme";
|
"bahaghariLib.tinted-theming.importScheme: given data is not a valid Tinted Theming scheme";
|
||||||
if isLegacyScheme scheme
|
if isLegacyScheme scheme
|
||||||
then modernizeLegacyScheme scheme
|
then modernizeLegacyScheme scheme
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ pkgs, lib }:
|
{ pkgs, lib, self }:
|
||||||
|
|
||||||
rec {
|
rec {
|
||||||
inherit (pkgs.lib.generators) toYAML;
|
inherit (pkgs.lib.generators) toYAML;
|
||||||
@ -21,10 +21,10 @@ rec {
|
|||||||
importYAML = path:
|
importYAML = path:
|
||||||
let
|
let
|
||||||
dataDrv = pkgs.runCommand "convert-yaml-to-json" { } ''
|
dataDrv = pkgs.runCommand "convert-yaml-to-json" { } ''
|
||||||
${pkgs.lib.getExe' pkgs.yaml2json "yaml2json"} < "${path}" > "$out"
|
${lib.getExe' pkgs.yaml2json "yaml2json"} < "${path}" > "$out"
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
pkgs.lib.importJSON dataDrv;
|
lib.importJSON dataDrv;
|
||||||
|
|
||||||
/* Convert a given decimal number to a specified base digit with the set of
|
/* Convert a given decimal number to a specified base digit with the set of
|
||||||
glyphs for each digit as returned from lib.toBaseDigits.
|
glyphs for each digit as returned from lib.toBaseDigits.
|
||||||
@ -44,10 +44,10 @@ rec {
|
|||||||
*/
|
*/
|
||||||
toBaseDigitsWithGlyphs = base: i: glyphs:
|
toBaseDigitsWithGlyphs = base: i: glyphs:
|
||||||
let
|
let
|
||||||
baseDigits = pkgs.lib.toBaseDigits base i;
|
baseDigits = lib.toBaseDigits base i;
|
||||||
toBaseDigits = d: glyphs.${builtins.toString d};
|
toBaseDigits = d: glyphs.${builtins.toString d};
|
||||||
in
|
in
|
||||||
pkgs.lib.concatMapStrings toBaseDigits baseDigits;
|
lib.concatMapStrings toBaseDigits baseDigits;
|
||||||
|
|
||||||
/* Generates a glyph set usable for `toBaseDigitsWithGlyphs`. Take note the
|
/* Generates a glyph set usable for `toBaseDigitsWithGlyphs`. Take note the
|
||||||
given list is assumed to be sorted and the generated glyph set starts at
|
given list is assumed to be sorted and the generated glyph set starts at
|
||||||
@ -68,11 +68,11 @@ rec {
|
|||||||
generateGlyphSet = glyphsList:
|
generateGlyphSet = glyphsList:
|
||||||
let
|
let
|
||||||
glyphsList' =
|
glyphsList' =
|
||||||
pkgs.lib.lists.imap0
|
lib.lists.imap0
|
||||||
(i: glyph: pkgs.lib.nameValuePair (builtins.toString i) glyph)
|
(i: glyph: lib.nameValuePair (builtins.toString i) glyph)
|
||||||
glyphsList;
|
glyphsList;
|
||||||
in
|
in
|
||||||
pkgs.lib.listToAttrs glyphsList';
|
lib.listToAttrs glyphsList';
|
||||||
|
|
||||||
/* Generates a conversion table for a sorted list of glyphs to its decimal
|
/* Generates a conversion table for a sorted list of glyphs to its decimal
|
||||||
number. Suitable for creating your own conversion function. Accepts the
|
number. Suitable for creating your own conversion function. Accepts the
|
||||||
@ -93,11 +93,11 @@ rec {
|
|||||||
generateConversionTable = glyphsList:
|
generateConversionTable = glyphsList:
|
||||||
let
|
let
|
||||||
glyphsList' =
|
glyphsList' =
|
||||||
pkgs.lib.lists.imap0
|
lib.lists.imap0
|
||||||
(i: glyph: pkgs.lib.nameValuePair glyph i)
|
(i: glyph: lib.nameValuePair glyph i)
|
||||||
glyphsList;
|
glyphsList;
|
||||||
in
|
in
|
||||||
pkgs.lib.listToAttrs glyphsList';
|
lib.listToAttrs glyphsList';
|
||||||
|
|
||||||
/* A factory function for generating an attribute set containing a glyph
|
/* A factory function for generating an attribute set containing a glyph
|
||||||
set, a conversion table, and a conversion function to and from decimal.
|
set, a conversion table, and a conversion function to and from decimal.
|
||||||
@ -118,7 +118,7 @@ rec {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
generateBaseDigitType = glyphsList: rec {
|
generateBaseDigitType = glyphsList: rec {
|
||||||
base = pkgs.lib.length glyphsList;
|
base = lib.length glyphsList;
|
||||||
glyphSet = generateGlyphSet glyphsList;
|
glyphSet = generateGlyphSet glyphsList;
|
||||||
conversionTable = generateConversionTable glyphsList;
|
conversionTable = generateConversionTable glyphsList;
|
||||||
|
|
||||||
@ -129,18 +129,18 @@ rec {
|
|||||||
# open a can of worms about implementing this with stringy types.
|
# open a can of worms about implementing this with stringy types.
|
||||||
fromDec = decimal:
|
fromDec = decimal:
|
||||||
let
|
let
|
||||||
digits = pkgs.lib.toBaseDigits base decimal;
|
digits = lib.toBaseDigits base decimal;
|
||||||
in
|
in
|
||||||
pkgs.lib.concatMapStrings (d: glyphSet.${builtins.toString d}) digits;
|
lib.concatMapStrings (d: glyphSet.${builtins.toString d}) digits;
|
||||||
|
|
||||||
toDec = digit:
|
toDec = digit:
|
||||||
let
|
let
|
||||||
chars = pkgs.lib.stringToCharacters digit;
|
chars = lib.stringToCharacters digit;
|
||||||
maxDigits = (pkgs.lib.length chars) - 1;
|
maxDigits = (lib.length chars) - 1;
|
||||||
convertDigitToDec =
|
convertDigitToDec =
|
||||||
pkgs.lib.lists.imap0 (i: v: conversionTable.${v} * (lib.math.pow base (maxDigits - i))) chars;
|
lib.lists.imap0 (i: v: conversionTable.${v} * (self.math.pow base (maxDigits - i))) chars;
|
||||||
in
|
in
|
||||||
pkgs.lib.foldl (sum: v: sum + v) 0 convertDigitToDec;
|
lib.foldl (sum: v: sum + v) 0 convertDigitToDec;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Given a range of two numbers, ensure the value is only returned within the
|
/* Given a range of two numbers, ensure the value is only returned within the
|
||||||
@ -154,7 +154,10 @@ rec {
|
|||||||
|
|
||||||
clamp (-100) 100 (-234)
|
clamp (-100) 100 (-234)
|
||||||
=> -100
|
=> -100
|
||||||
|
|
||||||
|
clamp (-100) 100 54
|
||||||
|
=> 54
|
||||||
*/
|
*/
|
||||||
clamp = min: max: value:
|
clamp = min: max: value:
|
||||||
pkgs.lib.min max (pkgs.lib.max min value);
|
lib.min max (lib.max min value);
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
lib = import ../../lib { inherit pkgs; };
|
lib = import ../../lib { inherit pkgs; };
|
||||||
|
callLib = file: import file {
|
||||||
|
inherit (pkgs) lib; inherit pkgs;
|
||||||
|
self = lib;
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
hex = import ./hex.nix { inherit pkgs lib; };
|
hex = callLib ./hex.nix;
|
||||||
math = import ./math.nix { inherit pkgs lib; };
|
math = callLib ./math.nix;
|
||||||
trivial = import ./trivial { inherit pkgs lib; };
|
trivial = callLib ./trivial;
|
||||||
tinted-theming = import ./tinted-theming { inherit pkgs lib; };
|
tinted-theming = callLib ./tinted-theming;
|
||||||
}
|
}
|
||||||
|
@ -1,63 +1,63 @@
|
|||||||
{ pkgs, lib }:
|
{ pkgs, lib, self }:
|
||||||
|
|
||||||
pkgs.lib.runTests {
|
lib.runTests {
|
||||||
testToHexString = {
|
testToHexString = {
|
||||||
expr = lib.hex.fromDec 293454837;
|
expr = self.hex.fromDec 293454837;
|
||||||
expected = "117DC3F5";
|
expected = "117DC3F5";
|
||||||
};
|
};
|
||||||
|
|
||||||
testToHexString2 = {
|
testToHexString2 = {
|
||||||
expr = lib.hex.fromDec 4500;
|
expr = self.hex.fromDec 4500;
|
||||||
expected = "1194";
|
expected = "1194";
|
||||||
};
|
};
|
||||||
|
|
||||||
testToHexString3 = {
|
testToHexString3 = {
|
||||||
expr = lib.hex.fromDec 5942819;
|
expr = self.hex.fromDec 5942819;
|
||||||
expected = "5AAE23";
|
expected = "5AAE23";
|
||||||
};
|
};
|
||||||
|
|
||||||
testHexToDec = {
|
testHexToDec = {
|
||||||
expr = lib.hex.toDec "FF";
|
expr = self.hex.toDec "FF";
|
||||||
expected = 255;
|
expected = 255;
|
||||||
};
|
};
|
||||||
|
|
||||||
testHexToDec2 = {
|
testHexToDec2 = {
|
||||||
expr = lib.hex.toDec "333FAB333";
|
expr = self.hex.toDec "333FAB333";
|
||||||
expected = 13756969779;
|
expected = 13756969779;
|
||||||
};
|
};
|
||||||
|
|
||||||
testCreateHexRange = {
|
testCreateHexRange = {
|
||||||
expr = lib.hex.range 10 17;
|
expr = self.hex.range 10 17;
|
||||||
expected = [ "A" "B" "C" "D" "E" "F" "10" "11" ];
|
expected = [ "A" "B" "C" "D" "E" "F" "10" "11" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
testCreateHexWithHigherStart = {
|
testCreateHexWithHigherStart = {
|
||||||
expr = lib.hex.range 49 17;
|
expr = self.hex.range 49 17;
|
||||||
expected = [ ];
|
expected = [ ];
|
||||||
};
|
};
|
||||||
|
|
||||||
testIsHexString = {
|
testIsHexString = {
|
||||||
expr = lib.hex.isHexString "ABC";
|
expr = self.hex.isHexString "ABC";
|
||||||
expected = true;
|
expected = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
testIsHexStringWithInvalidHex = {
|
testIsHexStringWithInvalidHex = {
|
||||||
expr = lib.hex.isHexString "WHAT IS THIS";
|
expr = self.hex.isHexString "WHAT IS THIS";
|
||||||
expected = false;
|
expected = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
testHexPad = {
|
testHexPad = {
|
||||||
expr = lib.hex.pad 5 "A";
|
expr = self.hex.pad 5 "A";
|
||||||
expected = "0000A";
|
expected = "0000A";
|
||||||
};
|
};
|
||||||
|
|
||||||
testHexPadWithLowerMaxDigits = {
|
testHexPadWithLowerMaxDigits = {
|
||||||
expr = lib.hex.pad 1 "9AC";
|
expr = self.hex.pad 1 "9AC";
|
||||||
expected = "9AC";
|
expected = "9AC";
|
||||||
};
|
};
|
||||||
|
|
||||||
testHexPadWithNegativeDigits = {
|
testHexPadWithNegativeDigits = {
|
||||||
expr = lib.hex.pad (-5) "A42C";
|
expr = self.hex.pad (-5) "A42C";
|
||||||
expected = "A42C";
|
expected = "A42C";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,98 +1,98 @@
|
|||||||
{ pkgs, lib }:
|
{ pkgs, lib, self }:
|
||||||
|
|
||||||
pkgs.lib.runTests {
|
lib.runTests {
|
||||||
testMathPowPositive = {
|
testMathPowPositive = {
|
||||||
expr = lib.math.pow 2 8;
|
expr = self.math.pow 2 8;
|
||||||
expected = 256;
|
expected = 256;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathPowNegative = {
|
testMathPowNegative = {
|
||||||
expr = lib.math.pow 2.0 (-1);
|
expr = self.math.pow 2.0 (-1);
|
||||||
expected = 0.5;
|
expected = 0.5;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathPowZero = {
|
testMathPowZero = {
|
||||||
expr = lib.math.pow 31 0;
|
expr = self.math.pow 31 0;
|
||||||
expected = 1;
|
expected = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathAbsoluteValue = {
|
testMathAbsoluteValue = {
|
||||||
expr = lib.math.abs 5493;
|
expr = self.math.abs 5493;
|
||||||
expected = 5493;
|
expected = 5493;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathAbsoluteValue2 = {
|
testMathAbsoluteValue2 = {
|
||||||
expr = lib.math.abs (-435354);
|
expr = self.math.abs (-435354);
|
||||||
expected = 435354;
|
expected = 435354;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathPercentage = {
|
testMathPercentage = {
|
||||||
expr = lib.math.percentage 50 100;
|
expr = self.math.percentage 50 100;
|
||||||
expected = 50;
|
expected = 50;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathPercentage2 = {
|
testMathPercentage2 = {
|
||||||
expr = lib.math.percentage 13 453;
|
expr = self.math.percentage 13 453;
|
||||||
expected = 58.89;
|
expected = 58.89;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathPercentageNegative = {
|
testMathPercentageNegative = {
|
||||||
expr = lib.math.percentage (-20) 500;
|
expr = self.math.percentage (-20) 500;
|
||||||
expected = -100;
|
expected = -100;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathPercentageNegative2 = {
|
testMathPercentageNegative2 = {
|
||||||
expr = lib.math.percentage (-64) 843;
|
expr = self.math.percentage (-64) 843;
|
||||||
expected = -539.52;
|
expected = -539.52;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathPercentageZero = {
|
testMathPercentageZero = {
|
||||||
expr = lib.math.percentage 0 45723;
|
expr = self.math.percentage 0 45723;
|
||||||
expected = 0;
|
expected = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathPercentageZero2 = {
|
testMathPercentageZero2 = {
|
||||||
expr = lib.math.percentage 0 (-3423);
|
expr = self.math.percentage 0 (-3423);
|
||||||
expected = 0;
|
expected = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathGrow = {
|
testMathGrow = {
|
||||||
expr = lib.math.grow 500 12;
|
expr = self.math.grow 500 12;
|
||||||
expected = 72;
|
expected = 72;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathGrow2 = {
|
testMathGrow2 = {
|
||||||
expr = lib.math.grow 55.5 5.5;
|
expr = self.math.grow 55.5 5.5;
|
||||||
expected = 8.5525;
|
expected = 8.5525;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathGrowVariantMax = {
|
testMathGrowVariantMax = {
|
||||||
expr = lib.math.grow' 0 255 130 100;
|
expr = self.math.grow' 0 255 130 100;
|
||||||
expected = 255;
|
expected = 255;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathGrowVariantMin = {
|
testMathGrowVariantMin = {
|
||||||
expr = lib.math.grow' 0 255 130 (-500);
|
expr = self.math.grow' 0 255 130 (-500);
|
||||||
expected = 0;
|
expected = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathRoundDown = {
|
testMathRoundDown = {
|
||||||
expr = lib.math.round 2.3;
|
expr = self.math.round 2.3;
|
||||||
expected = 2;
|
expected = 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathRoundUp = {
|
testMathRoundUp = {
|
||||||
expr = lib.math.round 2.8;
|
expr = self.math.round 2.8;
|
||||||
expected = 3;
|
expected = 3;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathWithinRange = {
|
testMathWithinRange = {
|
||||||
expr = lib.math.isWithinRange (-100) 100 50;
|
expr = self.math.isWithinRange (-100) 100 50;
|
||||||
expected = true;
|
expected = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
testMathWithinRange2 = {
|
testMathWithinRange2 = {
|
||||||
expr = lib.math.isWithinRange 5 10 (-5);
|
expr = self.math.isWithinRange 5 10 (-5);
|
||||||
expected = false;
|
expected = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
{ pkgs, lib }:
|
{ pkgs, lib, self }:
|
||||||
|
|
||||||
let
|
let
|
||||||
sampleBase16Scheme = lib.tinted-theming.importScheme ./sample-base16-scheme.yml;
|
sampleBase16Scheme = self.tinted-theming.importScheme ./sample-base16-scheme.yml;
|
||||||
sampleBase16Scheme' = lib.tinted-theming.importScheme ./sample-base16-scheme-with-missing-colors.yml;
|
sampleBase16Scheme' = self.tinted-theming.importScheme ./sample-base16-scheme-with-missing-colors.yml;
|
||||||
sampleBase24Scheme = lib.tinted-theming.importScheme ./sample-base24-scheme.yml;
|
sampleBase24Scheme = self.tinted-theming.importScheme ./sample-base24-scheme.yml;
|
||||||
sampleBase24Scheme' = lib.tinted-theming.importScheme ./sample-base24-scheme-with-missing-colors.yml;
|
sampleBase24Scheme' = self.tinted-theming.importScheme ./sample-base24-scheme-with-missing-colors.yml;
|
||||||
in
|
in
|
||||||
pkgs.lib.runTests {
|
lib.runTests {
|
||||||
testTintedThemingSchemeImport = {
|
testTintedThemingSchemeImport = {
|
||||||
expr = lib.tinted-theming.importScheme ./sample-base16-scheme.yml;
|
expr = self.tinted-theming.importScheme ./sample-base16-scheme.yml;
|
||||||
expected = {
|
expected = {
|
||||||
system = "base16";
|
system = "base16";
|
||||||
name = "Bark on a tree";
|
name = "Bark on a tree";
|
||||||
@ -37,7 +37,7 @@ pkgs.lib.runTests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
testTintedThemingLegacyBase24SchemeImport = {
|
testTintedThemingLegacyBase24SchemeImport = {
|
||||||
expr = lib.tinted-theming.importScheme ./sample-legacy-base24.yml;
|
expr = self.tinted-theming.importScheme ./sample-legacy-base24.yml;
|
||||||
expected = {
|
expected = {
|
||||||
system = "base24";
|
system = "base24";
|
||||||
name = "Scheme Name";
|
name = "Scheme Name";
|
||||||
@ -73,7 +73,7 @@ pkgs.lib.runTests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
testTintedThemingLegacyBase16SchemeImport = {
|
testTintedThemingLegacyBase16SchemeImport = {
|
||||||
expr = lib.tinted-theming.importScheme ./sample-legacy-base16.yml;
|
expr = self.tinted-theming.importScheme ./sample-legacy-base16.yml;
|
||||||
expected = {
|
expected = {
|
||||||
system = "base16";
|
system = "base16";
|
||||||
name = "Scheme Name";
|
name = "Scheme Name";
|
||||||
@ -101,32 +101,32 @@ pkgs.lib.runTests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
testIsBase16 = {
|
testIsBase16 = {
|
||||||
expr = lib.tinted-theming.isBase16 sampleBase16Scheme.palette;
|
expr = self.tinted-theming.isBase16 sampleBase16Scheme.palette;
|
||||||
expected = true;
|
expected = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
testIsNotBase16 = {
|
testIsNotBase16 = {
|
||||||
expr = lib.tinted-theming.isBase16 sampleBase16Scheme'.palette;
|
expr = self.tinted-theming.isBase16 sampleBase16Scheme'.palette;
|
||||||
expected = false;
|
expected = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
testIsBase24 = {
|
testIsBase24 = {
|
||||||
expr = lib.tinted-theming.isBase24 sampleBase24Scheme.palette;
|
expr = self.tinted-theming.isBase24 sampleBase24Scheme.palette;
|
||||||
expected = true;
|
expected = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
testIsNotBase24 = {
|
testIsNotBase24 = {
|
||||||
expr = lib.tinted-theming.isBase24 sampleBase24Scheme'.palette;
|
expr = self.tinted-theming.isBase24 sampleBase24Scheme'.palette;
|
||||||
expected = false;
|
expected = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
testIsALegacyBase16Scheme = {
|
testIsALegacyBase16Scheme = {
|
||||||
expr = lib.tinted-theming.isLegacyScheme (lib.importYAML ./sample-legacy-base16.yml);
|
expr = self.tinted-theming.isLegacyScheme (self.importYAML ./sample-legacy-base16.yml);
|
||||||
expected = true;
|
expected = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
testIsALegacyBase24Scheme = {
|
testIsALegacyBase24Scheme = {
|
||||||
expr = lib.tinted-theming.isLegacyScheme (lib.importYAML ./sample-legacy-base24.yml);
|
expr = self.tinted-theming.isLegacyScheme (self.importYAML ./sample-legacy-base24.yml);
|
||||||
expected = true;
|
expected = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{ pkgs, lib }:
|
{ pkgs, lib, self }:
|
||||||
|
|
||||||
let
|
let
|
||||||
customOctalGlyphs = {
|
customOctalGlyphs = {
|
||||||
@ -66,21 +66,21 @@ let
|
|||||||
"23" = "N";
|
"23" = "N";
|
||||||
};
|
};
|
||||||
|
|
||||||
base24Set = lib.trivial.generateBaseDigitType base24GlyphsList;
|
base24Set = self.trivial.generateBaseDigitType base24GlyphsList;
|
||||||
in
|
in
|
||||||
pkgs.lib.runTests {
|
lib.runTests {
|
||||||
testGenerateCustomGlyphSet = {
|
testGenerateCustomGlyphSet = {
|
||||||
expr = lib.trivial.generateGlyphSet [ "A" "B" "C" "D" "E" "F" "G" "H" ];
|
expr = self.trivial.generateGlyphSet [ "A" "B" "C" "D" "E" "F" "G" "H" ];
|
||||||
expected = customOctalGlyphs;
|
expected = customOctalGlyphs;
|
||||||
};
|
};
|
||||||
|
|
||||||
testGenerateBase24GlyphSet = {
|
testGenerateBase24GlyphSet = {
|
||||||
expr = lib.trivial.generateGlyphSet base24GlyphsList;
|
expr = self.trivial.generateGlyphSet base24GlyphsList;
|
||||||
expected = customBase24Glyphs;
|
expected = customBase24Glyphs;
|
||||||
};
|
};
|
||||||
|
|
||||||
testGenerateConversionTable = {
|
testGenerateConversionTable = {
|
||||||
expr = lib.trivial.generateConversionTable [ "A" "B" "C" "D" "E" "F" "G" "H" ];
|
expr = self.trivial.generateConversionTable [ "A" "B" "C" "D" "E" "F" "G" "H" ];
|
||||||
expected = {
|
expected = {
|
||||||
"A" = 0;
|
"A" = 0;
|
||||||
"B" = 1;
|
"B" = 1;
|
||||||
@ -94,7 +94,7 @@ pkgs.lib.runTests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
testGenerateConversionTable2 = {
|
testGenerateConversionTable2 = {
|
||||||
expr = lib.trivial.generateConversionTable
|
expr = self.trivial.generateConversionTable
|
||||||
[
|
[
|
||||||
"0"
|
"0"
|
||||||
"1"
|
"1"
|
||||||
@ -145,29 +145,29 @@ pkgs.lib.runTests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
testBaseDigitWithCustomOctalGlyph = {
|
testBaseDigitWithCustomOctalGlyph = {
|
||||||
expr = lib.trivial.toBaseDigitsWithGlyphs 8 9 customOctalGlyphs;
|
expr = self.trivial.toBaseDigitsWithGlyphs 8 9 customOctalGlyphs;
|
||||||
expected = "BB";
|
expected = "BB";
|
||||||
};
|
};
|
||||||
|
|
||||||
testBaseDigitWithCustomOctalGlyph2 = {
|
testBaseDigitWithCustomOctalGlyph2 = {
|
||||||
expr = lib.trivial.toBaseDigitsWithGlyphs 8 641 customOctalGlyphs;
|
expr = self.trivial.toBaseDigitsWithGlyphs 8 641 customOctalGlyphs;
|
||||||
expected = "BCAB";
|
expected = "BCAB";
|
||||||
};
|
};
|
||||||
|
|
||||||
testBaseDigitWithProperBase24Glyph = {
|
testBaseDigitWithProperBase24Glyph = {
|
||||||
expr = lib.trivial.toBaseDigitsWithGlyphs 24 641 customBase24Glyphs;
|
expr = self.trivial.toBaseDigitsWithGlyphs 24 641 customBase24Glyphs;
|
||||||
expected = "12H";
|
expected = "12H";
|
||||||
};
|
};
|
||||||
|
|
||||||
testBaseDigitWithProperBase24Glyph2 = {
|
testBaseDigitWithProperBase24Glyph2 = {
|
||||||
expr = lib.trivial.toBaseDigitsWithGlyphs 24 2583 customBase24Glyphs;
|
expr = self.trivial.toBaseDigitsWithGlyphs 24 2583 customBase24Glyphs;
|
||||||
expected = "4BF";
|
expected = "4BF";
|
||||||
};
|
};
|
||||||
|
|
||||||
# We're mainly testing if the underlying YAML library is mostly compliant
|
# We're mainly testing if the underlying YAML selfrary is mostly compliant
|
||||||
# with whatever it claims.
|
# with whatever it claims.
|
||||||
testImportBasicYAML = {
|
testImportBasicYAML = {
|
||||||
expr = lib.trivial.importYAML ./simple.yml;
|
expr = self.trivial.importYAML ./simple.yml;
|
||||||
expected = {
|
expected = {
|
||||||
hello = "there";
|
hello = "there";
|
||||||
how-are-you-doing = "I'm fine. Thank you for asking.\n";
|
how-are-you-doing = "I'm fine. Thank you for asking.\n";
|
||||||
@ -177,7 +177,7 @@ pkgs.lib.runTests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
testImportTintedThemingBase16YAML = {
|
testImportTintedThemingBase16YAML = {
|
||||||
expr = lib.trivial.importYAML ../tinted-theming/sample-base16-scheme.yml;
|
expr = self.trivial.importYAML ../tinted-theming/sample-base16-scheme.yml;
|
||||||
expected = {
|
expected = {
|
||||||
system = "base16";
|
system = "base16";
|
||||||
name = "Bark on a tree";
|
name = "Bark on a tree";
|
||||||
@ -207,22 +207,22 @@ pkgs.lib.runTests {
|
|||||||
|
|
||||||
# YAML is a superset of JSON (or was it the other way around?) after v1.2.
|
# YAML is a superset of JSON (or was it the other way around?) after v1.2.
|
||||||
testToYAML = {
|
testToYAML = {
|
||||||
expr = lib.trivial.toYAML { } { hello = "there"; };
|
expr = self.trivial.toYAML { } { hello = "there"; };
|
||||||
expected = "{\"hello\":\"there\"}";
|
expected = "{\"hello\":\"there\"}";
|
||||||
};
|
};
|
||||||
|
|
||||||
testNumberClamp = {
|
testNumberClamp = {
|
||||||
expr = lib.trivial.clamp 1 10 4;
|
expr = self.trivial.clamp 1 10 4;
|
||||||
expected = 4;
|
expected = 4;
|
||||||
};
|
};
|
||||||
|
|
||||||
testNumberClampMin = {
|
testNumberClampMin = {
|
||||||
expr = lib.trivial.clamp 1 10 (-5);
|
expr = self.trivial.clamp 1 10 (-5);
|
||||||
expected = 1;
|
expected = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
testNumberClampMax = {
|
testNumberClampMax = {
|
||||||
expr = lib.trivial.clamp 1 10 453;
|
expr = self.trivial.clamp 1 10 453;
|
||||||
expected = 10;
|
expected = 10;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user