html5ever_atoms/
lib.rs

1// Copyright 2016 The html5ever Project Developers. See the
2// COPYRIGHT file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10#![cfg_attr(feature = "heap_size", feature(proc_macro))]
11#[cfg(feature = "heap_size")] #[macro_use] extern crate heapsize_derive;
12#[cfg(feature = "heap_size")] extern crate heapsize;
13extern crate string_cache;
14
15include!(concat!(env!("OUT_DIR"), "/generated.rs"));
16
17#[macro_export]
18macro_rules! qualname {
19    ("", $local:tt) => {
20        $crate::QualName {
21            ns: ns!(),
22            local: local_name!($local),
23        }
24    };
25    ($ns:tt, $local:tt) => {
26        $crate::QualName {
27            ns: ns!($ns),
28            local: local_name!($local),
29        }
30    }
31}
32
33/// A name with a namespace.
34#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)]
35#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
36pub struct QualName {
37    pub ns: Namespace,
38    pub local: LocalName,
39}
40
41impl QualName {
42    #[inline]
43    pub fn new(ns: Namespace, local: LocalName) -> QualName {
44        QualName {
45            ns: ns,
46            local: local,
47        }
48    }
49}
50
51#[cfg(test)]
52mod tests {
53    use super::{Namespace, QualName};
54    use LocalName;
55
56    #[test]
57    fn ns_macro() {
58        assert_eq!(ns!(),       Namespace::from(""));
59
60        assert_eq!(ns!(html),   Namespace::from("http://www.w3.org/1999/xhtml"));
61        assert_eq!(ns!(xml),    Namespace::from("http://www.w3.org/XML/1998/namespace"));
62        assert_eq!(ns!(xmlns),  Namespace::from("http://www.w3.org/2000/xmlns/"));
63        assert_eq!(ns!(xlink),  Namespace::from("http://www.w3.org/1999/xlink"));
64        assert_eq!(ns!(svg),    Namespace::from("http://www.w3.org/2000/svg"));
65        assert_eq!(ns!(mathml), Namespace::from("http://www.w3.org/1998/Math/MathML"));
66    }
67
68    #[test]
69    fn qualname() {
70        assert_eq!(QualName::new(ns!(), local_name!("")),
71                   QualName { ns: ns!(), local: LocalName::from("") });
72        assert_eq!(QualName::new(ns!(xml), local_name!("base")),
73                   QualName { ns: ns!(xml), local: local_name!("base") });
74    }
75
76    #[test]
77    fn qualname_macro() {
78        assert_eq!(qualname!("", ""), QualName { ns: ns!(), local: local_name!("") });
79        assert_eq!(qualname!(xml, "base"), QualName { ns: ns!(xml), local: local_name!("base") });
80    }
81}