Skip to content

Commit e53f75f

Browse files
author
José Valim
committed
Merge pull request #1920 from jwarwick/uri_doctest
Added URI to doc_test list
2 parents 538b830 + cef74d0 commit e53f75f

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

lib/elixir/lib/uri.ex

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,18 @@ defmodule URI do
3131

3232
@doc """
3333
Returns the default port for a given scheme.
34+
3435
If the scheme is unknown to URI, returns `nil`.
3536
Any scheme may be registered via `default_port/2`.
37+
38+
## Examples
39+
40+
iex> URI.default_port("ftp")
41+
21
42+
43+
iex> URI.default_port("ponzi")
44+
nil
45+
3646
"""
3747
def default_port(scheme) when is_binary(scheme) do
3848
{ :ok, dict } = :application.get_env(:elixir, :uri)
@@ -48,39 +58,42 @@ defmodule URI do
4858
end
4959

5060
@doc """
61+
Encodes an enumerable into a query string.
62+
5163
Takes an enumerable (containing a sequence of two-item tuples)
52-
and returns a string of the form "k=v&k2=v2..." where keys and values are
53-
URL encoded as per `encode/1`. Keys and values can be any term
54-
that implements the `String.Chars` protocol (i.e. can be converted
64+
and returns a string of the form "key1=value1&key2=value2..." where
65+
keys and values are URL encoded as per `encode/1`. Keys and values can
66+
be any term that implements the `String.Chars` protocol (i.e. can be converted
5567
to a binary).
5668
5769
## Examples
5870
5971
iex> hd = HashDict.new([{"foo", 1}, {"bar", "2"}])
60-
#HashDict<[{"bar", "2"}, {"foo", 1}]>
6172
iex> URI.encode_query(hd)
6273
"bar=2&foo=1"
6374
6475
"""
6576
def encode_query(l), do: Enum.map_join(l, "&", &pair/1)
6677

6778
@doc """
68-
Given a query string of the form "key1=value1&key=value2...", produces an
79+
Decodes a query string into an orddict.
80+
81+
Given a query string of the form "key1=value1&key2=value2...", produces an
6982
orddict with one entry for each key-value pair. Each key and value will be a
70-
binary. It also does percent-unescaping of both keys and values.
83+
binary. Keys and values will be percent-unescaped.
7184
7285
Use `query_decoder/1` if you want to iterate over each value manually.
7386
7487
## Examples
7588
76-
iex> URI.decode_query("foo=1&bar=2")
77-
#HashDict<[{"bar", "2"}, {"foo", "1"}]>
89+
iex> URI.decode_query("foo=1&bar=2") |> Dict.to_list
90+
[{"bar", "2"}, {"foo", "1"}]
7891
79-
iex> hd = HashDict.new()
92+
> hd = HashDict.new()
8093
#HashDict<[]>
81-
iex> URI.decode_query("foo=1&bar=2", hd) |> HashDict.keys
94+
> URI.decode_query("foo=1&bar=2", hd) |> HashDict.keys
8295
["bar", "foo"]
83-
iex> URI.decode_query("foo=1&bar=2", hd) |> HashDict.values
96+
> URI.decode_query("foo=1&bar=2", hd) |> HashDict.values
8497
["2", "1"]
8598
8699
"""
@@ -201,7 +214,9 @@ defmodule URI do
201214
## Examples
202215
203216
iex> URI.parse("http://elixir-lang.org/")
204-
URI.Info[scheme: "http", path: "/", query: nil, fragment: nil, authority: "elixir-lang.org", userinfo: nil, host: "elixir-lang.org", port: 80]
217+
URI.Info[scheme: "http", path: "/", query: nil, fragment: nil,
218+
authority: "elixir-lang.org", userinfo: nil,
219+
host: "elixir-lang.org", port: 80]
205220
206221
"""
207222
def parse(s) when is_binary(s) do

lib/elixir/test/doc_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ defmodule KernelTest do
2727
doctest Stream
2828
doctest String
2929
doctest Tuple
30+
doctest URI
3031
doctest Version
3132
end

0 commit comments

Comments
 (0)