From afaadce28f542c2bdb5bd9a3c9d120c246458881 Mon Sep 17 00:00:00 2001 From: Yonghee Kim Date: Tue, 25 Jun 2024 10:36:44 +0000 Subject: [PATCH] Coverage Report 17e4d9708a95f3e501daf08dd178f3e9d9e95e98 --- docs/coverage/badge_combined.svg | 2 +- docs/coverage/badge_linecoverage.svg | 2 +- .../badge_shieldsio_linecoverage_blue.svg | 2 +- ...dge_shieldsio_linecoverage_brightgreen.svg | 2 +- .../badge_shieldsio_linecoverage_green.svg | 2 +- ...badge_shieldsio_linecoverage_lightgrey.svg | 2 +- .../badge_shieldsio_linecoverage_orange.svg | 2 +- .../badge_shieldsio_linecoverage_red.svg | 2 +- .../badge_shieldsio_linecoverage_yellow.svg | 2 +- ...dge_shieldsio_linecoverage_yellowgreen.svg | 2 +- .../2024-06-25_10-36-43_CoverageHistory.xml | 9 + docs/coverage/index.htm | 46 +- docs/coverage/index.html | 46 +- docs/coverage/lcov.info | 305 +++-- docs/coverage/src_JSONPointer.jl.html | 27 +- docs/coverage/src_dict_interface.jl.html | 1153 +++++++++++++++++ docs/coverage/src_pointer.jl.html | 303 ++--- docs/coverage/src_pointerdict.jl.html | 196 ++- 18 files changed, 1619 insertions(+), 486 deletions(-) create mode 100644 docs/coverage/history/2024-06-25_10-36-43_CoverageHistory.xml create mode 100644 docs/coverage/src_dict_interface.jl.html diff --git a/docs/coverage/badge_combined.svg b/docs/coverage/badge_combined.svg index 25e832d..074ed7a 100644 --- a/docs/coverage/badge_combined.svg +++ b/docs/coverage/badge_combined.svg @@ -96,7 +96,7 @@ Coverage Coverage - 83.1%83.1% + 86.9%86.9% N/AN/A N/AN/A diff --git a/docs/coverage/badge_linecoverage.svg b/docs/coverage/badge_linecoverage.svg index 34d1c5c..dcbde9a 100644 --- a/docs/coverage/badge_linecoverage.svg +++ b/docs/coverage/badge_linecoverage.svg @@ -96,7 +96,7 @@ Coverage Coverage - 83.1%83.1% + 86.9%86.9% diff --git a/docs/coverage/badge_shieldsio_linecoverage_blue.svg b/docs/coverage/badge_shieldsio_linecoverage_blue.svg index 2ca443b..402a8dd 100644 --- a/docs/coverage/badge_shieldsio_linecoverage_blue.svg +++ b/docs/coverage/badge_shieldsio_linecoverage_blue.svg @@ -1 +1 @@ - coveragecoverage83%83% \ No newline at end of file + coveragecoverage86%86% \ No newline at end of file diff --git a/docs/coverage/badge_shieldsio_linecoverage_brightgreen.svg b/docs/coverage/badge_shieldsio_linecoverage_brightgreen.svg index a24f6b0..820332b 100644 --- a/docs/coverage/badge_shieldsio_linecoverage_brightgreen.svg +++ b/docs/coverage/badge_shieldsio_linecoverage_brightgreen.svg @@ -1 +1 @@ - coveragecoverage83%83% \ No newline at end of file + coveragecoverage86%86% \ No newline at end of file diff --git a/docs/coverage/badge_shieldsio_linecoverage_green.svg b/docs/coverage/badge_shieldsio_linecoverage_green.svg index 7a84a54..5029007 100644 --- a/docs/coverage/badge_shieldsio_linecoverage_green.svg +++ b/docs/coverage/badge_shieldsio_linecoverage_green.svg @@ -1 +1 @@ - coveragecoverage83%83% \ No newline at end of file + coveragecoverage86%86% \ No newline at end of file diff --git a/docs/coverage/badge_shieldsio_linecoverage_lightgrey.svg b/docs/coverage/badge_shieldsio_linecoverage_lightgrey.svg index 3874fe5..e86049b 100644 --- a/docs/coverage/badge_shieldsio_linecoverage_lightgrey.svg +++ b/docs/coverage/badge_shieldsio_linecoverage_lightgrey.svg @@ -1 +1 @@ - coveragecoverage83%83% \ No newline at end of file + coveragecoverage86%86% \ No newline at end of file diff --git a/docs/coverage/badge_shieldsio_linecoverage_orange.svg b/docs/coverage/badge_shieldsio_linecoverage_orange.svg index e192f47..f264531 100644 --- a/docs/coverage/badge_shieldsio_linecoverage_orange.svg +++ b/docs/coverage/badge_shieldsio_linecoverage_orange.svg @@ -1 +1 @@ - coveragecoverage83%83% \ No newline at end of file + coveragecoverage86%86% \ No newline at end of file diff --git a/docs/coverage/badge_shieldsio_linecoverage_red.svg b/docs/coverage/badge_shieldsio_linecoverage_red.svg index 54a9f3d..a113b33 100644 --- a/docs/coverage/badge_shieldsio_linecoverage_red.svg +++ b/docs/coverage/badge_shieldsio_linecoverage_red.svg @@ -1 +1 @@ - coveragecoverage83%83% \ No newline at end of file + coveragecoverage86%86% \ No newline at end of file diff --git a/docs/coverage/badge_shieldsio_linecoverage_yellow.svg b/docs/coverage/badge_shieldsio_linecoverage_yellow.svg index e85dd80..aa9d3ec 100644 --- a/docs/coverage/badge_shieldsio_linecoverage_yellow.svg +++ b/docs/coverage/badge_shieldsio_linecoverage_yellow.svg @@ -1 +1 @@ - coveragecoverage83%83% \ No newline at end of file + coveragecoverage86%86% \ No newline at end of file diff --git a/docs/coverage/badge_shieldsio_linecoverage_yellowgreen.svg b/docs/coverage/badge_shieldsio_linecoverage_yellowgreen.svg index 7971e45..a388292 100644 --- a/docs/coverage/badge_shieldsio_linecoverage_yellowgreen.svg +++ b/docs/coverage/badge_shieldsio_linecoverage_yellowgreen.svg @@ -1 +1 @@ - coveragecoverage83%83% \ No newline at end of file + coveragecoverage86%86% \ No newline at end of file diff --git a/docs/coverage/history/2024-06-25_10-36-43_CoverageHistory.xml b/docs/coverage/history/2024-06-25_10-36-43_CoverageHistory.xml new file mode 100644 index 0000000..0d8fdea --- /dev/null +++ b/docs/coverage/history/2024-06-25_10-36-43_CoverageHistory.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/docs/coverage/index.htm b/docs/coverage/index.htm index 09613dd..7aab71c 100644 --- a/docs/coverage/index.htm +++ b/docs/coverage/index.htm @@ -762,15 +762,15 @@

