mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-07-06 17:13:24 -05:00
lib/types: add tests for types.mkStructuredType
This commit is contained in:
parent
53b47eb93d
commit
f4d45cdced
2 changed files with 45 additions and 0 deletions
|
|
@ -254,6 +254,19 @@ checkConfigError 'A definition for option .* is not of type .fileset.. Definitio
|
|||
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err3 ./fileset.nix
|
||||
checkConfigError 'A definition for option .* is not of type .fileset.. Definition values:\n.*' config.filesetCardinal.err4 ./fileset.nix
|
||||
|
||||
# types.serializableValueWith
|
||||
checkConfigOutput '^null$' config.nullableValue.null ./types.nix
|
||||
checkConfigOutput '^true$' config.nullableValue.bool ./types.nix
|
||||
checkConfigOutput '^1$' config.nullableValue.int ./types.nix
|
||||
checkConfigOutput '^1.1$' config.nullableValue.float ./types.nix
|
||||
checkConfigOutput '^"foo"$' config.nullableValue.str ./types.nix
|
||||
checkConfigOutput '^".*/store.*"$' config.nullableValue.path ./types.nix
|
||||
STRICT_EVAL=1 checkConfigOutput '^\{"foo":1\}$' config.nullableValue.attrs ./types.nix
|
||||
STRICT_EVAL=1 checkConfigOutput '^\[\{"bar":\[1\]\}\]$' config.nullableValue.list ./types.nix
|
||||
|
||||
checkConfigError 'A definition for option .* is not of type .VAL value.. .*' config.nullableValue.lambda ./types.nix
|
||||
checkConfigError 'A definition for option .* is not of type .VAL value.. .*' config.structuredValue.null ./types.nix
|
||||
|
||||
# Check boolean option.
|
||||
checkConfigOutput '^false$' config.enable ./declare-enable.nix
|
||||
checkConfigError 'The option .* does not exist. Definition values:\n\s*- In .*: true' config.enable ./define-enable.nix
|
||||
|
|
|
|||
|
|
@ -16,6 +16,19 @@ in
|
|||
options = {
|
||||
pathInStore = mkOption { type = types.lazyAttrsOf types.pathInStore; };
|
||||
externalPath = mkOption { type = types.lazyAttrsOf types.externalPath; };
|
||||
# serializableValueWith
|
||||
nullableValue = mkOption {
|
||||
type = types.attrsOf (types.serializableValueWith { typeName = "VAL"; });
|
||||
};
|
||||
structuredValue = mkOption {
|
||||
type = types.attrsOf (
|
||||
types.serializableValueWith {
|
||||
typeName = "VAL";
|
||||
nullable = false;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
assertions = mkOption { };
|
||||
};
|
||||
config = {
|
||||
|
|
@ -35,6 +48,22 @@ in
|
|||
externalPath.ok1 = "/foo/bar";
|
||||
externalPath.ok2 = "/";
|
||||
|
||||
# serializableValueWith { nullable = true; }
|
||||
nullableValue.null = null; # null
|
||||
nullableValue.bool = true; # bool
|
||||
nullableValue.int = 1; # int
|
||||
nullableValue.float = 1.1; # float
|
||||
nullableValue.str = "foo"; # str
|
||||
nullableValue.path = ./.; # path
|
||||
nullableValue.attrs = {
|
||||
foo = 1;
|
||||
};
|
||||
nullableValue.list = [ { bar = [ 1 ]; } ]; # list
|
||||
nullableValue.lambda = x: x; # Error
|
||||
|
||||
# serializableValueWith { nullable = false; }
|
||||
structuredValue.null = null; # Error
|
||||
|
||||
assertions =
|
||||
with lib.types;
|
||||
|
||||
|
|
@ -486,6 +515,9 @@ in
|
|||
assert (unique { message = "custom"; } (listOf str)).description == "list of string";
|
||||
assert (unique { message = "test"; } (either int str)).description == "signed integer or string";
|
||||
assert (unique { message = "test"; } (listOf str)).description == "list of string";
|
||||
# json & toml
|
||||
assert json.description == "JSON value";
|
||||
assert toml.description == "TOML value";
|
||||
# done
|
||||
"ok";
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue