From ba008a3ccaf5d1e4f4288429632c9d389e236675 Mon Sep 17 00:00:00 2001 From: Bauke Date: Wed, 21 Jun 2023 12:03:18 +0200 Subject: [PATCH] Add testing for topic parsing. --- tests/samples/topic_deleted.html | 41 ++++++++++++++++++++ tests/samples/topic_link.html | 50 +++++++++++++++++++++++++ tests/samples/topic_scheduled.html | 46 +++++++++++++++++++++++ tests/samples/topic_text.html | 54 +++++++++++++++++++++++++++ tests/snapshots/topic__deleted.snap | 14 +++++++ tests/snapshots/topic__link.snap | 22 +++++++++++ tests/snapshots/topic__scheduled.snap | 18 +++++++++ tests/snapshots/topic__text.snap | 22 +++++++++++ tests/topic.rs | 14 +++++++ 9 files changed, 281 insertions(+) create mode 100644 tests/samples/topic_deleted.html create mode 100644 tests/samples/topic_link.html create mode 100644 tests/samples/topic_scheduled.html create mode 100644 tests/samples/topic_text.html create mode 100644 tests/snapshots/topic__deleted.snap create mode 100644 tests/snapshots/topic__link.snap create mode 100644 tests/snapshots/topic__scheduled.snap create mode 100644 tests/snapshots/topic__text.snap create mode 100644 tests/topic.rs diff --git a/tests/samples/topic_deleted.html b/tests/samples/topic_deleted.html new file mode 100644 index 0000000..6283f1c --- /dev/null +++ b/tests/samples/topic_deleted.html @@ -0,0 +1,41 @@ + + + + + Deleted topic sample for topic.rs + + + +
+
+
+
+ 0 + votes +
+

+ + + +
+
+ +
Topic deleted by author
+ +
+
+
+

2 comments

+
+
+
+
+ + + diff --git a/tests/samples/topic_link.html b/tests/samples/topic_link.html new file mode 100644 index 0000000..2163900 --- /dev/null +++ b/tests/samples/topic_link.html @@ -0,0 +1,50 @@ + + + + + Link topic sample for topic.rs + + + +
+ +
+ + + diff --git a/tests/samples/topic_scheduled.html b/tests/samples/topic_scheduled.html new file mode 100644 index 0000000..b6600a6 --- /dev/null +++ b/tests/samples/topic_scheduled.html @@ -0,0 +1,46 @@ + + + + + Text topic sample for topic.rs + + + +
+
+
+
+ 50 + votes +
+

Scheduled Topic Title

+ + + +
+ Tags: + recurring.weekly +
+
+ +
+

Scheduled Topic Text

+
+ +
+
+
+

100 comments

+
+
+
+
+ + + diff --git a/tests/samples/topic_text.html b/tests/samples/topic_text.html new file mode 100644 index 0000000..06d7947 --- /dev/null +++ b/tests/samples/topic_text.html @@ -0,0 +1,54 @@ + + + + + Text topic sample for topic.rs + + + +
+
+
+
+ 5 + votes +
+

Text Topic Title

+ + + +
+ Tags: + one, + two, + three +
+
+ +
+

Topic Text

+
+ +
+ This topic is locked. New comments can not be posted. +
+ +
+
+
+

15 comments

+
+
+
+
+ + + diff --git a/tests/snapshots/topic__deleted.snap b/tests/snapshots/topic__deleted.snap new file mode 100644 index 0000000..7b9bea9 --- /dev/null +++ b/tests/snapshots/topic__deleted.snap @@ -0,0 +1,14 @@ +--- +source: tests/topic.rs +expression: topic +--- +Topic { + author: Unknown, + comment_total: 2, + content: Unknown, + id: "666", + is_locked: false, + is_official: false, + tags: [], + vote_count: 0, +} diff --git a/tests/snapshots/topic__link.snap b/tests/snapshots/topic__link.snap new file mode 100644 index 0000000..029bbc9 --- /dev/null +++ b/tests/snapshots/topic__link.snap @@ -0,0 +1,22 @@ +--- +source: tests/topic.rs +expression: topic +--- +Topic { + author: Name( + "AnotherUser", + ), + comment_total: 30, + content: Link( + "https://tildes.net/~test", + ), + id: "456", + is_locked: false, + is_official: false, + tags: [ + "four", + "five", + "six", + ], + vote_count: 10, +} diff --git a/tests/snapshots/topic__scheduled.snap b/tests/snapshots/topic__scheduled.snap new file mode 100644 index 0000000..74e134b --- /dev/null +++ b/tests/snapshots/topic__scheduled.snap @@ -0,0 +1,18 @@ +--- +source: tests/topic.rs +expression: topic +--- +Topic { + author: Scheduled, + comment_total: 100, + content: Text( + "

Scheduled Topic Text

", + ), + id: "789", + is_locked: false, + is_official: false, + tags: [ + "recurring.weekly", + ], + vote_count: 50, +} diff --git a/tests/snapshots/topic__text.snap b/tests/snapshots/topic__text.snap new file mode 100644 index 0000000..09348ff --- /dev/null +++ b/tests/snapshots/topic__text.snap @@ -0,0 +1,22 @@ +--- +source: tests/topic.rs +expression: topic +--- +Topic { + author: Name( + "User", + ), + comment_total: 15, + content: Text( + "

Topic Text

", + ), + id: "123", + is_locked: true, + is_official: false, + tags: [ + "one", + "two", + "three", + ], + vote_count: 5, +} diff --git a/tests/topic.rs b/tests/topic.rs new file mode 100644 index 0000000..1a80506 --- /dev/null +++ b/tests/topic.rs @@ -0,0 +1,14 @@ +use std::fs::read_to_string; + +use {insta::assert_debug_snapshot, tildes_parser::Topic}; + +#[test] +fn test_topic_parsing() { + let samples = ["link", "text", "deleted", "scheduled"]; + for sample in samples { + let html = + read_to_string(format!("tests/samples/topic_{sample}.html")).unwrap(); + let topic = &html.parse::().unwrap(); + assert_debug_snapshot!(sample, topic); + } +}