-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from hyrodium/feature/deparse
Add `@deparse` macro
- Loading branch information
Showing
5 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Replay | ||
|
||
i1 = @deparse println("Hello World") | ||
i2 = @deparse using LinearAlgebra | ||
i3 = @deparse begin | ||
x = [1, 1] | ||
A = [1 0; 0 2] | ||
end | ||
i4 = @deparse @show dot(x, A, x) | ||
i5 = @deparse function f(x) | ||
@comment This is a comment | ||
if x > 0 | ||
@comment x is larger than 0 | ||
@info "x is larger than 0" | ||
end | ||
@info "compute 2x + 2" | ||
2x + 2 | ||
end | ||
i6 = @deparse x = 3 | ||
i7 = @deparse f(x) | ||
|
||
replay([i1, i2, i3, i4, i5, i6, i7], use_ghostwriter=true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
@testset "@deparse 1" begin | ||
ref = "1" | ||
tar = @deparse 1 | ||
@test tar == ref | ||
end | ||
|
||
@testset "@deparse @show x" begin | ||
ref = "@show x" | ||
tar = @deparse @show x | ||
@test tar == ref | ||
end | ||
|
||
@testset "@deparse println(\"Hello World\")" begin | ||
ref = "println(\"Hello World\")" | ||
tar = @deparse println("Hello World") | ||
@test tar == ref | ||
end | ||
|
||
@testset "using LinearAlgebra: dot" begin | ||
ref = "using LinearAlgebra: dot" | ||
tar = @deparse using LinearAlgebra: dot | ||
@test tar == ref | ||
end | ||
|
||
# We don't support the expression yet. | ||
@testset "f(x) = x" begin | ||
ref = "f(x) = x" | ||
tar = @deparse f(x) = x | ||
@test_broken tar == ref | ||
end | ||
|
||
@testset "function definition" begin | ||
ref = """ | ||
function f(x) | ||
y = 2x + 1 | ||
z = y ^ 3 | ||
return y | ||
end | ||
""" | ||
tar = @deparse function f(x) | ||
y = 2x + 1 | ||
z = y^3 | ||
return y | ||
end | ||
@test ref == tar | ||
end | ||
|
||
@testset "function definition with comments" begin | ||
ref = """ | ||
function f(x) | ||
# linear transformation | ||
y = 2x | ||
# square root of y | ||
z = √y | ||
return y | ||
end | ||
""" | ||
tar = @deparse function f(x) | ||
@comment linear transformation | ||
y = 2x | ||
@comment square root of y | ||
z = √y | ||
return y | ||
end | ||
@test ref == tar | ||
end | ||
|
||
@testset "@comment" begin | ||
ref = """ | ||
function f(x) | ||
# This is a comment | ||
if x > 0 | ||
# x is larger than 0 | ||
@info "x is larger than 0" | ||
end | ||
@info "compute 2x + 2" | ||
2x + 2 | ||
end | ||
""" | ||
tar = @deparse function f(x) | ||
@comment This is a comment | ||
if x > 0 | ||
@comment x is larger than 0 | ||
@info "x is larger than 0" | ||
end | ||
@info "compute 2x + 2" | ||
2x + 2 | ||
end | ||
@test tar == ref | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters