free_mutant/spec/unit/mutant/mutator/node/if_spec.rb

82 lines
2.3 KiB
Ruby
Raw Normal View History

# encoding: utf-8
2013-06-10 10:15:59 +02:00
require 'spec_helper'
describe Mutant::Mutator, 'if' do
before do
2013-09-08 22:12:23 +02:00
Mutant::Random.stub(hex_string: 'random')
2013-06-10 10:15:59 +02:00
end
context 'with if and else branches' do
let(:source) { 'if :condition; true; else false; end' }
let(:mutations) do
mutants = []
# mutations of condition
mutants << 'if :srandom; true; else false; end'
mutants << 'if !:condition; true; else false; end'
mutants << 'if nil; true; else false; end'
mutants << 'if true; true; else false; end'
mutants << 'if false; true; else false; end'
# Deleted else branch
mutants << 'if :condition; true end'
2013-06-12 19:04:40 +02:00
# Deleted if branch resuting in unless rendering
2013-06-10 10:15:59 +02:00
mutants << 'unless :condition; false; end'
# Deleted if branch with promoting else branch to if branch
mutants << 'if :condition; false end'
# mutations of if body
mutants << 'if :condition; false; else false; end'
mutants << 'if :condition; nil; else false; end'
# mutations of else body
mutants << 'if :condition; true; else true; end'
mutants << 'if :condition; true; else nil; end'
mutants << 'nil'
2013-06-10 10:15:59 +02:00
end
it_should_behave_like 'a mutator'
end
2013-06-12 19:04:40 +02:00
context 'if with one branch' do
let(:source) { 'if condition; true; end' }
2013-06-10 10:15:59 +02:00
let(:mutations) do
mutants = []
2013-06-12 19:04:40 +02:00
mutants << 'if !condition; true; end'
mutants << 'if condition; false; end'
mutants << 'if condition; nil; end'
mutants << 'if true; true; end'
mutants << 'if false; true; end'
mutants << 'if nil; true; end'
mutants << 'nil'
2013-06-10 10:15:59 +02:00
end
it_should_behave_like 'a mutator'
end
2013-06-12 19:04:40 +02:00
context 'unless with one branch' do
let(:source) { 'unless :condition; true; end' }
2013-06-10 10:15:59 +02:00
2013-06-12 19:04:40 +02:00
let(:mutations) do
mutants = []
mutants << 'unless !:condition; true; end'
mutants << 'unless :srandom; true; end'
mutants << 'unless nil; true; end'
mutants << 'unless :condition; false; end'
mutants << 'unless :condition; nil; end'
mutants << 'unless true; true; end'
mutants << 'unless false; true; end'
mutants << 'if :condition; true; end'
mutants << 'nil'
2013-06-12 19:04:40 +02:00
end
2013-06-10 10:15:59 +02:00
2013-06-12 19:04:40 +02:00
it_should_behave_like 'a mutator'
end
2013-06-10 10:15:59 +02:00
end