Page MenuHomePhorge

No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/test/tesla/middleware/path_params_test.exs b/test/tesla/middleware/path_params_test.exs
index 886c7c8..a6a0da6 100644
--- a/test/tesla/middleware/path_params_test.exs
+++ b/test/tesla/middleware/path_params_test.exs
@@ -1,37 +1,61 @@
defmodule Tesla.Middleware.PathParamsTest do
use ExUnit.Case, async: true
alias Tesla.Env
@middleware Tesla.Middleware.PathParams
test "no params" do
assert {:ok, env} = @middleware.call(%Env{url: "/users/:id"}, [], nil)
assert env.url == "/users/:id"
end
test "passed params" do
opts = [path_params: [id: 42]]
assert {:ok, env} = @middleware.call(%Env{url: "/users/:id", opts: opts}, [], nil)
assert env.url == "/users/42"
end
test "value is not given" do
opts = [path_params: [y: 42]]
assert {:ok, env} = @middleware.call(%Env{url: "/users/:x", opts: opts}, [], nil)
assert env.url == "/users/:x"
end
test "value is nil" do
opts = [path_params: [id: nil]]
assert {:ok, env} = @middleware.call(%Env{url: "/users/:id", opts: opts}, [], nil)
assert env.url == "/users/:id"
end
test "placeholder contains another placeholder" do
opts = [path_params: [id: 1, id_post: 2]]
assert {:ok, env} = @middleware.call(%Env{url: "/users/:id/p/:id_post", opts: opts}, [], nil)
assert env.url == "/users/1/p/2"
end
+
+ test "placeholder start by number" do
+ opts = [path_params: ["1id": 1, id_post: 2]]
+
+ assert {:ok, env} = @middleware.call(%Env{url: "/users/:1id/p/:id_post", opts: opts}, [], nil)
+
+ assert env.url == "/users/:1id/p/2"
+ end
+
+ test "placeholder with only 1 character" do
+ opts = [path_params: [i: 1, id_post: 2]]
+
+ assert {:ok, env} = @middleware.call(%Env{url: "/users/:i/p/:id_post", opts: opts}, [], nil)
+
+ assert env.url == "/users/1/p/2"
+ end
+
+ test "placeholder with numbers, underscore and characters" do
+ opts = [path_params: [id_1_a: 1, id_post: 2]]
+
+ assert {:ok, env} = @middleware.call(%Env{url: "/users/:id_1_a/p/:id_post", opts: opts}, [], nil)
+
+ assert env.url == "/users/1/p/2"
+ end
end

File Metadata

Mime Type
text/x-diff
Expires
Mon, Nov 25, 10:04 PM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40089
Default Alt Text
(2 KB)

Event Timeline