зеркало из https://github.com/github/bert.git
convert times to complex types
This commit is contained in:
Родитель
4ea42f0b24
Коммит
64b20703d9
|
@ -26,6 +26,8 @@ module BERT
|
|||
end
|
||||
when :bool
|
||||
item[1] == :true
|
||||
when :time
|
||||
Time.at(item[1].to_i, item[2].to_i)
|
||||
else
|
||||
item.map { |x| convert(x) }
|
||||
end
|
||||
|
|
|
@ -26,6 +26,8 @@ module BERT
|
|||
[:nil, :nil]
|
||||
when TrueClass, FalseClass
|
||||
[:bool, item.to_s.to_sym]
|
||||
when Time
|
||||
[:time, item.to_i, item.usec]
|
||||
else
|
||||
item
|
||||
end
|
||||
|
|
|
@ -38,6 +38,12 @@ class DecoderTest < Test::Unit::TestCase
|
|||
assert_equal after, BERT::Decoder.convert(before)
|
||||
end
|
||||
|
||||
should "convert times" do
|
||||
before = [:time, 1254976067, 0]
|
||||
after = Time.at(1254976067)
|
||||
assert_equal after, BERT::Decoder.convert(before)
|
||||
end
|
||||
|
||||
should "leave other stuff alone" do
|
||||
before = [1, 2.0, [:foo, 'bar']]
|
||||
assert_equal before, BERT::Decoder.convert(before)
|
||||
|
|
|
@ -36,6 +36,12 @@ class EncoderTest < Test::Unit::TestCase
|
|||
assert_equal after, BERT::Encoder.convert(before)
|
||||
end
|
||||
|
||||
should "convert times" do
|
||||
before = Time.at(1254976067)
|
||||
after = [:time, 1254976067, 0]
|
||||
assert_equal after, BERT::Encoder.convert(before)
|
||||
end
|
||||
|
||||
should "leave other stuff alone" do
|
||||
before = [1, 2.0, [:foo, 'bar']]
|
||||
assert_equal before, BERT::Encoder.convert(before)
|
||||
|
|
Загрузка…
Ссылка в новой задаче