-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change document methods and add tests
- Loading branch information
Showing
2 changed files
with
107 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import pytest | ||
from beet import DataPack, Function, ResourcePack | ||
|
||
from lectern import Document, InvalidFragment | ||
|
||
|
||
def test_empty(): | ||
assert Document() == Document() | ||
assert Document().data == DataPack() | ||
assert Document().assets == ResourcePack() | ||
assert Document().get_text() == "" | ||
assert Document().get_markdown() == "" | ||
assert Document().get_markdown(emit_files=True) == ("", {}) | ||
|
||
|
||
def test_data_pack(): | ||
pack = DataPack() | ||
doc = Document(data=pack) | ||
assert doc.data is pack | ||
|
||
|
||
def test_resource_pack(): | ||
pack = ResourcePack() | ||
doc = Document(assets=pack) | ||
assert doc.assets is pack | ||
|
||
|
||
def test_text_basic(): | ||
source = "@function demo:foo\nsay hello\n" | ||
assert source in Document(text=source).get_text() | ||
|
||
|
||
def test_text_function(): | ||
pack = DataPack() | ||
pack["demo:foo"] = Function(["say foo"]) | ||
|
||
doc = Document(data=pack) | ||
doc.add_text("@function demo:bar\nsay bar\n") | ||
|
||
assert pack.functions == { | ||
"demo:foo": Function(["say foo"]), | ||
"demo:bar": Function(["say bar"]), | ||
} | ||
|
||
|
||
def test_text_tricky(): | ||
doc = Document( | ||
text="some preamble\n\n" | ||
"@function demo:foo\n" | ||
"say foo\n" | ||
"@other_thing hello world\n" | ||
"say after\n" | ||
" @function not taken into account\n" | ||
"say next\n" | ||
"@function demo:bar\n" | ||
"say bar\n" | ||
) | ||
assert len(doc.data.functions) == 2 | ||
|
||
|
||
def test_missing_argument(): | ||
with pytest.raises( | ||
InvalidFragment, match="Missing directive argument 'full_name'." | ||
): | ||
Document(text="@function\nsay hello") | ||
|
||
|
||
def test_extra_argument(): | ||
with pytest.raises( | ||
InvalidFragment, match="Unexpected directive argument 'banana'." | ||
): | ||
Document(text="@function demo:foo banana\nsay hello") |