Repository: jaytaph/gosub-browser
File: src/html5_parser/parser/mod.rs (Rust)

Code before:
        assert_eq!(parser.is_in_scope("select", Scope::Select), true);
    }

    #[test]
    fn reconstruct_formatting() {
        let mut stream = InputStream::new();
        stream.read_from_str(
            "<p><b>bold<i>bold and italic</b>italic</i></p>",
            Some(Encoding::UTF8),
        );

        let mut parser = Html5Parser::new(&mut stream);
        parser.parse();

        println!("{}", parser.document);
    }

    #[test]
    fn element_no_classes() {
        let mut stream = InputStream::new();
        stream.read_from_str("<div></div>", Some(Encoding::UTF8));

        let mut parser = Html5Parser::new(&mut stream);
        let (doc, _) = parser.parse();

        assert_eq!(doc.get_root().classes.is_none(), true);
    }

    #[test]
    fn element_with_classes() {
        let mut stream = InputStream::new();
        stream.read_from_str("<div class=\"one two three\"></div>", Some(Encoding::UTF8));

        let mut parser = Html5Parser::new(&mut stream);
        let (doc, _) = parser.parse();

        // document -> html -> head -> body -> div
        let div = doc.get_node_by_id(NodeId(4)).unwrap();
        assert!(div.classes.is_some());

        if let Some(&ref classes) = div.classes.as_ref() {
            assert_eq!(classes.len(), 3);

            assert_eq!(classes.contains("one"), true);
            assert_eq!(classes.contains("two"), true);
            assert_eq!(classes.contains("three"), true);

            assert_eq!(classes.is_active("one"), true);
            assert_eq!(classes.is_active("two"), true);
            assert_eq!(classes.is_active("three"), true);
        }

Review comment (suggestion):
This and elsewhere would be
```rust
assert!(doc.get_root().classes.is_none());
```

I wonder whether you would get this automatically by running `cargo clippy --fix`.

Code after:
        assert!(parser.is_in_scope("select", Scope::Select));
    }

    #[test]
    fn reconstruct_formatting() {
        let mut stream = InputStream::new();
        stream.read_from_str(
            "<p><b>bold<i>bold and italic</b>italic</i></p>",
            Some(Encoding::UTF8),
        );

        let mut parser = Html5Parser::new(&mut stream);
        parser.parse();

        println!("{}", parser.document);
    }

    #[test]
    fn element_no_classes() {
        let mut stream = InputStream::new();
        stream.read_from_str("<div></div>", Some(Encoding::UTF8));

        let mut parser = Html5Parser::new(&mut stream);
        let (doc, _) = parser.parse();

        assert!(doc.get_root().classes.is_none());
    }

    #[test]
    fn element_with_classes() {
        let mut stream = InputStream::new();
        stream.read_from_str("<div class=\"one two three\"></div>", Some(Encoding::UTF8));

        let mut parser = Html5Parser::new(&mut stream);
        let (doc, _) = parser.parse();

        // document -> html -> head -> body -> div
        let div = doc.get_node_by_id(NodeId(4)).unwrap();
        assert!(div.classes.is_some());

        if let Some(classes) = div.classes.as_ref() {
            assert_eq!(classes.len(), 3);

            assert!(classes.contains("one"));
            assert!(classes.contains("two"));
            assert!(classes.contains("three"));

            assert!(classes.is_active("one"));
            assert!(classes.is_active("two"));
            assert!(classes.is_active("three"));
        }