summaryrefslogtreecommitdiffstats
path: root/tests/test_api/test_token.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:24:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-29 04:24:24 +0000
commit12e8343068b906f8b2afddc5569968a8a91fa5b0 (patch)
tree75cc5e05a4392ea0292251898f992a15a16b172b /tests/test_api/test_token.py
parentInitial commit. (diff)
downloadmarkdown-it-py-upstream.tar.xz
markdown-it-py-upstream.zip
Adding upstream version 2.1.0.upstream/2.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_api/test_token.py')
-rw-r--r--tests/test_api/test_token.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_api/test_token.py b/tests/test_api/test_token.py
new file mode 100644
index 0000000..e3806b5
--- /dev/null
+++ b/tests/test_api/test_token.py
@@ -0,0 +1,38 @@
+import warnings
+
+from markdown_it.token import Token
+
+
+def test_token():
+ token = Token("name", "tag", 0)
+ assert token.as_dict() == {
+ "type": "name",
+ "tag": "tag",
+ "nesting": 0,
+ "attrs": None,
+ "map": None,
+ "level": 0,
+ "children": None,
+ "content": "",
+ "markup": "",
+ "info": "",
+ "meta": {},
+ "block": False,
+ "hidden": False,
+ }
+ token.attrSet("a", "b")
+ assert token.attrGet("a") == "b"
+ token.attrJoin("a", "c")
+ assert token.attrGet("a") == "b c"
+ token.attrPush(["x", "y"])
+ assert token.attrGet("x") == "y"
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ assert token.attrIndex("a") == 0
+ assert token.attrIndex("x") == 1
+ assert token.attrIndex("j") == -1
+
+
+def test_serialization():
+ token = Token("name", "tag", 0, children=[Token("other", "tag2", 0)])
+ assert token == Token.from_dict(token.as_dict())