From 4fa3c521ce44ebfc968d1cdf01597992d421c230 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Mon, 17 Jun 2019 17:30:03 +0200 Subject: [PATCH] add propertynames --- src/ProtoStruct.jl | 8 ++++++-- test/test_ProtoStruct.jl | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ProtoStruct.jl b/src/ProtoStruct.jl index 8934dda..930c1d7 100644 --- a/src/ProtoStruct.jl +++ b/src/ProtoStruct.jl @@ -1,13 +1,17 @@ macro proto( name ) ex = quote - struct $name{ NT<:NamedTuple{Syms,T} where {Syms,T} } + struct $name{NT<:NamedTuple} properties::NT end # struct $name(;kwargs...) = $name(kwargs.data) function Base.getproperty( o::$name, s::Symbol ) - return getproperty( getfield(o,:properties), s ) + return getproperty( getfield(o, :properties), s ) + end # function + + function Base.propertynames( o::$name ) + return propertynames( getfield(o, :properties) ) end # function end # quote esc(ex) diff --git a/test/test_ProtoStruct.jl b/test/test_ProtoStruct.jl index 4306d4e..f11c46f 100644 --- a/test/test_ProtoStruct.jl +++ b/test/test_ProtoStruct.jl @@ -13,3 +13,7 @@ end # testset @test test_me.B == "2" @test test_me.C == complex(1) end # testset + +@testset "Properties" begin + @test propertynames( test_me ) == (:A, :B, :C) +end # testset