-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
require "http/client"
, require "http/server"
instead of `requ…
…ire "net/http"`... Related to #279
- Loading branch information
Ary Borenszweig
committed
Dec 3, 2014
1 parent
5daa4e1
commit b2f6acf
Showing
29 changed files
with
210 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require "net/http" | ||
require "http/client" | ||
require "uri" | ||
require "cgi" | ||
require "secure_random" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require "cgi" | ||
require "net/http" | ||
require "http/client" | ||
require "json" | ||
require "./**" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
spec/std/net/http/client_spec.cr → spec/std/http/client_spec.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require "net/http" | ||
require "http/client" | ||
|
||
module HTTP | ||
{% for method in %w(get post put head delete patch) %} | ||
|
2 changes: 1 addition & 1 deletion
2
spec/std/net/http/common/headers_spec.cr → spec/std/http/headers_spec.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
require "spec" | ||
require "net/http/common" | ||
require "http/headers" | ||
|
||
describe HTTP::Headers do | ||
it "is empty" do | ||
|
2 changes: 1 addition & 1 deletion
2
spec/std/net/http/common/request_spec.cr → spec/std/http/request_spec.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
require "spec" | ||
require "net/http" | ||
require "http/request" | ||
|
||
module HTTP | ||
describe Request do | ||
|
2 changes: 1 addition & 1 deletion
2
spec/std/net/http/common/response_spec.cr → spec/std/http/response_spec.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
require "spec" | ||
require "net/http" | ||
require "http/response" | ||
|
||
module HTTP | ||
describe Response do | ||
|
2 changes: 1 addition & 1 deletion
2
...server/handlers/websocket_handler_spec.cr → ...server/handlers/websocket_handler_spec.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "http/server" | ||
|
||
module HTTP | ||
typeof(begin | ||
server = Server.new(8080) { |req| Response.ok("text/plain", "OK") } | ||
server.listen | ||
server.listen_fork(workers: 2) | ||
server.close | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
require "spec" | ||
require "iterator" | ||
|
||
describe Iterator do | ||
describe "ArrayIterator" do | ||
it "does next" do | ||
a = [1, 2, 3] | ||
iterator = a.iterator | ||
iterator.next.should eq(1) | ||
iterator.next.should eq(2) | ||
iterator.next.should eq(3) | ||
expect_raises StopIteration do | ||
iterator.next | ||
end | ||
end | ||
end | ||
|
||
describe "RangeIterator" do | ||
it "does next with inclusive range" do | ||
a = 1..3 | ||
iterator = a.iterator | ||
iterator.next.should eq(1) | ||
iterator.next.should eq(2) | ||
iterator.next.should eq(3) | ||
expect_raises StopIteration do | ||
iterator.next | ||
end | ||
end | ||
|
||
it "does next with exclusive range" do | ||
r = 1...3 | ||
iterator = r.iterator | ||
iterator.next.should eq(1) | ||
iterator.next.should eq(2) | ||
expect_raises StopIteration do | ||
iterator.next | ||
end | ||
end | ||
end | ||
|
||
describe "IntIterator" do | ||
it "does next with times" do | ||
n = 3 | ||
iterator = n.times | ||
iterator.next.should eq(0) | ||
iterator.next.should eq(1) | ||
iterator.next.should eq(2) | ||
expect_raises StopIteration do | ||
iterator.next | ||
end | ||
end | ||
end | ||
|
||
describe "map" do | ||
it "does map with Range iterator" do | ||
(1..3).iterator.map { |x| x * 2 }.to_a.should eq([2, 4, 6]) | ||
end | ||
end | ||
|
||
describe "select" do | ||
it "does select with Range iterator" do | ||
(1..3).iterator.select { |x| x >= 2 }.to_a.should eq([2, 3]) | ||
end | ||
end | ||
|
||
describe "reject" do | ||
it "does reject with Range iterator" do | ||
(1..3).iterator.reject { |x| x >= 2 }.to_a.should eq([1]) | ||
end | ||
end | ||
|
||
describe "take" do | ||
it "does take with Range iterator" do | ||
(1..3).iterator.take(2).to_a.should eq([1, 2]) | ||
end | ||
|
||
it "does take with more than available" do | ||
(1..3).iterator.take(10).to_a.should eq([1, 2, 3]) | ||
end | ||
end | ||
|
||
describe "skip" do | ||
it "does skip with Range iterator" do | ||
(1..3).iterator.skip(2).to_a.should eq([3]) | ||
end | ||
end | ||
|
||
describe "zip" do | ||
it "does skip with Range iterator" do | ||
r1 = (1..3).iterator | ||
r2 = (4..6).iterator | ||
r1.zip(r2).to_a.should eq([{1, 4}, {2, 5}, {3, 6}]) | ||
end | ||
end | ||
|
||
it "combines many iterators" do | ||
(1..100).iterator | ||
.select { |x| 50 <= x < 60 } | ||
.map { |x| x * 2 } | ||
.take(3) | ||
.to_a | ||
.should eq([100, 102, 104]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require "spec" | ||
require "markdown" | ||
|
||
module Markdown | ||
def self.expect_html(input, output) | ||
it "renders markdown #{input.inspect}" do | ||
render_html(input).should eq(output) | ||
end | ||
end | ||
|
||
describe "Markdown" do | ||
expect_html "Hello", "<p>Hello</p>" | ||
expect_html "Hello\nWorld", "<p>Hello\nWorld</p>" | ||
expect_html "Hello\n\nWorld", "<p>Hello</p>\n<p>World</p>" | ||
expect_html "Hello\n\n\n\n\nWorld", "<p>Hello</p>\n<p>World</p>" | ||
expect_html "Hello *world*", "<p>Hello <em>world</em></p>" | ||
expect_html "Hello _world_", "<p>Hello <em>world</em></p>" | ||
expect_html "Hello *world", "<p>Hello *world</p>" | ||
expect_html "Hello *world\nBye *world", "<p>Hello *world\nBye *world</p>" | ||
expect_html "Hello * world *", "<p>Hello * world *</p>" | ||
expect_html "Hello **world**", "<p>Hello <strong>world</strong></p>" | ||
expect_html "Hello __world__", "<p>Hello <strong>world</strong></p>" | ||
expect_html "Hello **world", "<p>Hello **world</p>" | ||
expect_html "Hello **world\nBye **world", "<p>Hello **world\nBye **world</p>" | ||
expect_html "Hello `world`", "<p>Hello <code>world</code></p>" | ||
expect_html "Hello `world`\nBye `world`", "<p>Hello <code>world</code>\nBye <code>world</code></p>" | ||
expect_html "Hello `world", "<p>Hello `world</p>" | ||
expect_html "Hello *`world`*", "<p>Hello <em><code>world</code></em></p>" | ||
expect_html "Hello *`world`", "<p>Hello *<code>world</code></p>" | ||
|
||
1.upto(6) do |count| | ||
expect_html "#{"#" * count} Hello", "<h#{count}>Hello</h#{count}>" | ||
end | ||
expect_html "####### Hello", "<h6># Hello</h6>" | ||
# expect_html "# One\n# Two", "<h1>One</h1>\n<h1>Two</h1>" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "spec" | ||
require "toml" | ||
|
||
def it_lexes_toml(string, expected_type) | ||
it "lexes #{string}" do | ||
lexer = Toml::Lexer.new string | ||
token = lexer.next_token | ||
token.type.should eq(expected_type) | ||
end | ||
end | ||
|
||
describe "Toml::Lexer" do | ||
it_lexes_toml "", :EOF | ||
it_lexes_toml "[", :"[" | ||
it_lexes_toml "]", :"]" | ||
it_lexes_toml ".", :"." | ||
it_lexes_toml "=", :"=" | ||
it_lexes_toml ",", :"," | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require "./**" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.