Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Unified Diff: third_party/grpc/src/ruby/spec/time_consts_spec.rb

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/grpc/src/ruby/spec/testdata/server1.pem ('k') | third_party/grpc/src/zlib/gen_build_yaml.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/grpc/src/ruby/spec/time_consts_spec.rb
diff --git a/third_party/protobuf/ruby/lib/google/protobuf.rb b/third_party/grpc/src/ruby/spec/time_consts_spec.rb
similarity index 50%
copy from third_party/protobuf/ruby/lib/google/protobuf.rb
copy to third_party/grpc/src/ruby/spec/time_consts_spec.rb
index f0eb626824f23b6dcd858ec820d57bcd246439de..871e0e241acacb7b27796c387c9b5976d3403547 100644
--- a/third_party/protobuf/ruby/lib/google/protobuf.rb
+++ b/third_party/grpc/src/ruby/spec/time_consts_spec.rb
@@ -1,6 +1,5 @@
-# Protocol Buffers - Google's data interchange format
-# Copyright 2008 Google Inc. All rights reserved.
-# https://developers.google.com/protocol-buffers/
+# Copyright 2015, Google Inc.
+# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
@@ -28,45 +27,63 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-# require mixins before we hook them into the java & c code
-require 'google/protobuf/message_exts'
+require 'grpc'
-# We define these before requiring the platform-specific modules.
-# That way the module init can grab references to these.
-module Google
- module Protobuf
- class Error < StandardError; end
- class ParseError < Error; end
+TimeConsts = GRPC::Core::TimeConsts
+
+describe TimeConsts do
+ before(:each) do
+ @known_consts = [:ZERO, :INFINITE_FUTURE, :INFINITE_PAST].sort
end
-end
-if RUBY_PLATFORM == "java"
- require 'json'
- require 'google/protobuf_java'
-else
- require 'google/protobuf_c'
-end
+ it 'should have all the known types' do
+ expect(TimeConsts.constants.collect.sort).to eq(@known_consts)
+ end
-require 'google/protobuf/repeated_field'
+ describe '#to_time' do
+ it 'converts each constant to a Time' do
+ m = TimeConsts
+ m.constants.each do |c|
+ expect(m.const_get(c).to_time).to be_a(Time)
+ end
+ end
+ end
+end
-module Google
- module Protobuf
+describe '#from_relative_time' do
+ it 'cannot handle arbitrary objects' do
+ expect { TimeConsts.from_relative_time(Object.new) }.to raise_error
+ end
- def self.encode(msg)
- msg.to_proto
+ it 'preserves TimeConsts' do
+ m = TimeConsts
+ m.constants.each do |c|
+ const = m.const_get(c)
+ expect(TimeConsts.from_relative_time(const)).to be(const)
end
+ end
- def self.encode_json(msg)
- msg.to_json
- end
+ it 'converts 0 to TimeConsts::ZERO' do
+ expect(TimeConsts.from_relative_time(0)).to eq(TimeConsts::ZERO)
+ end
- def self.decode(klass, proto)
- klass.decode(proto)
- end
+ it 'converts nil to TimeConsts::ZERO' do
+ expect(TimeConsts.from_relative_time(nil)).to eq(TimeConsts::ZERO)
+ end
- def self.decode_json(klass, json)
- klass.decode_json(json)
+ it 'converts negative values to TimeConsts::INFINITE_FUTURE' do
+ [-1, -3.2, -1e6].each do |t|
+ y = TimeConsts.from_relative_time(t)
+ expect(y).to eq(TimeConsts::INFINITE_FUTURE)
end
+ end
+ it 'converts a positive value to an absolute time' do
+ epsilon = 1
+ [1, 3.2, 1e6].each do |t|
+ want = Time.now + t
+ abs = TimeConsts.from_relative_time(t)
+ expect(abs.to_f).to be_within(epsilon).of(want.to_f)
+ end
end
end
« no previous file with comments | « third_party/grpc/src/ruby/spec/testdata/server1.pem ('k') | third_party/grpc/src/zlib/gen_build_yaml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698