Add testing for topic parsing.
This commit is contained in:
parent
773a075edf
commit
ba008a3cca
|
@ -0,0 +1,41 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Deleted topic sample for topic.rs</title>
|
||||
</head>
|
||||
|
||||
<body class="theme-white">
|
||||
<main>
|
||||
<article id="topic-666" class="topic-full">
|
||||
<header>
|
||||
<div class="topic-voting">
|
||||
<span class="topic-voting-votes">0</span>
|
||||
<span class="topic-voting-label">votes</span>
|
||||
</div>
|
||||
<h1></h1>
|
||||
|
||||
<div class="topic-full-byline">
|
||||
Posted
|
||||
<time class="time-responsive" datetime="2018-04-26T21:22:47Z"
|
||||
title="2018-04-26 21:22:47 UTC" data-abbreviated="Apr 26, 2018">
|
||||
<span class="time-responsive-full">April 26, 2018</span>
|
||||
</time> by unknown user
|
||||
</div>
|
||||
|
||||
<div class="topic-full-tags"></div>
|
||||
</header>
|
||||
|
||||
<div class="text-error">Topic deleted by author</div>
|
||||
|
||||
<section class="topic-comments">
|
||||
<div class="divider"></div>
|
||||
<header class="topic-comments-header">
|
||||
<h2>2 comments</h2>
|
||||
</header>
|
||||
</section>
|
||||
</article>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,50 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Link topic sample for topic.rs</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<article id="topic-456" class="topic-full">
|
||||
<header>
|
||||
<div class="topic-voting">
|
||||
<span class="topic-voting-votes">10</span>
|
||||
<span class="topic-voting-label">votes</span>
|
||||
</div>
|
||||
<h1>Link Topic Title</h1>
|
||||
|
||||
<div class="topic-full-byline">
|
||||
Posted
|
||||
<time class="time-responsive" datetime="2021-12-16T17:26:03Z"
|
||||
title="2021-12-16 17:26:03 UTC" data-abbreviated="Dec 16, 2021">
|
||||
<span class="time-responsive-full">December 16, 2021</span>
|
||||
</time>
|
||||
by
|
||||
<a href="/user/AnotherUser" class="link-user">AnotherUser</a>
|
||||
</div>
|
||||
|
||||
<div class="topic-full-tags">
|
||||
Tags:
|
||||
<a href="/~group?tag=four">four</a>,
|
||||
<a href="/~group?tag=five">five</a>,
|
||||
<a href="/~group?tag=six">six</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="topic-full-link">
|
||||
<a href="https://tildes.net/~test">https://tildes.net/~test</a>
|
||||
</div>
|
||||
|
||||
<section class="topic-comments">
|
||||
<div class="divider"></div>
|
||||
<header class="topic-comments-header">
|
||||
<h2>30 comments</h2>
|
||||
</header>
|
||||
</section>
|
||||
</article>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,46 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Text topic sample for topic.rs</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<article id="topic-789" class="topic-full">
|
||||
<header>
|
||||
<div class="topic-voting">
|
||||
<span class="topic-voting-votes">50</span>
|
||||
<span class="topic-voting-label">votes</span>
|
||||
</div>
|
||||
<h1>Scheduled Topic Title</h1>
|
||||
|
||||
<div class="topic-full-byline">
|
||||
Automatically posted
|
||||
<time class="time-responsive" datetime="2022-12-16T17:26:03Z"
|
||||
title="2022-12-16 17:26:03 UTC" data-abbreviated="Dec 16, 2022">
|
||||
<span class="time-responsive-full">December 16, 2022</span>
|
||||
</time>
|
||||
</div>
|
||||
|
||||
<div class="topic-full-tags">
|
||||
Tags:
|
||||
<a href="/~group?tag=recurring">recurring.weekly</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="topic-full-text">
|
||||
<p>Scheduled Topic Text</p>
|
||||
</div>
|
||||
|
||||
<section class="topic-comments">
|
||||
<div class="divider"></div>
|
||||
<header class="topic-comments-header">
|
||||
<h2>100 comments</h2>
|
||||
</header>
|
||||
</section>
|
||||
</article>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -0,0 +1,54 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<title>Text topic sample for topic.rs</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<article id="topic-123" class="topic-full">
|
||||
<header>
|
||||
<div class="topic-voting">
|
||||
<span class="topic-voting-votes">5</span>
|
||||
<span class="topic-voting-label">votes</span>
|
||||
</div>
|
||||
<h1>Text Topic Title</h1>
|
||||
|
||||
<div class="topic-full-byline">
|
||||
Posted
|
||||
<time class="time-responsive" datetime="2022-12-16T17:26:03Z"
|
||||
title="2022-12-16 17:26:03 UTC" data-abbreviated="Dec 16, 2022">
|
||||
<span class="time-responsive-full">December 16, 2022</span>
|
||||
</time>
|
||||
by
|
||||
<a href="/user/User" class="link-user">User</a>
|
||||
</div>
|
||||
|
||||
<div class="topic-full-tags">
|
||||
Tags:
|
||||
<a href="/~group?tag=one">one</a>,
|
||||
<a href="/~group?tag=two">two</a>,
|
||||
<a href="/~group?tag=three">three</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="topic-full-text">
|
||||
<p>Topic Text</p>
|
||||
</div>
|
||||
|
||||
<div class="toast toast-warning">
|
||||
This topic is locked. New comments can not be posted.
|
||||
</div>
|
||||
|
||||
<section class="topic-comments">
|
||||
<div class="divider"></div>
|
||||
<header class="topic-comments-header">
|
||||
<h2>15 comments</h2>
|
||||
</header>
|
||||
</section>
|
||||
</article>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -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,
|
||||
}
|
|
@ -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,
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
source: tests/topic.rs
|
||||
expression: topic
|
||||
---
|
||||
Topic {
|
||||
author: Scheduled,
|
||||
comment_total: 100,
|
||||
content: Text(
|
||||
"<p>Scheduled Topic Text</p>",
|
||||
),
|
||||
id: "789",
|
||||
is_locked: false,
|
||||
is_official: false,
|
||||
tags: [
|
||||
"recurring.weekly",
|
||||
],
|
||||
vote_count: 50,
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
source: tests/topic.rs
|
||||
expression: topic
|
||||
---
|
||||
Topic {
|
||||
author: Name(
|
||||
"User",
|
||||
),
|
||||
comment_total: 15,
|
||||
content: Text(
|
||||
"<p>Topic Text</p>",
|
||||
),
|
||||
id: "123",
|
||||
is_locked: true,
|
||||
is_official: false,
|
||||
tags: [
|
||||
"one",
|
||||
"two",
|
||||
"three",
|
||||
],
|
||||
vote_count: 5,
|
||||
}
|
|
@ -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::<Topic>().unwrap();
|
||||
assert_debug_snapshot!(sample, topic);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue