aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream/tag.rs
blob: 0d2ee238d4cbaa764025414bb2fd3770459c2da9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
 * Representation of a Tag
 *
 * SPDX-FileCopyrightText: 2023 Eilertsens Kodeknekkeri
 * SPDX-FileCopyrightText: 2023 Harald Eilertsen <haraldei@anduin.net>
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

use serde::Deserialize;
use url::Url;

#[derive(Debug, Deserialize, PartialEq)]
pub enum TagType {
    #[serde(rename = "hashtag")]
    Hashtag,
}

#[derive(Debug, Deserialize, PartialEq)]
pub struct Tag {
    tag: String,
    url: Url,

    #[serde(rename = "type")]
    tag_type: TagType,
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn test_parsing_tag_from_json() {
        let json = r#"
              {
                "tag": "hubzilla",
                "url": "https://example.com/search?tag=hubzilla",
                "type": "hashtag"
              }
        "#;

        let tag: Tag = serde_json::from_str(json).unwrap();
        assert_eq!("hubzilla", tag.tag);
        assert_eq!("https://example.com/search?tag=hubzilla", tag.url.to_string());
        assert_eq!(TagType::Hashtag, tag.tag_type);
    }
}