Jsonschema: clean up tests

This commit is contained in:
Johannes Kirschbauer
2024-11-08 13:22:58 +01:00
parent bdd9497335
commit c33c5f8b19
2 changed files with 254 additions and 253 deletions

View File

@@ -209,42 +209,6 @@ in
}; };
}; };
testFreeFormOfInt =
let
default = {
foo = 1;
bar = 2;
};
in
{
expr = slib.parseOptions (lib.evalModules {
modules = [
{
freeformType = with lib.types; attrsOf int;
options = {
enable = lib.mkEnableOption "enable this";
};
}
default
];
}).options { };
expected = {
"$schema" = "http://json-schema.org/draft-07/schema#";
additionalProperties = {
type = "integer";
};
properties = {
enable = {
default = false;
description = "Whether to enable enable this.";
examples = [ true ];
type = "boolean";
};
};
type = "object";
};
};
testLazyAttrsOfInt = testLazyAttrsOfInt =
let let
default = { default = {
@@ -264,230 +228,230 @@ in
}; };
}; };
# testNullOrBool = testNullOrBool =
# let let
# default = null; # null is a valid value for this type default = null; # null is a valid value for this type
# in in
# { {
# expr = slib.parseOption (evalType (lib.types.nullOr lib.types.bool) default); expr = slib.parseOption (evalType (lib.types.nullOr lib.types.bool) default);
# expected = { expected = {
# oneOf = [ oneOf = [
# { type = "null"; } { type = "null"; }
# { type = "boolean"; } { type = "boolean"; }
# ]; ];
# inherit default description; inherit default description;
# }; };
# }; };
# testNullOrNullOr = testNullOrNullOr =
# let let
# default = null; # null is a valid value for this type default = null; # null is a valid value for this type
# in in
# { {
# expr = slib.parseOption (evalType (lib.types.nullOr (lib.types.nullOr lib.types.bool)) default); expr = slib.parseOption (evalType (lib.types.nullOr (lib.types.nullOr lib.types.bool)) default);
# expected = { expected = {
# oneOf = [ oneOf = [
# { type = "null"; } { type = "null"; }
# { {
# oneOf = [ oneOf = [
# { type = "null"; } { type = "null"; }
# { type = "boolean"; } { type = "boolean"; }
# ]; ];
# } }
# ]; ];
# inherit default description; inherit default description;
# }; };
# }; };
# testSubmoduleOption = testSubmoduleOption =
# let let
# subModule = { subModule = {
# options.opt = lib.mkOption { options.opt = lib.mkOption {
# type = lib.types.bool; type = lib.types.bool;
# default = true; default = true;
# inherit description; inherit description;
# }; };
# }; };
# in in
# { {
# expr = slib.parseOption (evalType (lib.types.submodule subModule) { }); expr = slib.parseOption (evalType (lib.types.submodule subModule) { });
# expected = { expected = {
# type = "object"; type = "object";
# additionalProperties = false; additionalProperties = false;
# description = "Test Description"; description = "Test Description";
# properties = { properties = {
# opt = { opt = {
# type = "boolean"; type = "boolean";
# default = true; default = true;
# inherit description; inherit description;
# }; };
# }; };
# }; };
# }; };
# testSubmoduleOptionWithoutDefault = testSubmoduleOptionWithoutDefault =
# let let
# subModule = { subModule = {
# options.opt = lib.mkOption { options.opt = lib.mkOption {
# type = lib.types.bool; type = lib.types.bool;
# inherit description; inherit description;
# }; };
# }; };
# in in
# { {
# expr = slib.parseOption (evalType (lib.types.submodule subModule) { }); expr = slib.parseOption (evalType (lib.types.submodule subModule) { });
# expected = { expected = {
# type = "object"; type = "object";
# additionalProperties = false; additionalProperties = false;
# description = "Test Description"; description = "Test Description";
# properties = { properties = {
# opt = { opt = {
# type = "boolean"; type = "boolean";
# inherit description; inherit description;
# }; };
# }; };
# required = [ "opt" ]; required = [ "opt" ];
# }; };
# }; };
# testAttrsOfSubmodule = testAttrsOfSubmodule =
# let let
# subModule = { subModule = {
# options.opt = lib.mkOption { options.opt = lib.mkOption {
# type = lib.types.bool; type = lib.types.bool;
# default = true; default = true;
# inherit description; inherit description;
# }; };
# }; };
# default = { default = {
# foo.opt = false; foo.opt = false;
# bar.opt = true; bar.opt = true;
# }; };
# in in
# { {
# expr = slib.parseOption (evalType (lib.types.attrsOf (lib.types.submodule subModule)) default); expr = slib.parseOption (evalType (lib.types.attrsOf (lib.types.submodule subModule)) default);
# expected = { expected = {
# type = "object"; type = "object";
# additionalProperties = { additionalProperties = {
# type = "object"; type = "object";
# additionalProperties = false; additionalProperties = false;
# properties = { properties = {
# opt = { opt = {
# type = "boolean"; type = "boolean";
# default = true; default = true;
# inherit description; inherit description;
# }; };
# }; };
# }; };
# inherit default description; inherit default description;
# }; };
# }; };
# testListOfSubmodule = testListOfSubmodule =
# let let
# subModule = { subModule = {
# options.opt = lib.mkOption { options.opt = lib.mkOption {
# type = lib.types.bool; type = lib.types.bool;
# default = true; default = true;
# inherit description; inherit description;
# }; };
# }; };
# default = [ default = [
# { opt = false; } { opt = false; }
# { opt = true; } { opt = true; }
# ]; ];
# in in
# { {
# expr = slib.parseOption (evalType (lib.types.listOf (lib.types.submodule subModule)) default); expr = slib.parseOption (evalType (lib.types.listOf (lib.types.submodule subModule)) default);
# expected = { expected = {
# type = "array"; type = "array";
# items = { items = {
# type = "object"; type = "object";
# additionalProperties = false; additionalProperties = false;
# properties = { properties = {
# opt = { opt = {
# type = "boolean"; type = "boolean";
# default = true; default = true;
# inherit description; inherit description;
# }; };
# }; };
# }; };
# inherit default description; inherit default description;
# }; };
# }; };
# testEither = testEither =
# let let
# default = "foo"; default = "foo";
# in in
# { {
# expr = slib.parseOption (evalType (lib.types.either lib.types.bool lib.types.str) default); expr = slib.parseOption (evalType (lib.types.either lib.types.bool lib.types.str) default);
# expected = { expected = {
# oneOf = [ oneOf = [
# { type = "boolean"; } { type = "boolean"; }
# { type = "string"; } { type = "string"; }
# ]; ];
# inherit default description; inherit default description;
# }; };
# }; };
# testAnything = testAnything =
# let let
# default = "foo"; default = "foo";
# in in
# { {
# expr = slib.parseOption (evalType lib.types.anything default); expr = slib.parseOption (evalType lib.types.anything default);
# expected = { expected = {
# inherit default description; inherit default description;
# type = [ type = [
# "boolean" "boolean"
# "integer" "integer"
# "number" "number"
# "string" "string"
# "array" "array"
# "object" "object"
# "null" "null"
# ]; ];
# }; };
# }; };
# testUnspecified = testUnspecified =
# let let
# default = "foo"; default = "foo";
# in in
# { {
# expr = slib.parseOption (evalType lib.types.unspecified default); expr = slib.parseOption (evalType lib.types.unspecified default);
# expected = { expected = {
# inherit default description; inherit default description;
# type = [ type = [
# "boolean" "boolean"
# "integer" "integer"
# "number" "number"
# "string" "string"
# "array" "array"
# "object" "object"
# "null" "null"
# ]; ];
# }; };
# }; };
# testRaw = testRaw =
# let let
# default = "foo"; default = "foo";
# in in
# { {
# expr = slib.parseOption (evalType lib.types.raw default); expr = slib.parseOption (evalType lib.types.raw default);
# expected = { expected = {
# inherit default description; inherit default description;
# type = [ type = [
# "boolean" "boolean"
# "integer" "integer"
# "number" "number"
# "string" "string"
# "array" "array"
# "object" "object"
# "null" "null"
# ]; ];
# }; };
# }; };
} }

View File

@@ -36,4 +36,41 @@
type = "object"; type = "object";
}; };
}; };
testFreeFormOfInt =
let
default = {
foo = 1;
bar = 2;
};
in
{
expr = slib.parseOptions (lib.evalModules {
modules = [
{
freeformType = with lib.types; attrsOf int;
options = {
enable = lib.mkEnableOption "enable this";
};
}
default
];
}).options { };
expected = {
"$schema" = "http://json-schema.org/draft-07/schema#";
additionalProperties = {
type = "integer";
};
properties = {
enable = {
default = false;
description = "Whether to enable enable this.";
examples = [ true ];
type = "boolean";
};
};
type = "object";
};
};
} }