mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-17 14:19:58 +03:00
lib/types: add ints.positive
.
For values that are positive, but cannot be 0.
This commit is contained in:
parent
1158910676
commit
462c048c77
@ -65,6 +65,8 @@ checkConfigError 'The option .* defined in .* does not exist.' config.enable ./d
|
||||
# unsigned
|
||||
checkConfigOutput "42" config.value ./declare-int-unsigned-value.nix ./define-value-int-positive.nix
|
||||
checkConfigError 'The option value .* in .* is not of type.*unsigned integer.*' config.value ./declare-int-unsigned-value.nix ./define-value-int-negative.nix
|
||||
# positive
|
||||
checkConfigError 'The option value .* in .* is not of type.*positive integer.*' config.value ./declare-int-positive-value.nix ./define-value-int-zero.nix
|
||||
# between
|
||||
checkConfigOutput "42" config.value ./declare-int-between-value.nix ./define-value-int-positive.nix
|
||||
checkConfigError 'The option value .* in .* is not of type.*between.*-21 and 43.*inclusive.*' config.value ./declare-int-between-value.nix ./define-value-int-negative.nix
|
||||
|
9
lib/tests/modules/declare-int-positive-value.nix
Normal file
9
lib/tests/modules/declare-int-positive-value.nix
Normal file
@ -0,0 +1,9 @@
|
||||
{ lib, ... }:
|
||||
|
||||
{
|
||||
options = {
|
||||
value = lib.mkOption {
|
||||
type = lib.types.ints.positive;
|
||||
};
|
||||
};
|
||||
}
|
3
lib/tests/modules/define-value-int-zero.nix
Normal file
3
lib/tests/modules/define-value-int-zero.nix
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
value = 0;
|
||||
}
|
@ -151,6 +151,10 @@ rec {
|
||||
name = "unsignedInt";
|
||||
description = "unsigned integer, meaning >=0";
|
||||
};
|
||||
positive = addCheck types.int (x: x > 0) // {
|
||||
name = "positiveInt";
|
||||
description = "positive integer, meaning >0";
|
||||
};
|
||||
u8 = unsign 8 256;
|
||||
u16 = unsign 16 65536;
|
||||
u32 = unsign 32 4294967296;
|
||||
|
@ -78,6 +78,13 @@
|
||||
for 8 bits).
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<varname>types.ints.positive</varname>
|
||||
</term>
|
||||
<listitem><para>A positive integer (that is > 0).
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
<para>String-related types:</para>
|
||||
|
Loading…
Reference in New Issue
Block a user