@@ -5,18 +5,21 @@ import ClimaCore.MatrixFields: @name, is_subset_that_covers_set
5
5
6
6
include (" matrix_field_test_utils.jl" )
7
7
8
- struct Foo {T}
8
+ struct FooFieldName {T}
9
9
_value:: T
10
10
end
11
- Base. propertynames (:: Foo ) = (:value ,)
12
- Base. getproperty (foo:: Foo , s:: Symbol ) =
11
+ Base. propertynames (:: FooFieldName ) = (:value ,)
12
+ Base. getproperty (foo:: FooFieldName , s:: Symbol ) =
13
13
s == :value ? getfield (foo, :_value ) : error (" Invalid property name" )
14
- Base. convert (:: Type{Foo{T}} , foo:: Foo ) where {T} = Foo {T} (foo. value)
15
- Base. zero (:: Type{Foo{T}} ) where {T} = Foo (zero (T))
14
+ Base. convert (:: Type{FooFieldName{T}} , foo:: FooFieldName ) where {T} =
15
+ FooFieldName {T} (foo. value)
16
+ Base. zero (:: Type{FooFieldName{T}} ) where {T} = FooFieldName (zero (T))
16
17
17
- const x = (; foo = Foo (0 ), a = (; b = 1 , c = ((; d = 2 ), (;), (3 , ()))))
18
+ get_x () =
19
+ (; foo = FooFieldName (0 ), a = (; b = 1 , c = ((; d = 2 ), (;), (3 , ()))))
18
20
19
21
@testset " FieldName Unit Tests" begin
22
+ x = get_x ()
20
23
@test_all @name () == MatrixFields. FieldName ()
21
24
@test_all @name (a. c.:(1 ). d) == MatrixFields. FieldName (:a , :c , 1 , :d )
22
25
@test_all @name (a. c.:(3 ). :(1 )) == MatrixFields. FieldName (:a , :c , 3 , 1 )
@@ -81,6 +84,7 @@ const x = (; foo = Foo(0), a = (; b = 1, c = ((; d = 2), (;), (3, ()))))
81
84
end
82
85
83
86
@testset " FieldNameTree Unit Tests" begin
87
+ x = get_x ()
84
88
name_tree = MatrixFields. FieldNameTree (x)
85
89
86
90
@test_all MatrixFields. FieldNameTree (x) == name_tree
110
114
end
111
115
112
116
@testset " FieldNameSet Unit Tests" begin
117
+ x = get_x ()
113
118
name_tree = MatrixFields. FieldNameTree (x)
114
119
115
120
vector_keys (names... ) = MatrixFields. FieldVectorKeys (names, name_tree)
706
711
end
707
712
708
713
@testset " FieldNameDict Unit Tests" begin
714
+ x = get_x ()
709
715
FT = Float64
710
716
x_FT = convert (replace_basetype (Int, FT, typeof (x)), x)
711
717
0 commit comments