lib.gvariant: fix rendering of empty non-string arrays
Before, empty arrays would always be rendered as an empty string array.
This commit is contained in:
parent
a3d691c053
commit
a965b097b1
|
@ -71,6 +71,8 @@ in rec {
|
||||||
|
|
||||||
inherit type typeOf;
|
inherit type typeOf;
|
||||||
|
|
||||||
|
isGVariant = v: v._type or "" == "gvariant";
|
||||||
|
|
||||||
isArray = hasPrefix "a";
|
isArray = hasPrefix "a";
|
||||||
isMaybe = hasPrefix "m";
|
isMaybe = hasPrefix "m";
|
||||||
isTuple = hasPrefix "(";
|
isTuple = hasPrefix "(";
|
||||||
|
|
|
@ -70,7 +70,11 @@ in rec {
|
||||||
check = v: gvar.mkValue v != null;
|
check = v: gvar.mkValue v != null;
|
||||||
merge = loc: defs:
|
merge = loc: defs:
|
||||||
let
|
let
|
||||||
vdefs = map (d: d // { value = gvar.mkValue d.value; }) defs;
|
vdefs = map (d:
|
||||||
|
d // {
|
||||||
|
value =
|
||||||
|
if gvar.isGVariant d.value then d.value else gvar.mkValue d.value;
|
||||||
|
}) defs;
|
||||||
vals = map (d: d.value) vdefs;
|
vals = map (d: d.value) vdefs;
|
||||||
defTypes = map (x: x.type) vals;
|
defTypes = map (x: x.type) vals;
|
||||||
sameOrNull = x: y: if x == y then y else null;
|
sameOrNull = x: y: if x == y then y else null;
|
||||||
|
@ -82,8 +86,10 @@ in rec {
|
||||||
+ " mismatched GVariant types given in"
|
+ " mismatched GVariant types given in"
|
||||||
+ " ${showFiles (getFiles defs)}.")
|
+ " ${showFiles (getFiles defs)}.")
|
||||||
else if gvar.isArray sharedDefType && allChecked then
|
else if gvar.isArray sharedDefType && allChecked then
|
||||||
(types.listOf gvariant).merge loc
|
gvar.mkValue ((types.listOf gvariant).merge loc
|
||||||
(map (d: d // { value = d.value.value; }) vdefs)
|
(map (d: d // { value = d.value.value; }) vdefs)) // {
|
||||||
|
type = sharedDefType;
|
||||||
|
}
|
||||||
else if gvar.isTuple sharedDefType && allChecked then
|
else if gvar.isTuple sharedDefType && allChecked then
|
||||||
mergeOneOption loc defs
|
mergeOneOption loc defs
|
||||||
else if gvar.isMaybe sharedDefType && allChecked then
|
else if gvar.isMaybe sharedDefType && allChecked then
|
||||||
|
|
|
@ -33,8 +33,10 @@ in {
|
||||||
{ uint64 = mkUint64 42; }
|
{ uint64 = mkUint64 42; }
|
||||||
{ uint64 = mkUint64 42; }
|
{ uint64 = mkUint64 42; }
|
||||||
|
|
||||||
{ list = [ "one" ]; }
|
{ array1 = [ "one" ]; }
|
||||||
{ list = mkArray type.string [ "two" ]; }
|
{ array1 = mkArray type.string [ "two" ]; }
|
||||||
|
{ array2 = mkArray type.uint32 [ 1 ]; }
|
||||||
|
{ array2 = mkArray type.uint32 [ 2 ]; }
|
||||||
|
|
||||||
{ emptyArray1 = [ ]; }
|
{ emptyArray1 = [ ]; }
|
||||||
{ emptyArray2 = mkEmptyArray type.uint32; }
|
{ emptyArray2 = mkEmptyArray type.uint32; }
|
||||||
|
@ -63,15 +65,16 @@ in {
|
||||||
home-files/result.txt \
|
home-files/result.txt \
|
||||||
${
|
${
|
||||||
pkgs.writeText "expected.txt" ''
|
pkgs.writeText "expected.txt" ''
|
||||||
|
array1 = @as ['one','two']
|
||||||
|
array2 = @au [1,2]
|
||||||
bool = true
|
bool = true
|
||||||
emptyArray1 = @as []
|
emptyArray1 = @as []
|
||||||
emptyArray2 = @as []
|
emptyArray2 = @au []
|
||||||
escapedString = '\'\\\n'
|
escapedString = '\'\\\n'
|
||||||
float = 3.140000
|
float = 3.140000
|
||||||
int = -42
|
int = -42
|
||||||
int16 = @n -42
|
int16 = @n -42
|
||||||
int64 = @x -42
|
int64 = @x -42
|
||||||
list = @as ['one','two']
|
|
||||||
maybe1 = @ms nothing
|
maybe1 = @ms nothing
|
||||||
maybe2 = just @u 4
|
maybe2 = just @u 4
|
||||||
string = 'foo'
|
string = 'foo'
|
||||||
|
|
Loading…
Reference in a new issue