test/choice_test.rb in bindata-2.3.3 vs test/choice_test.rb in bindata-2.3.4
- old
+ new
@@ -15,45 +15,45 @@
end
end
def create_choice(choices, options = {})
chooser = Chooser.new
- params = {:choices => choices, :selection => lambda { chooser.choice } }.merge(options)
+ params = {choices: choices, selection: -> { chooser.choice } }.merge(options)
choice = BinData::Choice.new(params)
choice.set_chooser(chooser)
choice
end
describe BinData::Choice, "when instantiating" do
it "ensures mandatory parameters are supplied" do
args = {}
lambda { BinData::Choice.new(args) }.must_raise ArgumentError
- args = {:selection => 1}
+ args = {selection: 1}
lambda { BinData::Choice.new(args) }.must_raise ArgumentError
- args = {:choices => []}
+ args = {choices: []}
lambda { BinData::Choice.new(args) }.must_raise ArgumentError
end
it "fails when a given type is unknown" do
- args = {:choices => [:does_not_exist], :selection => 0}
+ args = {choices: [:does_not_exist], selection: 0}
lambda { BinData::Choice.new(args) }.must_raise BinData::UnRegisteredTypeError
end
it "fails when a given type is unknown" do
- args = {:choices => {0 => :does_not_exist}, :selection => 0}
+ args = {choices: {0 => :does_not_exist}, selection: 0}
lambda { BinData::Choice.new(args) }.must_raise BinData::UnRegisteredTypeError
end
it "fails when :choices Hash has a symbol as key" do
- args = {:choices => {:a => :uint8}, :selection => 0}
+ args = {choices: {a: :uint8}, selection: 0}
lambda { BinData::Choice.new(args) }.must_raise ArgumentError
end
it "fails when :choices Hash has a nil key" do
- args = {:choices => {nil => :uint8}, :selection => 0}
+ args = {choices: {nil => :uint8}, selection: 0}
lambda { BinData::Choice.new(args) }.must_raise ArgumentError
end
end
module ChoiceInitializedWithArrayOrHash
@@ -110,24 +110,24 @@
describe BinData::Choice, "with sparse choices array" do
include ChoiceInitializedWithArrayOrHash
let(:obj) {
choices = [nil, nil, nil,
- [:uint8, {:value => 30}], nil,
- [:uint8, {:value => 50}], nil,
- [:uint8, {:value => 70}]]
+ [:uint8, {value: 30}], nil,
+ [:uint8, {value: 50}], nil,
+ [:uint8, {value: 70}]]
create_choice(choices)
}
end
describe BinData::Choice, "with choices hash" do
include ChoiceInitializedWithArrayOrHash
let(:obj) {
- choices = {3 => [:uint8, {:value => 30}],
- 5 => [:uint8, {:value => 50}],
- 7 => [:uint8, {:value => 70}]}
+ choices = {3 => [:uint8, {value: 30}],
+ 5 => [:uint8, {value: 50}],
+ 7 => [:uint8, {value: 70}]}
create_choice(choices)
}
end
describe BinData::Choice, "with single values" do
@@ -200,11 +200,11 @@
end
describe BinData::Choice, "with copy_on_change => true" do
let(:obj) {
choices = {3 => :uint8, 5 => :uint8, 7 => :uint8}
- create_choice(choices, :copy_on_change => true)
+ create_choice(choices, copy_on_change: true)
}
it "copies value when changing selection" do
obj.choice = 3
obj.assign(254)
@@ -213,27 +213,27 @@
obj.must_equal 254
end
end
describe BinData::Choice, "with :default" do
- let(:choices) { { "a" => :int8, :default => :int16be } }
+ let(:choices) { { "a" => :int8, default: :int16be } }
it "selects for existing case" do
- obj = BinData::Choice.new(:selection => "a", :choices => choices)
+ obj = BinData::Choice.new(selection: "a", choices: choices)
obj.num_bytes.must_equal 1
end
it "selects for default case" do
- obj = BinData::Choice.new(:selection => "other", :choices => choices)
+ obj = BinData::Choice.new(selection: "other", choices: choices)
obj.num_bytes.must_equal 2
end
end
describe BinData::Choice, "subclassed with default parameters" do
class DerivedChoice < BinData::Choice
endian :big
- default_parameter :selection => 'a'
+ default_parameter selection: 'a'
uint16 'a'
uint32 'b'
uint64 :default
end
@@ -242,14 +242,14 @@
obj = DerivedChoice.new
obj.num_bytes.must_equal 2
end
it "overides default parameter" do
- obj = DerivedChoice.new(:selection => 'b')
+ obj = DerivedChoice.new(selection: 'b')
obj.num_bytes.must_equal 4
end
it "selects default selection" do
- obj = DerivedChoice.new(:selection => 'z')
+ obj = DerivedChoice.new(selection: 'z')
obj.num_bytes.must_equal 8
end
end