Summary3 +4 Files: -3 +4 Tag: -5_9425395627 +6_9660904350 @@ -779,28 +779,28 @@

Summary
Line coverage
+
@@ -868,15 +868,16 @@

Coverage

Line coverage NameCoveredUncoveredCoverableTotalPercentage -Default1683420246883.1%
  
-
src/JSONPointer.jl10110100%
 
-src/pointer.jl1211113231191.6%
  
-src/pointerdict.jl46236914766.6%
  
+Default1662519151286.9%
  
+src/dict_interface.jl7297077.7%
  
+src/JSONPointer.jl10111100%
 
+src/pointer.jl127813531694%
  
+src/pointerdict.jl31154611567.3%
  
- + @@ -868,15 +868,16 @@

Coverage

Line coverage NameCoveredUncoveredCoverableTotalPercentage -Default1683420246883.1%
  
-src/JSONPointer.jl10110100%
 
-src/pointer.jl1211113231191.6%
  
-src/pointerdict.jl46236914766.6%
  
+Default1662519151286.9%
  
+src/dict_interface.jl7297077.7%
  
+src/JSONPointer.jl10111100%
 
+src/pointer.jl127813531694%
  
+src/pointerdict.jl31154611567.3%
  
- +

File(s)

@@ -853,20 +853,21 @@

src/JSONPointer.jl

- + - + - - - - + + + + +
#LineLine coverage
 31module JSONPointer
 41module JSONPointer
 2
 3using OrderedCollections
 3using OrderedCollections, TypedDelegation
 4
 5include("pointer.jl")
 6include("pointerdict.jl")
 7
 8export @j_str, PointerDict
 9
 10end # module
 7include("dict_interface.jl")
 8
 9export @j_str, PointerDict, has_pointer, get_pointer, set_pointer!
 10
 11end # module
- +

Methods/Properties

diff --git a/docs/coverage/src_dict_interface.jl.html b/docs/coverage/src_dict_interface.jl.html new file mode 100644 index 0000000..f0fa42c --- /dev/null +++ b/docs/coverage/src_dict_interface.jl.html @@ -0,0 +1,1153 @@ + + + + + + + +src/dict_interface.jl - Coverage Report + +
+

< Summary

