Skip to content

Commit

Permalink
Unit test and fix generic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
neelsmith committed Sep 15, 2021
1 parent 2f5cc84 commit 9d6619c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
5 changes: 3 additions & 2 deletions src/CitableBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module CitableBase
using Documenter, DocStringExtensions

# Urn and its required functions:
export Urn
export components, parts, validurn
export Urn
export dropversion, addversion
# Concrete implementations:
export components, parts

# Citable and its required functions
export Citable
Expand Down
23 changes: 8 additions & 15 deletions src/citable.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@

"Unique identifiers expressible in the syntax of the IETF's URN specification."
abstract type Urn end
# Classes extending the URN abstractions MUST
# have a member of type AbstractString named "urn":



"A citable unit of any kind is identified by a URN and has a human-readable label."
abstract type Citable end

"""Citable content should always be serializable.
"""
function cex(data::T, delim="|") where {T <: Citable}
@warn("No cex function defined for ", typeof(data))
end
function cex end

function objectid(data::T) where {T <: Citable}
@warn("No cex function defined for ", typeof(data))
nothing
end
"""Citable content has a label.
"""
function label end

"""Citable content is identified by a URN.
"""
function urn end
3 changes: 1 addition & 2 deletions src/urns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ $(SIGNATURES)
Splits a URN's string representation into top-level components.
"""
function components(u::Urn)
split(u.urn, ":")
split(string(u), ":")
end


"""
$(SIGNATURES)
Splits a string on periods (seprator for parts within components of URNs).
Expand Down
2 changes: 0 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using CitableBase
using Test


include("test_urnimpl.jl")
include("test_urnmanipulation.jl")
include("test_citeimpl.jl")
include("test_cex.jl")
12 changes: 0 additions & 12 deletions test/test_cex.jl

This file was deleted.

19 changes: 18 additions & 1 deletion test/test_citeimpl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,21 @@
@test urn(c) == u
@test label(c) == "label"
@test cex(c) == "urn:fake:id.subid|label"
end

end

@testset "Test incomplete implementation of Citable" begin
struct PretendCitable <: Citable
col1
col2
end
function cex(pc::PretendCitable, delim="|")
join([pc.col1, pc.col2], delim)
end
pc = PretendCitable("x", "y")
@test cex(pc) == "x|y"
@test cex(pc, "#") == "x#y"
@test_throws MethodError urn(pc)
@test_throws MethodError label(pc)
end

0 comments on commit 9d6619c

Please sign in to comment.