Skip to content

Commit

Permalink
Add get(mmcif, key, default) method for MMCIFDict. (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcom authored Sep 27, 2020
1 parent e58f6c1 commit e25b969
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/mmcif.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ end
Base.keys(mmcif_dict::MMCIFDict) = keys(mmcif_dict.dict)
Base.values(mmcif_dict::MMCIFDict) = values(mmcif_dict.dict)
Base.haskey(mmcif_dict::MMCIFDict, key) = haskey(mmcif_dict.dict, key)
Base.get(mmcif_dict::MMCIFDict, key, default) = get(mmcif_dict.dict, key, default)

function Base.show(io::IO, mmcif_dict::MMCIFDict)
print(io, "mmCIF dictionary with $(length(keys(mmcif_dict))) fields")
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,9 @@ end
@test length(values(dic)) == 610
@test haskey(dic, "_cell.entry_id")
@test !haskey(dic, "nokey")
@test get(dic, "_cell.entry_id", ["default"]) == ["1AKE"]
@test get(dic, "nokey", ["default"]) == ["default"]
@test ismissing(get(dic, "nokey", missing))
show(devnull, dic)

multiline_str = """
Expand Down

0 comments on commit e25b969

Please sign in to comment.