more tests and fixes

This commit is contained in:
Steven G. Johnson 2017-08-01 17:04:18 -04:00
parent 457f4104d4
commit e6c0702811
4 changed files with 10 additions and 3 deletions

View File

@ -2,7 +2,7 @@ module BibTeX
export Bibliography, Citation
include("parser.jl")
include("bibitem.jl")
include("bib.jl")
include("citation.jl")
include("bibliography.jl")
end

View File

@ -18,7 +18,7 @@ function Citation!(data::Dict{String,String})
end
Base.similar(b::Citation{S}) where {S} = Citation{S}(Dict{String,String}())
Base.rehash!(b::Citation, n=length(b.data)) = begin rehash!(b.data, n); b; end
Base.rehash!(b::Citation, n=length(b.data)) = begin Base.rehash!(b.data, n); b; end
Base.sizehint!(b::Citation, n) = begin sizehint!(b.data, n); b; end
Base.empty!(b::Citation) = begin empty!(b.data); b; end
Base.copy(b::Citation{S}) where {S} = Citation{S}(copy(b.data))

View File

@ -31,12 +31,19 @@ end
Base.rehash!(b)
b2 = copy(b)
@test length(b2) == length(b)
@test isempty(sizehint!(empty!(b2),10))
@test isempty(similar(b))
b2["x"] = Citation{:foo}()
b2["x"]["bar"] = "blah"
@test length(b2) == length(b2["x"]) == 1
@test b2["x"]["bar"] == "blah"
@test get(b2["x"], "foo", nothing) === nothing
@test collect(b2)[1][2] == b2["x"]
@test collect(b2["x"])[1] == ("bar"=>"blah")
Base.rehash!(b2["x"])
x2 = copy(b2["x"])::Citation{:foo}
@test length(x2) == 1
@test isempty(similar(x2))
@test isempty(sizehint!(empty!(x2),10))
end