< Summary

Information
Class: src/abstractdict_interface.jl
Assembly: Default
File(s): src/abstractdict_interface.jl
Tag: 7_9662997695
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 70
Line coverage: 100%
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/abstractdict_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
 120set_pointer!(dict::AbstractDict, key, value) = setindex!(dict, value, key)
 321get_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