Repository: jaytaph/gosub-browser
File: src/testing/tree_construction.rs (Rust)

Code before:

    /// Match a single node and its children
    fn match_node(
        &self,
        node_idx: NodeId,
        document_offset_id: isize,
        indent: isize,
        document: &Document,
    ) -> SubtreeResult {
        let mut next_expected_idx = document_offset_id;

        let node = document.get_node_by_id(node_idx).unwrap();

        let node_result = match &node.data {
            NodeData::DocType(doctype) => {
                let doctype_text =
                    if doctype.pub_identifier.is_empty() && doctype.sys_identifier.is_empty() {
                        // <!DOCTYPE html>
                        doctype.name.to_string()
                    } else {
                        // <!DOCTYPE html "pubid" "sysid">
                        format!(
                            "{} \"{}\" \"{}\"",
                            doctype.name, doctype.pub_identifier, doctype.sys_identifier
                        )
                    };

                let actual = format!(
                    "|{}<!DOCTYPE {}>",
                    " ".repeat(indent as usize * 2 + 1),
                    doctype_text.trim(),
                );

                let expected = self.document[next_expected_idx as usize].to_owned();
                next_expected_idx += 1;

                if actual != expected {
                    let node = Some(NodeResult::DocTypeMatchFailure {
                        actual,
                        expected: "".to_string(),
                    });

                    return SubtreeResult {
                        node,
                        children: vec![],
                        next_expected_idx: None,
                    };
                }

                Some(NodeResult::TextMatchSuccess { expected })
            }

Review comment (suggestion):
```suggestion
            NodeData::DocType(DocTypeData {
                name,
                pub_identifier,
                sys_identifier,
            }) => {
                let doctype_text = if pub_identifier.is_empty() && sys_identifier.is_empty() {
                    // <!DOCTYPE html>
                    name.to_string()
                } else {
                    // <!DOCTYPE html "pubid" "sysid">
                    format!(r#"{name} "{pub_identifier}" "{sys_identifier}""#,)
                };
```

Code after:
    }

    /// Match a single node and its children
    fn match_node(
        &self,
        node_idx: NodeId,
        document_offset_id: isize,
        indent: isize,
        document: &Document,
    ) -> SubtreeResult {
        let mut next_expected_idx = document_offset_id;

        let node = document.get_node_by_id(node_idx).unwrap();

        let node_result = match &node.data {
            NodeData::DocType(DocTypeData {
                name,
                pub_identifier,
                sys_identifier,
            }) => {
                let doctype_text = if pub_identifier.is_empty() && sys_identifier.is_empty() {
                    // <!DOCTYPE html>
                    name.to_string()
                } else {
                    // <!DOCTYPE html "pubid" "sysid">
                    format!(r#"{name} "{pub_identifier}" "{sys_identifier}""#,)
                };

                let actual = format!(
                    "|{}<!DOCTYPE {}>",
                    " ".repeat(indent as usize * 2 + 1),
                    doctype_text.trim(),
                );

                let expected = self.document[next_expected_idx as usize].to_owned();
                next_expected_idx += 1;

                if actual != expected {
                    let node = Some(NodeResult::DocTypeMatchFailure {
                        actual,
                        expected: "".to_string(),
                    });

                    return SubtreeResult {
                        node,
                        children: vec![],
                        next_expected_idx: None,
                    };
                }

                Some(NodeResult::TextMatchSuccess { expected })