Skip to content

Commit

Permalink
Removed some TODOs for Crystal 0.18
Browse files Browse the repository at this point in the history
jhass committed Jun 15, 2016

Verified

This commit was signed with the committer’s verified signature.
jhass Jonne Haß
1 parent 71bca5d commit fd0f67b
Showing 7 changed files with 22 additions and 44 deletions.
6 changes: 2 additions & 4 deletions spec/std/named_tuple_spec.cr
Original file line number Diff line number Diff line change
@@ -26,8 +26,7 @@ describe "NamedTuple" do
NamedTuple(foo: Int32, bar: Int32).from({:foo => 1, :baz => 2})
end

# TODO: simplify regex and use TypeCastError after 0.18
expect_raises(Exception, /cast (?:from String )?to Int32 failed/) do
expect_raises(TypeCastError, /cast from String to Int32 failed/) do
NamedTuple(foo: Int32, bar: Int32).from({:foo => 1, :bar => "foo"})
end
end
@@ -49,8 +48,7 @@ describe "NamedTuple" do
{foo: Int32, bar: Int32}.from({:foo => 1, :baz => 2})
end

# TODO: simplify regex and use TypeCastError after 0.18
expect_raises(Exception, /cast (?:from String )?to Int32 failed/) do
expect_raises(TypeCastError, /cast from String to Int32 failed/) do
{foo: Int32, bar: Int32}.from({:foo => 1, :bar => "foo"})
end
end
26 changes: 13 additions & 13 deletions spec/std/openssl/ssl/context_spec.cr
Original file line number Diff line number Diff line change
@@ -4,21 +4,21 @@ require "openssl"
describe OpenSSL::SSL::Context do
it "new for client" do
context = OpenSSL::SSL::Context::Client.new
context.options.should eq(OpenSSL::SSL.options_flags(
context.options.should eq(OpenSSL::SSL::Options.flags(
ALL, NO_SSLV2, NO_SSLV3, NO_SESSION_RESUMPTION_ON_RENEGOTIATION, SINGLE_ECDH_USE, SINGLE_DH_USE
))
context.modes.should eq(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
context.modes.should eq(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
context.verify_mode.should eq(OpenSSL::SSL::VerifyMode::PEER)

OpenSSL::SSL::Context::Client.new(LibSSL.tlsv1_method)
end

it "new for server" do
context = OpenSSL::SSL::Context::Server.new
context.options.should eq(OpenSSL::SSL.options_flags(
context.options.should eq(OpenSSL::SSL::Options.flags(
ALL, NO_SSLV2, NO_SSLV3, NO_SESSION_RESUMPTION_ON_RENEGOTIATION, SINGLE_ECDH_USE, SINGLE_DH_USE, CIPHER_SERVER_PREFERENCE
))
context.modes.should eq(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
context.modes.should eq(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
context.verify_mode.should eq(OpenSSL::SSL::VerifyMode::NONE)

OpenSSL::SSL::Context::Server.new(LibSSL.tlsv1_method)
@@ -81,39 +81,39 @@ describe OpenSSL::SSL::Context do
context = OpenSSL::SSL::Context::Client.new
context.remove_options(context.options) # reset
context.add_options(OpenSSL::SSL::Options::ALL).should eq(OpenSSL::SSL::Options::ALL)
context.add_options(OpenSSL::SSL.options_flags(NO_SSLV2, NO_SSLV3))
.should eq(OpenSSL::SSL.options_flags(ALL, NO_SSLV2, NO_SSLV3))
context.add_options(OpenSSL::SSL::Options.flags(NO_SSLV2, NO_SSLV3))
.should eq(OpenSSL::SSL::Options.flags(ALL, NO_SSLV2, NO_SSLV3))
end

it "removes options" do
context = OpenSSL::SSL::Context::Client.insecure
context.add_options(OpenSSL::SSL.options_flags(ALL, NO_SSLV2))
context.add_options(OpenSSL::SSL::Options.flags(ALL, NO_SSLV2))
context.remove_options(OpenSSL::SSL::Options::ALL).should eq(OpenSSL::SSL::Options::NO_SSLV2)
end

it "returns options" do
context = OpenSSL::SSL::Context::Client.insecure
context.add_options(OpenSSL::SSL.options_flags(ALL, NO_SSLV2))
context.options.should eq(OpenSSL::SSL.options_flags(ALL, NO_SSLV2))
context.add_options(OpenSSL::SSL::Options.flags(ALL, NO_SSLV2))
context.options.should eq(OpenSSL::SSL::Options.flags(ALL, NO_SSLV2))
end

it "adds modes" do
context = OpenSSL::SSL::Context::Client.insecure
context.add_modes(OpenSSL::SSL::Modes::AUTO_RETRY).should eq(OpenSSL::SSL::Modes::AUTO_RETRY)
context.add_modes(OpenSSL::SSL::Modes::RELEASE_BUFFERS)
.should eq(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
.should eq(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
end

it "removes modes" do
context = OpenSSL::SSL::Context::Client.insecure
context.add_modes(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
context.add_modes(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
context.remove_modes(OpenSSL::SSL::Modes::AUTO_RETRY).should eq(OpenSSL::SSL::Modes::RELEASE_BUFFERS)
end

it "returns modes" do
context = OpenSSL::SSL::Context::Client.insecure
context.add_modes(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
context.modes.should eq(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
context.add_modes(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
context.modes.should eq(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))
end

it "sets the verify mode" do
6 changes: 2 additions & 4 deletions spec/std/tuple_spec.cr
Original file line number Diff line number Diff line change
@@ -155,8 +155,7 @@ describe "Tuple" do
Tuple(Int32).from([1, 2])
end

# TODO: simplify regex and use TypeCastError after 0.18
expect_raises(Exception, /cast (?:from String )?to Int32 failed/) do
expect_raises(TypeCastError, /cast from String to Int32 failed/) do
Tuple(Int32, String).from(["foo", 1])
end
end
@@ -170,8 +169,7 @@ describe "Tuple" do
{Int32}.from([1, 2])
end

# TODO: simplify regex and use TypeCastError after 0.18
expect_raises(Exception, /cast (?:from String )?to Int32 failed/) do
expect_raises(TypeCastError, /cast from String to Int32 failed/) do
{Int32, String}.from(["foo", 1])
end
end
7 changes: 2 additions & 5 deletions src/hash.cr
Original file line number Diff line number Diff line change
@@ -398,11 +398,8 @@ class Hash(K, V)
# h.key_index("qux") # => nil
# ```
def key_index(key)
# TODO: use each_with_index
i = 0
each do |my_key, my_value|
return i if key == my_key
i += 1
each_with_index do |(my_key, my_value), index|
return index if key == my_key
end
nil
end
5 changes: 1 addition & 4 deletions src/http/headers.cr
Original file line number Diff line number Diff line change
@@ -210,9 +210,7 @@ struct HTTP::Headers

def to_s(io : IO)
io << "HTTP::Headers{"
# TODO: use each_with_index
index = 0
@hash.each do |key, values|
@hash.each_with_index do |(key, values), index|
io << ", " if index > 0
key.name.inspect(io)
io << " => "
@@ -221,7 +219,6 @@ struct HTTP::Headers
else
values.inspect(io)
end
index += 1
end
io << "}"
end
12 changes: 0 additions & 12 deletions src/openssl.cr
Original file line number Diff line number Diff line change
@@ -31,18 +31,6 @@ module OpenSSL
alias X509VerifyFlags = LibCrypto::X509VerifyFlags
{% end %}

# TODO: remove these after 0.18.0

# :nodoc:
macro options_flags(*flags)
LibSSL::Options.flags({{*flags}})
end

# :nodoc:
macro modes_flags(*flags)
LibSSL::Modes.flags({{*flags}})
end

class Error < OpenSSL::Error
getter error : ErrorType

4 changes: 2 additions & 2 deletions src/openssl/ssl/context.cr
Original file line number Diff line number Diff line change
@@ -136,7 +136,7 @@ abstract class OpenSSL::SSL::Context

set_default_verify_paths

add_options(OpenSSL::SSL.options_flags(
add_options(OpenSSL::SSL::Options.flags(
ALL,
NO_SSLV2,
NO_SSLV3,
@@ -145,7 +145,7 @@ abstract class OpenSSL::SSL::Context
SINGLE_DH_USE
))

add_modes(OpenSSL::SSL.modes_flags(AUTO_RETRY, RELEASE_BUFFERS))
add_modes(OpenSSL::SSL::Modes.flags(AUTO_RETRY, RELEASE_BUFFERS))

self.ciphers = CIPHERS

0 comments on commit fd0f67b

Please sign in to comment.