+
+
+
Information
+
+
+ + + + + + + + + + + + + + + + + +
Class:src/dict_interface.jl
Assembly:Default
File(s):src/dict_interface.jl
Tag:6_9660904350
+
+
+
+
+
+
+
Line coverage
+
+
77%
+
+ + + + + + + + + + + + + + + + + + + + + +
Covered lines:7
Uncovered lines:2
Coverable lines:9
Total lines:70
Line coverage:77.7%
+
+
+
+
+
Branch coverage
+
+
N/A
+
+ + + + + + + + + + + + + +
Covered branches:0
Total branches:0
Branch coverage:N/A
+
+
+
+
+
Method coverage
+
+
+

Method coverage is only available for sponsors.

+Upgrade to PRO version +
+
+
+
+

Coverage History

+
+ +

File(s)

+

src/dict_interface.jl

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#LineLine coverage
 1# Contains interfaces for AbstractDict
 2function has_pointer(dict::AbstractDict, p::Pointer)
 283    _haskey(dict, p)
 4end
 5
 6function get_pointer(dict::AbstractDict, p::Pointer)
 407    _getindex(dict, p)
 8end
 9function get_pointer(dict::AbstractDict, p::Pointer, default)
 210    if has_pointer(dict, p)
 111        return _getindex(dict, p)
 12    end
 113    return default
 14end
 15function set_pointer!(dict::AbstractDict, p::Pointer, value)
 716    _setindex!(dict, value, p)
 17end
 18
 19# Fallback funcctions, When provided key is not JSONPointer
 020set_pointer!(dict::AbstractDict, key, value) = setindex!(dict, value, key)
 021get_pointer(dict::AbstractDict, key, default) = get(dict, key, default)
 24322get_pointer(dict::AbstractDict, key) = getindex(dict, key)
 23
 24
 25
 26"""
 27   @set_pointer(expr)
 28
 29The macro extracts document, key, and value, then constructs an expression to call `set_pointer!` with these arguments, 
 30
 31## Example
 32JSONPointer.@set_pointer doc[key] = value
 33"""
 34macro set_pointer(expr)
 35    # Check if the expression is of the form `doc[key] = value`
 36    if expr.head !== :(=)
 37        error("@set_pointer expects a syntax `doc[key] = value`")
 38    end
 39
 40    # Extract the document, key, and value from the expression
 41    doc_expr = expr.args[1].args[1]
 42    key_expr = expr.args[1].args[2]
 43    value_expr = expr.args[2]
 44
 45    # Construct a new expression that calls `set_pointer!` with the extracted arguments
 46    new_expr = quote
 47        doc = $(esc(doc_expr))
 48        key = $(esc(key_expr))
 49        value = $(esc(value_expr))
 50        set_pointer!(doc, key, value)
 51    end
 52    return new_expr
 53end
 54
 55macro get_pointer(expr)
 56    # Check if the expression is of the form `doc[key]`
 57    if expr.head !== :ref
 58        error("@get_pointer expects a syntax `doc[key]`")
 59    end
 60
 61    doc_expr = expr.args[1]
 62    key_expr = expr.args[2]
 63
 64    new_expr = quote
 65        doc = $(esc(doc_expr))
 66        key = $(esc(key_expr))
 67        get_pointer(doc, key)
 68    end
 69    return new_expr
 70end
+
+
+
+
+

Methods/Properties

+
+
+ + \ No newline at end of file diff --git a/docs/coverage/src_pointer.jl.html b/docs/coverage/src_pointer.jl.html index 51a63f6..f05bf2c 100644 --- a/docs/coverage/src_pointer.jl.html +++ b/docs/coverage/src_pointer.jl.html @@ -766,7 +766,7 @@

< Summary

Tag: -5_9425395627 +6_9660904350
@@ -777,28 +777,28 @@

< Summary

Line coverage
-
91%
+
94%
- + - + - + - + - +
Covered lines:121127
Uncovered lines:118
Coverable lines:132135
Total lines:311316
Line coverage:91.6%94%
@@ -837,14 +837,14 @@

< Summary

Coverage History

-
+

File(s)

@@ -856,7 +856,7 @@

