lib/trivial: add a few examples of usage of assertMsg/assertOneOf

This commit is contained in:
Profpatsch
2018-09-06 18:14:27 +02:00
parent 320cdecd16
commit 3e45b61a99
5 changed files with 20 additions and 10 deletions
+5 -2
View File
@@ -410,7 +410,7 @@ rec {
components = splitString "/" url;
filename = lib.last components;
name = builtins.head (splitString sep filename);
in assert name != filename; name;
in assert name != filename; name;
/* Create an --{enable,disable}-<feat> string that can be passed to
standard GNU Autoconf scripts.
@@ -468,7 +468,10 @@ rec {
strw = lib.stringLength str;
reqWidth = width - (lib.stringLength filler);
in
assert strw <= width;
assert lib.assertMsg (strw <= width)
"fixedWidthString: requested string length (${
toString width}) must not be shorter than actual length (${
toString strw})";
if strw == width then str else filler + fixedWidthString reqWidth filler str;
/* Format a number adding leading zeroes up to fixed width.