Sha256: a5bed49ea387f10c106bc73f226cfdb5cbe2366d77448ad64e8158de13191aab

Contents?: true

Size: 862 Bytes

Versions: 3

Compression:

Stored size: 862 Bytes

Contents

require 'spec_helper'
describe BoolExpr::NotPushProcessor do
  subject{ BoolExpr }

  def _(expr)
    BoolExpr.sexpr(expr)
  end

  def rw(expr)
    BoolExpr::NotPushProcessor.new.call(expr)
  end

  it 'does nothing on variable references' do
    rw("not x").should eq([:bool_not, [:var_ref, "x"]])
  end

  it 'rewrites literals through negating them' do
    rw("not true").should  eq(_ "false")
    rw("not false").should eq(_ "true")
  end

  it 'rewrites not through removing them' do
    rw("not not true").should eq(_ "true")
  end

  it 'rewrites or through and of negated terms' do
    rw("not(x or y)").should eq(_ "not(x) and not(y)")
  end

  it 'rewrites and through or of negated terms' do
    rw("not(x and y)").should eq(_ "not(x) or not(y)")
  end

  it 'rewrites recursively' do
    rw("not(x and not(y))").should eq(_ "not(x) or y")
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sexpr-1.1.0 spec/integration/bool_expr/test_not_push.rb
sexpr-1.0.0 spec/integration/bool_expr/test_not_push.rb
sexpr-0.6.0 spec/integration/bool_expr/test_not_push.rb