Skip to content

Commit

Permalink
add .new and .empty? to HTTP::Params (#6241)
Browse files Browse the repository at this point in the history
  • Loading branch information
icyleaf authored and RX14 committed Jul 3, 2018
1 parent ae32184 commit 75b46ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/std/http/params_spec.cr
Expand Up @@ -3,6 +3,10 @@ require "http/params"

module HTTP
describe Params do
describe ".new" do
Params.new.should eq(Params.parse(""))
end

describe ".parse" do
{
{"", {} of String => Array(String)},
Expand Down Expand Up @@ -250,5 +254,13 @@ module HTTP
end
end
end

describe "#empty?" do
it "test empty?" do
Params.parse("foo=bar&foo=baz&baz=qux").empty?.should be_false
Params.parse("").empty?.should be_true
Params.new.empty?.should be_true
end
end
end
end
13 changes: 13 additions & 0 deletions src/http/params.cr
Expand Up @@ -124,6 +124,11 @@ module HTTP

protected getter raw_params

# Returns an empty `HTTP::Params`.
def initialize
@raw_params = {} of String => Array(String)
end

def initialize(@raw_params : Hash(String, Array(String)))
end

Expand Down Expand Up @@ -164,6 +169,14 @@ module HTTP
# ```
delegate has_key?, to: raw_params

# Return `true` if params is empty.
#
# ```
# Params.new.empty? # => true
# Params.parse("foo=bar&foo=baz&qux=zoo").empty? # => false
# ```
delegate empty?, to: raw_params

# Sets first *value* for specified param *name*.
#
# ```
Expand Down

0 comments on commit 75b46ac

Please sign in to comment.