Skip to content

Commit ee151d6

Browse files
committed
style: formatting
1 parent 5d511aa commit ee151d6

File tree

1 file changed

+29
-42
lines changed

1 file changed

+29
-42
lines changed

test/test_parse.jl

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,20 @@ end
5252
@test typeof(ex.tree) <: Node{Float64}
5353
end
5454

55-
# # Or an int
56-
# let ex = @parse_expression(1, operators = operators, variable_names = [])
5755
@testitem "Or an int" begin
5856
using DynamicExpressions
5957
operators = OperatorEnum()
6058
ex = @parse_expression(1, operators = operators, variable_names = [])
6159
@test typeof(ex.tree) <: Node{Int64}
6260
end
6361

64-
# Or just a variable
6562
@testitem "Or just a variable" begin
6663
using DynamicExpressions
6764
operators = OperatorEnum()
6865
ex = @parse_expression(x, operators = operators, variable_names = ["x"])
6966
@test typeof(ex.tree) <: Node{Float32}
7067
end
7168

72-
# Or, with custom node types
7369
@testitem "Or, with custom node types" begin
7470
using DynamicExpressions
7571
operators = OperatorEnum()
@@ -79,7 +75,6 @@ end
7975
@test typeof(ex.tree) <: GraphNode{Float32}
8076
end
8177

82-
8378
@testitem "With GraphNode" begin
8479
using DynamicExpressions
8580

@@ -90,8 +85,8 @@ end
9085
end
9186

9287
@testitem "Should work with symbols for variable names too" begin
93-
using DynamicExpressions
94-
let ex = @parse_expression(
88+
using DynamicExpressions
89+
ex = @parse_expression(
9590
cos(exp(α)),
9691
operators = OperatorEnum(; unary_operators=[cos, exp]),
9792
variable_names = []
@@ -100,11 +95,10 @@ let ex = @parse_expression(
10095
s = sprint((io, e) -> show(io, MIME("text/plain"), e), ex)
10196
@test s == "cos(exp(α))"
10297
end
103-
end
10498

10599
@testitem "This also works for parsing mixed types" begin
106-
using DynamicExpressions
107-
let v = [1, 2, 3],
100+
using DynamicExpressions
101+
v = [1, 2, 3]
108102
ex = @parse_expression(
109103
$v * tan(cos(5 + x)),
110104
operators = GenericOperatorEnum(;
@@ -182,26 +176,24 @@ let v = [1, 2, 3],
182176
end
183177

184178
@testitem "Also check with tuple inputs" begin
185-
let tu = (1.0, 2.0im),
179+
tu = (1.0, 2.0im)
186180
ex = @parse_expression(
187181
x * $tu - cos(y),
188182
operators = GenericOperatorEnum(; binary_operators=[*, -], unary_operators=[cos]),
189183
variable_names = ["x", "y"],
190184
node_type = Node{Tuple{Float64,ComplexF64}}
191-
),
185+
)
192186
s = sprint((io, e) -> show(io, MIME("text/plain"), e), ex)
193187

194188
@test s == "(x * ((1.0, 0.0 + 2.0im))) - cos(y)"
195189
@test typeof(ex.tree) <: Node{Tuple{Float64,ComplexF64}}
196190
end
197-
end
198191

199192
@testitem "interpolating custom function" begin
200-
using DynamicExpressions
201-
using Suppressor
202-
show_type(x) = (show(typeof(x)); x)
193+
using DynamicExpressions
194+
using Suppressor
195+
show_type(x) = (show(typeof(x)); x)
203196

204-
let
205197
logged_out = @capture_out begin
206198
ex = @parse_expression(
207199
x * 2.5 - $(show_type)(cos(y)),
@@ -214,11 +206,10 @@ let
214206
end
215207
@test contains(logged_out, "Node{Float32}")
216208
end
217-
end
218209

219210
@testitem "Helpful errors for missing operator" begin
220-
using DynamicExpressions
221-
let operators = OperatorEnum(; unary_operators=[sin])
211+
using DynamicExpressions
212+
operators = OperatorEnum(; unary_operators=[sin])
222213
@test_throws ArgumentError @parse_expression(
223214
cos(x), operators = operators, variable_names = [:x]
224215
)
@@ -271,42 +262,38 @@ let operators = OperatorEnum(; unary_operators=[sin])
271262
)
272263
end
273264
end
274-
end
275265

276266
@testitem "Helpful error for missing function in scope" begin
277-
using DynamicExpressions
278-
operators = OperatorEnum(;
279-
binary_operators=[+, -, *, /],
280-
unary_operators=[cos, sin],
281-
define_helper_functions=false,
282-
)
283-
my_badly_scoped_function(x) = x
284-
@test_throws ArgumentError begin
285-
ex = @parse_expression(
286-
my_badly_scoped_function(x),
287-
operators = operators,
288-
variable_names = ["x"],
289-
evaluate_on = [my_badly_scoped_function]
267+
using DynamicExpressions
268+
operators = OperatorEnum(;
269+
binary_operators=[+, -, *, /],
270+
unary_operators=[cos, sin],
271+
define_helper_functions=false,
290272
)
291-
end
292-
if VERSION >= v"1.9"
293-
@test_throws "Tried to interpolate function `my_badly_scoped_function` but failed." begin
273+
my_badly_scoped_function(x) = x
274+
@test_throws ArgumentError begin
294275
ex = @parse_expression(
295276
my_badly_scoped_function(x),
296277
operators = operators,
297278
variable_names = ["x"],
298279
evaluate_on = [my_badly_scoped_function]
299280
)
300281
end
301-
end
282+
if VERSION >= v"1.9"
283+
@test_throws "Tried to interpolate function `my_badly_scoped_function` but failed." begin
284+
ex = @parse_expression(
285+
my_badly_scoped_function(x),
286+
operators = operators,
287+
variable_names = ["x"],
288+
evaluate_on = [my_badly_scoped_function]
289+
)
290+
end
291+
end
302292
end
303293

304294
@testitem "Helpful error for missing variable name" begin
305295
using DynamicExpressions
306-
operators = OperatorEnum(
307-
binary_operators=[+, -, *, /],
308-
unary_operators=[cos, sin],
309-
)
296+
operators = OperatorEnum(; binary_operators=[+, -, *, /], unary_operators=[cos, sin])
310297
@test_throws ArgumentError @parse_expression(
311298
x + y, operators = operators, variable_names = ["x"],
312299
)

0 commit comments

Comments
 (0)