Skip to content

Commit

Permalink
Allow markdown strings in code replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
ctessum committed Jul 23, 2022
1 parent de22b31 commit 03d38dc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Grader"
uuid = "d440d0cf-a03a-4c3f-a45e-240b6b8fa1ca"
authors = ["Christopher Tessum <[email protected]> and contributors"]
version = "0.3.0"
version = "0.3.1"

[deps]
Espresso = "6912e4f1-e036-58b0-9138-08d1e6358ea9"
Expand All @@ -16,9 +16,10 @@ Parameters = "0.12"
julia = "1"

[extras]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"

[targets]
test = ["Test", "Plots", "LinearAlgebra"]
test = ["Test", "Plots", "LinearAlgebra", "Markdown"]
3 changes: 2 additions & 1 deletion src/Grader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ function fill_answers(code::AbstractString, answerkey::Dict)::String
expr = Espresso.subs(expr, answerkey)
io = IOBuffer()
print(io, expr)
String(take!(io))
s = String(take!(io))
replace(replace(s, r"end$"=>""), r"^begin"=>"") # remove begin and end added above
end

"""
Expand Down
19 changes: 18 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,24 @@ using Test
@test p.score 1.0
end

@testset "fill answers 2" begin
code = """
using LinearAlgebra
using Markdown
n = missing
md\"\"\"Testing if markdown strings are okay.\"\"\"
"""

answer_code = fill_answers(code, Dict(
:(n = missing) => :(n = LinearAlgebra.norm([1, 2, 3]))
))

p = Problem()
answer = @runstudent! p answer_code
grade!(p, "norm", "calculate norm", 1, :($answer.n 3.7416573867739413), "norm is incorrect")
@test p.score 1.0
end

@testset "plot" begin
using LinearAlgebra

Expand All @@ -274,7 +292,6 @@ using Test
grade!(p, "XY Plot", "Y values", 3,
quote
ynorm = $norm($student.xy[1][1][:y])
println(ynorm)
ynorm 159.16343801262903
end,
"The Y values are not correct")
Expand Down

2 comments on commit 03d38dc

@ctessum
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
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/64840

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.3.1 -m "<description of version>" 03d38dc75d27dfa6f4a5feb06bd681178c78627a
git push origin v0.3.1

Please sign in to comment.