Added Ruby::Node#if_false
This commit is contained in:
parent
4b50a161ed
commit
0dcee637d3
|
@ -148,6 +148,15 @@ module Oga
|
|||
Node.new(:if, [self, yield])
|
||||
end
|
||||
|
||||
##
|
||||
# Wraps the current node in an `if !...` statement.
|
||||
#
|
||||
# @see [#if_true]
|
||||
#
|
||||
def if_false
|
||||
self.not.if_true { yield }
|
||||
end
|
||||
|
||||
##
|
||||
# Wraps the current node in a `while` statement.
|
||||
#
|
||||
|
|
|
@ -133,6 +133,21 @@ describe Oga::Ruby::Node do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#if_false' do
|
||||
it 'returns an if statement Node' do
|
||||
condition = described_class.new(:lit, %w{number})
|
||||
body = described_class.new(:lit, %w{10})
|
||||
statement = condition.if_false { body }
|
||||
|
||||
statement.type.should == :if
|
||||
|
||||
statement.to_a[0].type.should == :send
|
||||
|
||||
statement.to_a[0].to_a.should == [condition, '!']
|
||||
statement.to_a[1].should == body
|
||||
end
|
||||
end
|
||||
|
||||
describe '#while_true' do
|
||||
it 'returns a while statement Node' do
|
||||
condition = described_class.new(:lit, %w{number})
|
||||
|
|
Loading…
Reference in New Issue