Permalink
Browse files

Use context helper method instead of repeating code.

  • Loading branch information...
1 parent 28ad478 commit f6e311bfd074623c4a3e3c26d5fd3b5de5b270ba @vic committed Aug 24, 2011
Showing with 9 additions and 17 deletions.
  1. +8 −16 spec/shuffle_spec.rb
  2. +1 −1 spec/spec_helper.rb
View
@@ -12,8 +12,7 @@
describe 'basic math opers' do
it 'associates correctly + and *' do
- n = c('a + b * c - d')
- n.shuffle.sexp.should ==
+ n('a + b * c - d').should ==
[:chain,
[:name, "a"],
[:act, "+", nil,
@@ -24,23 +23,20 @@
describe 'assignment' do
it 'takes lhs and rhs' do
- n = c('a = b')
- n.shuffle.sexp.should ==
+ n('a = b').should ==
[:act, "=", nil, [:name, "a"], [:name, "b"]]
end
it 'has higher precedence than +' do
- n = c('a = b + c')
- n.shuffle.sexp.should ==
+ n('a = b + c').should ==
[:act, "=", nil,
[:name, "a"],
[:chain, [:name, "b"],
[:act, "+", nil, [:name, "c"]]]]
end
it 'has higher precedence than both + and *' do
- n = c('a * d = b + c')
- n.shuffle.sexp.should ==
+ n('a * d = b + c').should ==
[:act, "=", nil,
[:chain, [:name, "a"],
[:act, "*", nil, [:name, "d"]]],
@@ -51,31 +47,27 @@
describe 'unary negation' do
it 'binds to right' do
- n = c('!b')
- n.shuffle.sexp.should ==
+ n('!b').should ==
[:chain, [:name, "b"], [:act, "!", nil]]
end
it 'binds chain to right' do
- n = c('!b c d')
- n.shuffle.sexp.should ==
+ n('!b c d').should ==
[:chain,
[:name, "b"], [:name, "c"], [:name, "d"],
[:act, "!", nil]]
end
it 'binds chain to right till oper' do
- n = c('!b c + d')
- n.shuffle.sexp.should ==
+ n('!b c + d').should ==
[:chain,
[:name, "b"], [:name, "c"],
[:act, "!", nil],
[:act, "+", nil, [:name, "d"]]]
end
it 'binds chain to right till oper' do
- n = c('b + ! c d')
- n.shuffle.sexp.should ==
+ n('b + ! c d').should ==
[:chain,
[:name, "b"],
[:act, "+", nil,
View
@@ -22,6 +22,6 @@ def s(code, rule = :root, *args)
def n(code, rule = :root, *args)
n = c(code, rule, true, *args)
- n.shuffle if n
+ n.shuffle.sexp if n
end
end

0 comments on commit f6e311b

Please sign in to comment.