Refactor modules into contexts (#78)
* [WIP] break out a few contexts, start refactoring fast index modules * [WIP] more contexts, this time around slow indexing and downloads * [WIP] got all tests passing * [WIP] Added moduledocs * Built a genserver to rename old jobs on boot * Added a module naming check; moved things around * Fixed specs
This commit is contained in:
1 parent
7fa5c4da63
commit
33baa99aae
66 files changed
+1092
-568
No files matched your search
@@ -0,0 +1,48 @@
|
||||
defmodule Pinchflat.Downloading.OutputPath.ParserTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Pinchflat.Downloading.OutputPath.Parser
|
||||
|
||||
describe "parse/3" do
|
||||
test "it returns the rendered string when the string is valid" do
|
||||
assert {:ok, "bar"} = Parser.parse("{{ foo }}", %{"foo" => "bar"})
|
||||
end
|
||||
|
||||
test "it works with filepath-like strings" do
|
||||
assert {:ok, "bar/baz"} =
|
||||
Parser.parse("{{ foo }}/{{ bar }}", %{"foo" => "bar", "bar" => "baz"})
|
||||
end
|
||||
|
||||
test "it works when mixing text and variables" do
|
||||
assert {:ok, "bar text baz"} =
|
||||
Parser.parse("{{ foo }} text {{ bar }}", %{"foo" => "bar", "bar" => "baz"})
|
||||
end
|
||||
|
||||
test "it removes the placeholder but doesn't blow up when the variable isn't provided" do
|
||||
assert {:ok, ""} = Parser.parse("{{ foo }}", %{})
|
||||
end
|
||||
|
||||
test "it accepts any number of spaces between open and closing tags" do
|
||||
assert {:ok, "bar"} = Parser.parse("{{foo}}", %{"foo" => "bar"})
|
||||
assert {:ok, "bar"} = Parser.parse("{{ foo}}", %{"foo" => "bar"})
|
||||
assert {:ok, "bar"} = Parser.parse("{{foo }}", %{"foo" => "bar"})
|
||||
assert {:ok, "bar"} = Parser.parse("{{ foo }}", %{"foo" => "bar"})
|
||||
end
|
||||
|
||||
test "it doesn't interpret single braces as variables" do
|
||||
assert {:ok, "{foo}"} = Parser.parse("{foo}", %{})
|
||||
end
|
||||
|
||||
test "it returns an error when the string is invalid" do
|
||||
assert {:error, "expected end of string"} = Parser.parse("{{ 1-1 }", %{})
|
||||
end
|
||||
|
||||
test "it supports a custom fetcher function" do
|
||||
custom_fetcher = fn _, _ ->
|
||||
"quux"
|
||||
end
|
||||
|
||||
assert {:ok, "quux"} = Parser.parse("{{ foo }}", %{}, custom_fetcher)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user