Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/card.jl
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ end
function formatcard(::Type{Value{V}}, value::V, comment::C; kwds...) where
{V <: ValueType, C <: AbstractString}

units = unit(value) === NoUnits ? missing : string(unit(value))
# An undefined value has no units: `unit(missing)` is `missing`, not `NoUnits`.
units = ismissing(value) || unit(value) === NoUnits ? missing : string(unit(value))
# Create appropriate CardFormat type
format = CardFormat(kwds[:fixed])
fmt = string(ustrip(value))
Expand Down
22 changes: 22 additions & 0 deletions test/card_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,28 @@
# create Value Card and get its type with boolean value
@test typeof(Card("BOOL", true)) <: Card{Value{Bool}}

# create Value card with undefined value
@test isequal(showfields(Card("UNDEF", missing)),
("UNDEF", missing, "",
"UNDEF = "))

# create Value card with undefined value and comment. An undefined value has no
# units, so no units field is written.
@test isequal(showfields(Card("UNDEF", missing, "a comment")),
("UNDEF", missing, "a comment",
"UNDEF = / a comment "))

# an undefined value card round trips through its image
@test isequal(showfields(parse(Card,
"UNDEF = / a comment ")),
("UNDEF", missing, "a comment",
"UNDEF = / a comment "))

# a units string in the comment of an undefined value card is preserved
@test isequal(showfields(Card("UNDEF", missing, "[m] a comment")),
("UNDEF", missing, "[m] a comment",
"UNDEF = / [m] a comment "))

# create Value card with boolean value, fixed-format
@test isequal(showfields(Card("BOOL", false)),
("BOOL", false, "",
Expand Down
Loading