src/pointer.jl

 1const TOKEN_PREFIX = '/'  2  3macro j_str(token) - 1304    Pointer(token) + 1904    Pointer(token)  5end  6  7""" @@ -866,33 +866,33 @@

src/pointer.jl

 11https://tools.ietf.org/html/rfc6901  12"""  13function _unescape_jpath(raw::AbstractString) - 1314    m = match(r"%([0-9A-F]{2})", raw) - 1315    if m !== nothing - 616        for c in m.captures - 1217            raw = replace(raw, "%$(c)" => Char(parse(UInt8, "0x$(c)"))) + 2614    m = match(r"%([0-9A-F]{2})", raw) + 2615    if m !== nothing + 1216        for c in m.captures + 2417            raw = replace(raw, "%$(c)" => Char(parse(UInt8, "0x$(c)")))  18        end  19    end - 1320    return raw + 2620    return raw  21end  22  23function _last_element_to_type!(jk) - 13324    if !occursin("::", jk[end]) - 12225        return Any + 19224    if !occursin("::", jk[end]) + 18025        return Any  26    end - 1127    x = split(jk[end], "::") - 1128    jk[end] = String(x[1]) - 1129    if x[2] == "string" + 1227    x = split(jk[end], "::") + 1228    jk[end] = String(x[1]) + 1229    if x[2] == "string"  130        return String - 1031    elseif x[2] == "number" + 1131    elseif x[2] == "number"  132        return Union{Int, Float64} - 933    elseif x[2] == "object" + 1033    elseif x[2] == "object"  234        return OrderedDict{String, Any} - 735    elseif x[2] == "array" + 835    elseif x[2] == "array"  236        return Vector{Any} - 537    elseif x[2] == "boolean" + 637    elseif x[2] == "boolean"  238        return Bool - 339    elseif x[2] == "null" - 140        return Missing + 439    elseif x[2] == "null" + 240        return Missing  41    else  42        # what is most fitting error type for this?  43 @@ -936,49 +936,49 @@

