Skip to content

Commit c100d50

Browse files
committed
Test error is thrown for unsupported functions
1 parent fcc056e commit c100d50

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/base.jl

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,10 @@ function convert(
297297
end
298298
(::Type{Node{T}})(tree::Node; kws...) where {T} = convert(Node{T}, tree; kws...)
299299

300-
function reduce(f, tree::Node; init=nothing)
301-
throw(ArgumentError("reduce is not supported for trees. Use tree_mapreduce instead."))
302-
end
303-
function foldl(f, tree::Node; init=nothing)
304-
throw(ArgumentError("foldl is not supported for trees. Use tree_mapreduce instead."))
305-
end
306-
function foldr(f, tree::Node; init=nothing)
307-
throw(ArgumentError("foldr is not supported for trees. Use tree_mapreduce instead."))
308-
end
309-
function mapfoldl(f, tree::Node; init=nothing)
310-
throw(ArgumentError("mapfoldl is not supported for trees. Use tree_mapreduce instead."))
311-
end
312-
function mapfoldr(f, tree::Node; init=nothing)
313-
throw(ArgumentError("mapfoldr is not supported for trees. Use tree_mapreduce instead."))
300+
for func in (:reduce, :foldl, :foldr, :mapfoldl, :mapfoldr)
301+
@eval begin
302+
function $func(f, tree::Node; kws...)
303+
throw(error(string($func) * " not implemented for Node. Use `tree_mapreduce` instead."))
304+
end
305+
end
314306
end

test/test_base.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,10 @@ end
163163
end
164164
@test sum(t -> (t.degree == 0 && t.constant) ? t.val : 0.0, ctree) 11.6 * 1.5
165165
end
166+
167+
@testset "Unsupported" begin
168+
for func in (:reduce, :foldl, :foldr, :mapfoldl, :mapfoldr)
169+
wrapped_func(args...) = (@eval $func)(args...)
170+
@test_throws ErrorException wrapped_func(Returns(1), tree)
171+
end
172+
end

0 commit comments

Comments
 (0)