Skip to content
This repository was archived by the owner on Sep 20, 2022. It is now read-only.

Commit d125970

Browse files
author
Nathan Smith
committed
test and fix for empty first line
1 parent 143e5e0 commit d125970

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/PyGen.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ end
4040
"""
4141
@pygen
4242
43-
Making julie walking a little *more* like python. Stick the @pygen macro in front of a
44-
function declaration and you can use `yield` statements to make a python style
43+
Making julie walking a little *more* like python. Stick
44+
the @pygen macro in front of a function declaration and
45+
you can use `yield` statements to make a python style
4546
generator!
4647
"""
4748
macro pygen(f)
4849
f′ = replace(f, yregex, asput)
4950
lines = f′ |> IOBuffer |> readlines
50-
insert!(lines, 2, "function γ(c::Channel)")
51+
ind = findfirst(x -> contains(x, "function"), lines)
52+
insert!(lines, ind + 1, "function γ(c::Channel)")
5153
push!(lines, "return Channel(γ)\nend")
5254
return join(lines, "\n") |> parse |> esc
5355
end

test/runtests.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@ using PyGen
22
using Base.Test
33

44
# write your own tests here
5-
@test PyGen.asput("yield pi") == "put!(c, pi)"
5+
@test PyGen.asput("yield pi") == "put!(c, pi)"
6+
7+
@pygen "
8+
9+
function λ()
10+
yield 10
11+
end
12+
"
13+
14+
# Test for \n in first line issue
15+
@test isdefined(:λ) == true

0 commit comments

Comments
 (0)