src/pointer.jl

 81    Pointer("/a/0/c::object"; shift_index = true)  82"""  83struct Pointer{T} - 14184    tokens::Vector{Union{String, Int}} + 20884    tokens::Vector{Union{String, Int}}  85end  86  87function Pointer(token_string::AbstractString; shift_index::Bool = false) - 41888    if startswith(token_string, "#") - 2589        token_string = _unescape_jpath(token_string[2:end]) + 60688    if startswith(token_string, "#") + 5089        token_string = _unescape_jpath(token_string[2:end])  90    end - 14091    if isempty(token_string) - 392        return Pointer{Nothing}([""]) + 20391    if isempty(token_string) + 592        return Pointer{Nothing}([""])  93    end - 27494    if !startswith(token_string, TOKEN_PREFIX) + 39694    if !startswith(token_string, TOKEN_PREFIX)  195        throw(ArgumentError("JSONPointer must starts with '$TOKEN_PREFIX' prefix"))  96    end - 26997    tokens = convert( + 38997    tokens = convert(  98        Vector{Union{String, Int}},  99        String.(split(token_string, TOKEN_PREFIX; keepempty = false)),  100    ) - 136101    if length(tokens) == 0 - 3102        return Pointer{Any}([""]) + 197101    if length(tokens) == 0 + 5102        return Pointer{Any}([""])  103    end - 133104    T = _last_element_to_type!(tokens) - 262105    for (i, token) in enumerate(tokens) - 307106        if occursin(r"^\d+$", token) # index of a array - 73107            tokens[i] = parse(Int, token) - 73108            if shift_index - 3109                tokens[i] += 1 + 192104    T = _last_element_to_type!(tokens) + 380105    for (i, token) in enumerate(tokens) + 402106        if occursin(r"^\d+$", token) # index of a array + 85107            tokens[i] = parse(Int, token) + 85108            if shift_index + 5109                tokens[i] += 1  110            end - 73111            if iszero(tokens[i]) + 85111            if iszero(tokens[i])  2112                throw(BoundsError("Julia uses 1-based indexing, use '1' instead of '0'"))  113            end - 234114        elseif occursin(r"^\\\d+$", token) # literal string for a number + 317114        elseif occursin(r"^\\\d+$", token) # literal string for a number  3115            tokens[i] = String(chop(token; head = 1, tail = 0)) - 231116        elseif occursin("~", token) - 487117            tokens[i] = replace(replace(token, "~0" => "~"), "~1" => "/") + 314116        elseif occursin("~", token) + 622117            tokens[i] = replace(replace(token, "~0" => "~"), "~1" => "/")  118        end  119    end - 129120    return Pointer{T}(tokens) + 188120    return Pointer{T}(tokens)  121end  122 - 92123Base.length(x::Pointer) = length(x.tokens) - 0124Base.eachindex(x::Pointer) = eachindex(x.tokens) + 103123Base.length(x::Pointer) = length(x.tokens) + 1124Base.eachindex(x::Pointer) = eachindex(x.tokens)  125 - 16126Base.eltype(::Pointer{T}) where {T} = T + 26126Base.eltype(::Pointer{T}) where {T} = T  127  0128function Base.show(io::IO, x::Pointer{T}) where {T}  0129    print(io, "JSONPointer{", T, "}(\"/", join(x.tokens, "/"), "\")") @@ -988,23 +988,23 @@

src/pointer.jl

 0133    print(io, "JSONPointer{Nothing}(\"\")")  134end  135 - 7136Base.getindex(A::AbstractArray, p::Pointer) = _getindex(A, p) + 8136Base.getindex(A::AbstractArray, p::Pointer) = _getindex(A, p)  2137Base.haskey(A::AbstractArray, p::Pointer) = _haskey(A, p)  138  139function Base.unique(arr::AbstractArray{<:Pointer, N}) where {N} - 1140    out = deepcopy(arr) - 1141    if isempty(arr) - 0142        return out + 3140    out = deepcopy(arr) + 3141    if isempty(arr) + 1142        return out  143    end - 2144    pointers = getfield.(arr, :tokens) - 1145    if allunique(pointers) - 0146        return out + 4144    pointers = getfield.(arr, :tokens) + 2145    if allunique(pointers) + 1146        return out  147    end  1148    delete_target = Int[]  1149    for p in pointers - 3150        indicies = findall(el -> el == p, pointers) - 3151        if length(indicies) > 1 - 3152            append!(delete_target, indicies[1:end-1]) + 6150        indicies = findall(el -> el == p, pointers) + 6151        if length(indicies) > 1 + 5152            append!(delete_target, indicies[1:end-1])  153        end  154    end  1155    deleteat!(out, unique(delete_target)) @@ -1015,9 +1015,9 @@

src/pointer.jl

 160  161# ==============================================================================  162 - 44163_checked_get(collection::AbstractArray, token::Int) = collection[token] + 56163_checked_get(collection::AbstractArray, token::Int) = collection[token]  164 - 162165_checked_get(collection::AbstractDict, token::String) = collection[token] + 243165_checked_get(collection::AbstractDict, token::String) = get_pointer(collection, token)  166  167function _checked_get(collection, token)  1168    throw(ArgumentError( @@ -1028,48 +1028,48 @@

src/pointer.jl

 173  174# ==============================================================================  175 - 1176_haskey(::Any, ::Pointer{Nothing}) = true + 2176_haskey(::Any, ::Pointer{Nothing}) = true  177  178function _haskey(collection, p::Pointer) - 27179    for token in p.tokens - 140180        if !_haskey(collection, token) - 9181            return false + 54179    for token in p.tokens + 236180        if !_haskey(collection, token) + 16181            return false  182        end - 80183        collection = _checked_get(collection, token) + 144183        collection = _checked_get(collection, token)  184    end - 18185    return true + 38185    return true  186end  187 - 60188_haskey(collection::AbstractDict, token::String) = haskey(collection, token) + 106188_haskey(collection::AbstractDict, token::String) = haskey(collection, token)  189  190function _haskey(collection::AbstractArray, token::Int) - 11191    return 1 <= token <= length(collection) + 16191    return 1 <= token <= length(collection)  192end  193  0194_haskey(::Any, ::Any) = false  195  196# ==============================================================================  197 - 2198_getindex(collection, ::Pointer{Nothing}) = collection + 4198_getindex(collection, ::Pointer{Nothing}) = collection  199  200function _getindex(collection, p::Pointer) - 62201    return _getindex(collection, p.tokens) + 101201    return _getindex(collection, p.tokens)  202end  203  204function _getindex(collection, tokens::Vector{Union{String, Int}}) - 62205    for token in tokens - 202206        collection = _checked_get(collection, token) + 101205    for token in tokens + 285206        collection = _checked_get(collection, token)  207    end - 57208    return collection + 91208    return collection  209end  210  211# ==============================================================================  212  213function _get(collection, p::Pointer, default)  3214    if _haskey(collection, p) - 1215        return _getindex(collection, p) + 0215        return _getindex(collection, p)  216    end - 2217    return default + 3217    return default  218end  219function _get!(collection, p::Pointer, default)  3220    if _haskey(collection, p) @@ -1082,92 +1082,97 @@

src/pointer.jl

 227  228# ==============================================================================  229 - 5230_null_value(p::Pointer) = _null_value(eltype(p)) + 6230_null_value(p::Pointer) = _null_value(eltype(p))  1231_null_value(::Type{String}) = "" - 1232_null_value(::Type{<:Real}) = 0 + 3232_null_value(::Type{<:Real}) = 0  1233_null_value(::Type{<:AbstractDict}) = OrderedDict{String, Any}()  1234_null_value(::Type{<:AbstractVector{T}}) where {T} = T[]  1235_null_value(::Type{Bool}) = false  0236_null_value(::Type{Nothing}) = nothing - 0237_null_value(::Type{Missing}) = missing + 1237_null_value(::Type{Missing}) = missing  238 - 43239_null_value(::Type{Any}) = missing + 47239_null_value(::Type{Any}) = missing  240 - 32241_convert_v(v::U, ::Pointer{U}) where {U} = v + 38241_convert_v(v::U, ::Pointer{U}) where {U} = v  242function _convert_v(v::V, p::Pointer{U}) where {U, V}  8243    v = ismissing(v) ? _null_value(p) : v  8244    try - 8245        return convert(eltype(p), v)246    catch - 2247        throw(ArgumentError(248            "$(v)::$(typeof(v)) is not valid type for $(p). Remove type " *249            "assertion in the JSON pointer if you don't a need static type."250        ))251    end252end253254function _add_element_if_needed(prev::AbstractVector{T}, k::Int) where {T} - 25255    x = k - length(prev) - 25256    if x > 0 - 24257        append!(prev, [_null_value(T) for _ = 1:x])258    end - 25259    return260end261262function _add_element_if_needed(263    prev::AbstractDict{K, V}, k::String264) where {K, V} - 67265    if !haskey(prev, k) - 43266        prev[k] = _null_value(V)267    end268end269270function _add_element_if_needed(collection, token) - 3271    throw(ArgumentError(272        "JSON pointer does not match the data-structure. I tried (and " *273        "failed) to set $(collection) at the index: $(token)"274    ))275end276 - 11277_new_data(::Any, n::Int) = Vector{Any}(missing, n) - 4278_new_data(::AbstractVector, ::String) = OrderedDict{String, Any}()279function _new_data(x::T, ::String) where T <: AbstractDict - 13280    OrderedDict{String, Any}()245        #Conversion to OrderedDict is deprecated for unordered associative containers. Need to be sorted before the conv + 8246        if eltype(p) <: OrderedDict + 2247            if <:(V, OrderedDict) == false + 2248                return convert(eltype(p), sort!(OrderedDict(v)))249            end250        end + 6251        return convert(eltype(p), v)252    catch + 2253        throw(ArgumentError(254            "$(v)::$(typeof(v)) is not valid type for $(p). Remove type " *255            "assertion in the JSON pointer if you don't a need static type."256        ))257    end258end259260function _add_element_if_needed(prev::AbstractVector{T}, k::Int) where {T} + 27261    x = k - length(prev) + 27262    if x > 0 + 24263        append!(prev, [_null_value(T) for _ = 1:x])264    end + 27265    return266end267268function _add_element_if_needed(269    prev::AbstractDict{K, V}, k::String270) where {K, V} + 75271    if !haskey(prev, k) + 51272        prev[k] = _null_value(V)273    end274end275276function _add_element_if_needed(collection, token) + 3277    throw(ArgumentError(278        "JSON pointer does not match the data-structure. I tried (and " *279        "failed) to set $(collection) at the index: $(token)"280    ))  281end  282283284function _setindex!(collection::AbstractDict, v, p::Pointer) - 43285    prev = collection - 86286    for (i, token) in enumerate(p.tokens) - 95287        _add_element_if_needed(prev, token) - 92288        if i != length(p) - 76289            if ismissing(prev[token]) - 28290                prev[token] = _new_data(prev, p.tokens[i + 1])291            end - 104292            prev = prev[token]293        end294    end - 40295    prev[p.tokens[end]] = _convert_v(v, p) - 38296    return v297end298299# pointer manipulation functions300function Base.append!(p::Pointer, token::Union{String, Int}) - 4301    push!(p.tokens, token) - 4302    return p303end304function Base.deleteat!(p::Pointer, index::Int) - 4305    deleteat!(p.tokens, index) - 4306    return p307end308function Base.pop!(p::Pointer) - 4309    pop!(p.tokens) - 4310    return p311end + 13283_new_data(::Any, n::Int) = Vector{Any}(missing, n) + 6284_new_data(::AbstractVector, ::String) = OrderedDict{String, Any}()285function _new_data(x::T, ::String) where T <: AbstractDict + 13286    OrderedDict{String, Any}()287end288289function _setindex!(collection::AbstractDict, v, p::Pointer) + 49290    prev = collection + 98291    for (i, token) in enumerate(p.tokens) + 107292        _add_element_if_needed(prev, token) + 102293        if i < length(p) + 80294            if ismissing(prev[token]) + 32295                prev[token] = _new_data(prev, p.tokens[i + 1])296            end + 112297            prev = prev[token]298        end299    end + 48300    prev[p.tokens[end]] = _convert_v(v, p) + 44301    return v302end303304# pointer manipulation functions305function Base.append!(p::Pointer, token::Union{String, Int}) + 4306    push!(p.tokens, token) + 4307    return p308end309function Base.deleteat!(p::Pointer, index::Int) + 4310    deleteat!(p.tokens, index) + 4311    return p312end313function Base.pop!(p::Pointer) + 4314    pop!(p.tokens) + 4315    return p316end
- +

Methods/Properties

diff --git a/docs/coverage/src_pointerdict.jl.html b/docs/coverage/src_pointerdict.jl.html index 679ebf0..0930d19 100644 --- a/docs/coverage/src_pointerdict.jl.html +++ b/docs/coverage/src_pointerdict.jl.html @@ -766,7 +766,7 @@

< Summary

Tag: -5_9425395627 +6_9660904350
@@ -777,28 +777,28 @@

< Summary

Line coverage
-
66%
+
67%
- + - + - + - + - +
Covered lines:4631
Uncovered lines:2315
Coverable lines:6946
Total lines:147115
Line coverage:66.6%67.3%
@@ -837,14 +837,14 @@

< Summary

Coverage History

-
+

File(s)

@@ -879,15 +879,15 @@

src/pointerdict.jl

 124        PointerDict(dict)  25    end  26    function PointerDict(args...) - 1727        d = OrderedDict{String, Any}() - 1728        for (k, v) in args - 5929            if isa(k, Pointer) - 3230                _setindex!(d, v, k) + 1427        d = OrderedDict{String, Any}() + 1428        for (k, v) in args + 3829            if isa(k, Pointer) + 3130                _setindex!(d, v, k)  31            else - 7532                setindex!(d, v, k) + 5132                setindex!(d, v, k)  33            end  34        end - 1735        PointerDict(d) + 1435        PointerDict(d)  36    end  37    # PointerDict(; kwargs...) = PointerDict(values(kwargs))  38end @@ -898,112 +898,80 @@

src/pointerdict.jl

 043Base.IteratorSize(@nospecialize T::Type{<:PointerDict}) = Base.IteratorSize(fieldtype(T, :d))  044Base.IteratorEltype(@nospecialize T::Type{<:PointerDict}) = Base.IteratorEltype(eltype(T))  45 - 1046Base.length(pd::PointerDict) = length(getfield(pd, :d))47function Base.sizehint!(pd::PointerDict, n::Integer) - 148    sizehint!(getfield(pd, :d), n) - 149    return pd50end51 - 152Base.keytype(@nospecialize T::Type{<:PointerDict{String}}) = String - 053Base.keytype(@nospecialize T::Type{<:PointerDict{Symbol}}) = Symbol54 - 155Base.pop!(pd::PointerDict, k) = pop!(getfield(pd, :d),  k) - 156Base.pop!(pd::PointerDict, k, d) = pop!(getfield(pd, :d), k, d)5758function Base.empty!(pd::PointerDict) - 159    empty!(getfield(pd, :d)) - 160    return pd61end - 062Base.isempty(pd::PointerDict) = isempty(getfield(pd, :d))63function Base.empty(pd::PointerDict, ::Type{K}=keytype(pd), ::Type{V}=valtype(pd)) where {K,V} - 264    PointerDict(empty(getfield(pd, :d), K, V)) + 146Base.keytype(@nospecialize T::Type{<:PointerDict{String}}) = String + 047Base.keytype(@nospecialize T::Type{<:PointerDict{Symbol}}) = Symbol4849function Base.empty(pd::PointerDict, ::Type{K}=keytype(pd), ::Type{V}=valtype(pd)) where {K,V} + 250    PointerDict(empty(getfield(pd, :d), K, V))51end5253# Simply delegated dictionary functions to the wrapped PointerDdicct object54# NOTE: push! is not included below, because the fallback version just55#       calls setindex!56@delegate_onefield(PointerDict, d, [ Base.getindex, Base.get, Base.get!, Base.haskey,57Base.getkey, Base.pop!, Base.iterate,58Base.isempty, Base.length, Base.delete!, Base.setindex!])59# Base.copy(pd::PointerDict) = PointerDict(copy(getfield(pd, :d)))6061# empty! returns the wrapped dictionary if simply delegated62function Base.empty!(pd::PointerDict) + 163    empty!(getfield(pd, :d)) + 164    return pd  65end  6667function Base.delete!(pd::PointerDict, k) - 168    delete!(getfield(pd, :d), k) - 169    return pd6768function Base.get(pd::PointerDict, jk::Pointer, d) + 369    _get(getfield(pd, :d), jk, d)  70end7172function Base.get(pd::PointerDict, k, d) - 2973    get(getfield(pd, :d), k, d)74end75function Base.get(pd::PointerDict, jk::Pointer, d) - 376    _get(getfield(pd, :d), jk, d) + 071function Base.get(f::Base.Callable, pd::PointerDict, jp::Pointer) + 072    _get(f, getfield(pd, :d), jp)73end7475function Base.get!(pd::PointerDict, jp::Pointer, d) + 376    _get!(getfield(pd, :d), jp, d)  77end - 078function Base.get(f::Base.Callable, pd::PointerDict, k) - 079    get(f, getfield(pd, :d), k) + 078function Base.get!(f::Base.Callable, pd::PointerDict, jp::Pointer) + 079    _get!(f, getfield(pd, :d), jp)  80end - 081function Base.get(f::Base.Callable, pd::PointerDict, jp::Pointer) - 082    _get(f, getfield(pd, :d), jp)83end8485function Base.get!(pd::PointerDict, k, d) - 186    get!(getfield(pd, :d), k, d)87end88function Base.get!(pd::PointerDict, jp::Pointer, d) - 389    _get!(getfield(pd, :d), jp, d)90end - 091function Base.get!(f::Base.Callable, pd::PointerDict, k) - 092    get!(f, getfield(pd, :d), pd, k)93end - 094function Base.get!(f::Base.Callable, pd::PointerDict, jp::Pointer) - 095    _get!(f, getfield(pd, :d), jp)96end9798function Base.getindex(pd::PointerDict, k) - 1499    getindex(getfield(pd, :d), k)100end101function Base.getindex(pd::PointerDict, jp::Pointer) - 56102    _getindex(getfield(pd, :d), jp)8182function Base.getindex(pd::PointerDict, jp::Pointer) + 5683    _getindex(getfield(pd, :d), jp)84end8586function Base.setindex!(pd::PointerDict, v, jp::Pointer) + 887    _setindex!(getfield(pd, :d), v, jp)88end + 2089Base.haskey(pd::PointerDict, jp::Pointer) = _haskey(getfield(pd, :d), jp) + 090Base.getkey(pd::PointerDict, jp::Pointer, d) = getkey(getfield(pd, :d), jp, d)9192## merge and mergewith + 093Base.merge(pd::PointerDict) = copy(pd)9495function Base.merge(pd::PointerDict, pds::PointerDict...) + 296    K = _promote_keytypes((pd, pds...)) + 297    V = _promote_valtypes(valtype(pd), pds...) + 298    out = PointerDict(Dict{K,V}()) + 299    for (k,v) in pd + 6100        out[k] = v101    end + 2102    merge!(recursive_merge, out, pds...)  103end104function Base.setindex!(pd::PointerDict, v, k) - 14105    setindex!(getfield(pd, :d), v, k)106end107function Base.setindex!(pd::PointerDict, v, jp::Pointer) - 8108    _setindex!(getfield(pd, :d), v, jp)109end110 - 11111Base.iterate(pd::PointerDict) = iterate(getfield(pd, :d)) - 24112Base.iterate(pd::PointerDict, i) = iterate(getfield(pd, :d), i)113 - 0114Base.values(pd::PointerDict) = values(getfield(pd, :d))115 - 9116Base.haskey(pd::PointerDict, k) = haskey(getfield(pd, :d), k) - 20117Base.haskey(pd::PointerDict, jp::Pointer) = _haskey(getfield(pd, :d), jp) - 1118Base.getkey(pd::PointerDict, k, d) = getkey(getfield(pd, :d), k, d) - 0119Base.getkey(pd::PointerDict, jp::Pointer, d) = getkey(getfield(pd, :d), jp, d) - 0120Base.keys(pd::PointerDict) = keys(getfield(pd, :d))121 - 0122Base.copy(pd::PointerDict) = PointerDict(copy(getfield(pd, :d)))123124## merge and mergewith - 0125Base.merge(pd::PointerDict) = copy(pd)126127function Base.merge(pd::PointerDict, pds::PointerDict...) - 2128    K = _promote_keytypes((pd, pds...)) - 2129    V = _promote_valtypes(valtype(pd), pds...) - 2130    out = PointerDict(Dict{K,V}()) - 2131    for (k,v) in pd - 6132        out[k] = v133    end - 2134    merge!(recursive_merge, out, pds...)135end136 - 3137recursive_merge(x::AbstractDict...) = merge(recursive_merge, x...) - 2138recursive_merge(x::AbstractVector...) = cat(x...; dims=1) - 0139recursive_merge(x...) = x[end]140141# fall back to String if we don't clearly have Symbol - 0142_promote_keytypes(@nospecialize(pds::Tuple{Vararg{PointerDict{Symbol, T}}})) where T = Symbol - 2143_promote_keytypes(@nospecialize(pds::Tuple{Vararg{PointerDict}})) = String - 0144_promote_valtypes(V) = V145function _promote_valtypes(V, d, ds...)  # give up if promoted to any - 2146    V === Any ? Any : _promote_valtypes(promote_type(V, valtype(d)), ds...)147end104 + 3105recursive_merge(x::AbstractDict...) = merge(recursive_merge, x...) + 2106recursive_merge(x::AbstractVector...) = cat(x...; dims=1) + 0107recursive_merge(x...) = x[end]108109# fall back to String if we don't clearly have Symbol + 0110_promote_keytypes(@nospecialize(pds::Tuple{Vararg{PointerDict{Symbol, T}}})) where T = Symbol + 2111_promote_keytypes(@nospecialize(pds::Tuple{Vararg{PointerDict}})) = String + 0112_promote_valtypes(V) = V113function _promote_valtypes(V, d, ds...)  # give up if promoted to any + 2114    V === Any ? Any : _promote_valtypes(promote_type(V, valtype(d)), ds...)115end
- +

Methods/Properties