diff --git a/tests/test_replybuilder.py b/tests/test_replybuilder.py
new file mode 100644
index 0000000..9266e75
--- /dev/null
+++ b/tests/test_replybuilder.py
@@ -0,0 +1,105 @@
+from datetime import timedelta
+from django.test import TestCase
+from board.models import Board, Post
+from board.templatetags.post_body import ReplyBuilder
+
+
+class ReplyBuilderTestCase(TestCase):
+ def setUp(self):
+ Board.objects.create(
+ url="test", name="test", post_cooldown=timedelta(seconds=0)
+ )
+
+ def test_quote(self):
+ expected = [
+ (
+ "this is some text that shouldn't be quoted.",
+ "this is some text that shouldn't be quoted.",
+ ),
+ (
+ ">implying this quotes text correctly",
+ '>implying this quotes text correctly',
+ ),
+ (
+ ">implying this >quotes >text correctly",
+ '>implying this >quotes >text correctly',
+ ),
+ (
+ """
+>implying this quotes text correctly
+nothing ever changes
+""",
+ '>implying this quotes text correctly
nothing ever changes',
+ ),
+ (
+ """
+what happened to the 1 2 3 4 5 6 7 8 9
+>implying this quotes text correctly
+nothing ever changes
+""",
+ 'what happened to the 1 2 3 4 5 6 7 8 9
>implying this quotes text correctly
nothing ever changes',
+ ),
+ (
+ """
+nothing ever changes
+>implying this quotes text correctly
+what happened to the 1 2 3 4 5 6 7 8 9
+""",
+ 'nothing ever changes
>implying this quotes text correctly
what happened to the 1 2 3 4 5 6 7 8 9',
+ ),
+ ]
+
+ for input, output in expected:
+ rb = ReplyBuilder(input.strip())
+ self.assertEquals(rb.build(), output)
+
+ def test_reply(self):
+ board = Board.objects.get(url="test")
+ post1 = Post.objects.create(board=board, text="test 1", ip="127.0.0.1")
+ post2 = Post.objects.create(board=board, text="test 1", ip="127.0.0.1")
+ post3 = Post.objects.create(board=board, text="test 1", ip="127.0.0.1")
+
+ expected = [
+ (
+ f">>{post1.id}",
+ f'>>{post1.id}',
+ ),
+ (
+ f">>{post2.id}",
+ f'>>{post2.id}',
+ ),
+ (
+ f">>{post1.id} >>{post2.id} >>{post3.id}",
+ f'>>{post1.id} '
+ f'>>{post2.id} '
+ f'>>{post3.id}',
+ ),
+ (
+ f">>999999",
+ f'>>999999',
+ ),
+ ]
+
+ for input, output in expected:
+ rb = ReplyBuilder(input.strip())
+ self.assertEquals(rb.build(), output)
+
+ def test_spoiler(self):
+ expected = [
+ (
+ "[spoiler]This is a spoiler[/spoiler]",
+ 'This is a spoiler',
+ ),
+ (
+ r"\[spoiler]This is an escaped spoiler[/spoiler]",
+ "[spoiler]This is an escaped spoiler[/spoiler]",
+ ),
+ (
+ "[spoiler]This is an unfinished spoiler",
+ 'This is an unfinished spoiler',
+ ),
+ ]
+
+ for input, output in expected:
+ rb = ReplyBuilder(input.strip(), parse_spoilers=True)
+ self.assertEquals(rb.build(), output)