Skip to content

Commit

Permalink
Add pp! and p! macro methods (#6374)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored and Serdar Dogruyol committed Jul 12, 2018
1 parent bec784d commit 6a30458
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
47 changes: 47 additions & 0 deletions spec/compiler/macro/macro_methods_spec.cr
Expand Up @@ -1686,5 +1686,52 @@ module Crystal
it "compares versions" do
assert_macro "", %({{compare_versions("1.10.3", "1.2.3")}}), [] of ASTNode, %(1)
end

describe "printing" do
it "puts" do
String.build do |io|
assert_macro "foo", %({% puts foo %}), "" do |program|
program.stdout = io
["bar".string] of ASTNode
end
end.should eq %("bar"\n)
end

it "p" do
String.build do |io|
assert_macro "foo", %({% p foo %}), "" do |program|
program.stdout = io
["bar".string] of ASTNode
end
end.should eq %("bar"\n)
end

it "p!" do
String.build do |io|
assert_macro "foo", "{% p! foo %}", "" do |program|
program.stdout = io
["bar".string] of ASTNode
end
end.should eq %(foo # => "bar"\n)
end

it "pp" do
String.build do |io|
assert_macro "foo", "{% pp foo %}", "" do |program|
program.stdout = io
["bar".string] of ASTNode
end
end.should eq %("bar"\n)
end

it "pp!" do
String.build do |io|
assert_macro "foo", "{% pp! foo %}", "" do |program|
program.stdout = io
["bar".string] of ASTNode
end
end.should eq %(foo # => "bar"\n)
end
end
end
end
8 changes: 4 additions & 4 deletions src/compiler/crystal/macros/methods.cr
Expand Up @@ -20,10 +20,10 @@ module Crystal
interpret_env(node)
when "flag?"
interpret_flag?(node)
when "puts", "p"
when "puts", "p", "pp"
interpret_puts(node)
when "pp"
interpret_pp(node)
when "p!", "pp!"
interpret_pp!(node)
when "skip_file"
interpret_skip_file(node)
when "system", "`"
Expand Down Expand Up @@ -122,7 +122,7 @@ module Crystal
@last = Nop.new
end

def interpret_pp(node)
def interpret_pp!(node)
strings = [] of {String, String}

node.args.each do |arg|
Expand Down

0 comments on commit 6a30458

Please sign in to comment.