forked from fediversity/fediversity
152 lines
3.4 KiB
Nix
152 lines
3.4 KiB
Nix
let
|
|
inherit (import ../default.nix { }) pkgs;
|
|
inherit (pkgs) lib;
|
|
inherit (builtins) tryEval;
|
|
inherit (lib) mkOption types;
|
|
inherit (types)
|
|
int
|
|
str
|
|
submodule
|
|
;
|
|
functionType = submodule ./function.nix;
|
|
in
|
|
{
|
|
_class = "nix-unit";
|
|
|
|
test-function-ok = {
|
|
expr =
|
|
tryEval
|
|
(lib.evalModules {
|
|
modules = [
|
|
(
|
|
{ config, ... }:
|
|
{
|
|
options = {
|
|
fn = mkOption {
|
|
type = functionType;
|
|
};
|
|
call = mkOption {
|
|
default = config.fn.apply 1;
|
|
};
|
|
};
|
|
config.fn = {
|
|
implementation = x: x;
|
|
input-type = int;
|
|
output-type = int;
|
|
};
|
|
}
|
|
)
|
|
];
|
|
}).config.call;
|
|
expected = {
|
|
success = true;
|
|
value = 1;
|
|
};
|
|
};
|
|
|
|
test-bad-input = {
|
|
expr =
|
|
tryEval
|
|
(lib.evalModules {
|
|
modules = [
|
|
(
|
|
{ config, ... }:
|
|
{
|
|
options = {
|
|
fn = mkOption {
|
|
type = functionType;
|
|
};
|
|
call = mkOption {
|
|
default = config.fn.apply 1;
|
|
};
|
|
};
|
|
config.fn = {
|
|
implementation = x: x;
|
|
input-type = str;
|
|
output-type = int;
|
|
};
|
|
}
|
|
)
|
|
];
|
|
}).config.call;
|
|
expected = {
|
|
success = false;
|
|
value = false;
|
|
};
|
|
};
|
|
|
|
test-bad-output = {
|
|
expr =
|
|
tryEval
|
|
(lib.evalModules {
|
|
modules = [
|
|
(
|
|
{ config, ... }:
|
|
{
|
|
options = {
|
|
fn = mkOption {
|
|
type = functionType;
|
|
};
|
|
call = mkOption {
|
|
default = config.fn.apply 1;
|
|
};
|
|
};
|
|
config.fn = {
|
|
implementation = x: x;
|
|
input-type = int;
|
|
output-type = str;
|
|
};
|
|
}
|
|
)
|
|
];
|
|
}).config.call;
|
|
expected = {
|
|
success = false;
|
|
value = false;
|
|
};
|
|
};
|
|
|
|
test-read-only = {
|
|
expr =
|
|
tryEval
|
|
(lib.evalModules {
|
|
modules = [
|
|
(
|
|
{ config, ... }:
|
|
{
|
|
options = {
|
|
fn = mkOption {
|
|
type = functionType;
|
|
};
|
|
call = mkOption {
|
|
default = config.fn.apply { };
|
|
};
|
|
};
|
|
config.fn =
|
|
let
|
|
sub = submodule {
|
|
options.foo = mkOption {
|
|
type = int;
|
|
readOnly = true;
|
|
default = 1;
|
|
};
|
|
};
|
|
in
|
|
{
|
|
implementation = x: x;
|
|
input-type = sub;
|
|
output-type = sub;
|
|
type-output = false;
|
|
};
|
|
}
|
|
)
|
|
];
|
|
}).config.call;
|
|
expected = {
|
|
success = true;
|
|
value = {
|
|
foo = 1;
|
|
};
|
|
};
|
|
};
|
|
}
|