Skip to content

Commit

Permalink
Merge pull request #20 from co1emi11er2/kw_fixes-and-misc
Browse files Browse the repository at this point in the history
Kw fixes and misc
  • Loading branch information
co1emi11er2 authored Nov 18, 2024
2 parents 23d2089 + 42c02ed commit 77f50d3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Handcalcs"
uuid = "e8a07092-c156-4455-ab8e-ed8bc81edefb"
authors = ["Cole Miller"]
version = "0.4.1"
version = "0.4.2"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand All @@ -22,7 +22,7 @@ Latexify = "^0.16.4"
MacroTools = "0.5"
PrecompileTools = "1.2"
Revise = "3.5"
TestHandcalcFunctions = "0.2"
TestHandcalcFunctions = "0.2.1"
Unitful = "1.19"
UnitfulLatexify = "^1.6.4"
julia = "1.10"
Expand Down
3 changes: 2 additions & 1 deletion src/handfunc_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function _extract_kw(kw::Expr, dict::Dict)
return dict
end

function _extract_kw(arg::Symbol, dict::Dict)
function _extract_kw(kw::Symbol, dict::Dict)
dict[kw] = nothing
return dict
end
Expand Down Expand Up @@ -195,6 +195,7 @@ function _arr_to_expr!(expr::Expr, arr::Array)
right_tuple_expr = expr.args[1].args[2].args
for (arg_name, arg_val) in arr
push!(left_tuple_expr, arg_name)
arg_val = typeof(arg_val) == Symbol ? QuoteNode(arg_val) : arg_val
push!(right_tuple_expr, arg_val)
end
end
Expand Down
28 changes: 28 additions & 0 deletions test/handfunc_macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,23 @@ calc_Iy_3 = @handfunc x = TestHandcalcFunctions.calc_Iy(15,5;expo=2, denominator
calc_Iy_4 = @handfunc x = TestHandcalcFunctions.calc_Iy(10+5,5;expo=2, denominator=5+5) # check expressions
@test calc_Iy_3 == expected_Iy_3
@test calc_Iy_4 == expected_Iy_3

b = 5
h = 15
a = 5
c = 15
expected_1 = (L"$\begin{aligned}
Ix &= \frac{b \cdot h^{3}}{12} = \frac{5 \cdot 15^{3}}{12} = 1406.25
\end{aligned}$")
calc_1 = @handfunc x = calc_Ix(;b=b, h=h) # check kw parameters with same name
#calc_2 = @handfunc x = calc_Ix(;b, h) # check kw parameters with same name
calc_3 = @handfunc x = calc_Ix(;b=a, h=c) # check kw parameters with different name
calc_4 = @handfunc x = calc_Ix(;b=5, h=15) # check numeric parameters
@test calc_1 == expected_1
# @test calc_2 == expected_1
@test calc_3 == expected_1
@test calc_4 == expected_1

# ***************************************************


Expand Down Expand Up @@ -107,4 +124,15 @@ b = 5
h = 15
calc = @handfunc Is = TestHandcalcFunctions.calc_Is(b, h)
@test calc == expected
# ***************************************************

# Check with symbol variabels
# ***************************************************
# ***************************************************
expected_1 = (L"$\begin{aligned}
y &= x = hello
\end{aligned}$")
x = :hello
calc_1 = @handcalcs y = sym_function(x)
@test calc_1 == expected_1
# ***************************************************
6 changes: 3 additions & 3 deletions test/unitful_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ b = -5u"inch"
calc = @handcalc x = a + b
@test calc == expected

#TODO: Fix exponent issue
# Unitful and UnitfulLatexify exponent test
expected = L"$x = (a)^{2} = (2\;\mathrm{inch})^{2} = 4\;\mathrm{inch}^{2}$"
expected = L"$x = a^{2} = \left( 2\;\mathrm{inch} \right)^{2} = 4\;\mathrm{inch}^{2}$"
a = 2u"inch"
calc = @handcalc x = a^2
@test_broken calc == expected
@test calc == expected

# pipe operator
expected = L"$\begin{aligned}
area &= b \cdot h = 5\;\mathrm{ft} \cdot 120\;\mathrm{inch} = 50\;\mathrm{ft}^{2}
\end{aligned}$"
Expand Down

2 comments on commit 77f50d3

@co1emi11er2
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Bug Fixes

  • fixed some keyword function parsing (still cant do x = some_func(; a, b, c))
  • fixed symbol parsing. Variable values that were of type symbol would result in an error previously.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/119720

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.2 -m "<description of version>" 77f50d350857f48f0ebe2986297c0e050e1c9ce9
git push origin v0.4.2

Please sign in to comment.