Skip to content

Commit

Permalink
Move all rcdom-related tests to markup5ever_rcdom
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Oct 22, 2019
1 parent 040a4dd commit 7e87faf
Show file tree
Hide file tree
Showing 29 changed files with 324 additions and 418 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "html5lib-tests"]
path = html5ever/html5lib-tests
path = rcdom/html5lib-tests
url = https://github.com/html5lib/html5lib-tests
[submodule "xml5lib-tests"]
path = xml5ever/xml5lib-tests
path = rcdom/xml5lib-tests
url = https://github.com/Ygg01/xml5lib-tests
19 changes: 0 additions & 19 deletions html5ever/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,14 @@ build = "build.rs"
categories = [ "parser-implementations", "web-programming" ]
edition = "2018"

[lib]
name = "html5ever"

doctest = true

[[test]]
name = "tree_builder"
harness = false

[[test]]
name = "tokenizer"
harness = false

[[test]]
name = "serializer"

[dependencies]
log = "0.4"
mac = "0.1"
markup5ever = { version = "0.10", path = "../markup5ever" }

[dev-dependencies]
serde_json = "1.0"
rustc-test = "0.3"
typed-arena = "1.3.0"
criterion = "0.3"
markup5ever_rcdom = { version = "0.1", path = "../rcdom" }

[build-dependencies]
quote = "1"
Expand Down
2 changes: 1 addition & 1 deletion html5ever/benches/html5ever.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use criterion::{black_box, Criterion};

use html5ever::tendril::*;
use html5ever::tokenizer::{
BufferQueue, Token, TokenSink, TokenSinkResult, Tokenizer, TokenizerOpts,
BufferQueue, Token, TokenSink, TokenSinkResult, Tokenizer,
};

struct Sink;
Expand Down
23 changes: 0 additions & 23 deletions html5ever/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,3 @@ impl<Sink: TreeSink> Parser<Sink> {
Utf8LossyDecoder::new(self)
}
}

#[cfg(test)]
mod tests {
extern crate markup5ever_rcdom;
use super::*;
use self::markup5ever_rcdom::{RcDom, SerializableHandle};
use crate::serialize::serialize;
use tendril::TendrilSink;

#[test]
fn from_utf8() {
let dom = parse_document(RcDom::default(), ParseOpts::default())
.from_utf8()
.one("<title>Test".as_bytes());
let mut serialized = Vec::new();
let document: SerializableHandle = dom.document.clone().into();
serialize(&mut serialized, &document, Default::default()).unwrap();
assert_eq!(
String::from_utf8(serialized).unwrap().replace(" ", ""),
"<html><head><title>Test</title></head><body></body></html>"
);
}
}
168 changes: 0 additions & 168 deletions html5ever/src/tree_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,171 +1679,3 @@ where
}
}
}

#[cfg(test)]
#[allow(non_snake_case)]
mod test {
extern crate markup5ever_rcdom as rcdom;
use markup5ever::interface::{AppendNode, AppendText, NodeOrText};
use markup5ever::interface::{ElementFlags, Tracer, TreeSink};
use markup5ever::interface::{LimitedQuirks, NoQuirks, Quirks, QuirksMode};

use super::types::*;

use crate::tendril::stream::{TendrilSink, Utf8LossyDecoder};
use crate::tendril::StrTendril;
use crate::ExpandedName;
use crate::QualName;

use crate::tokenizer;
use crate::tokenizer::states as tok_state;
use crate::tokenizer::{Doctype, StartTag, Tag, TokenSink};
use crate::tokenizer::{Tokenizer, TokenizerOpts};
use crate::driver::*;

use crate::util::str::is_ascii_whitespace;

use std::borrow::Cow;
use std::borrow::Cow::Borrowed;
use std::collections::VecDeque;
use std::default::Default;
use std::mem::replace;

use super::{TreeBuilder, TreeBuilderOpts};
use markup5ever::{Attribute, local_name, namespace_url, ns};
use self::rcdom::{Handle, Node, NodeData, RcDom};

pub struct LineCountingDOM {
pub line_vec: Vec<(QualName, u64)>,
pub current_line: u64,
pub rcdom: RcDom,
}

impl TreeSink for LineCountingDOM {
type Output = Self;

fn finish(self) -> Self {
self
}

type Handle = Handle;

fn parse_error(&mut self, msg: Cow<'static, str>) {
self.rcdom.parse_error(msg);
}

fn get_document(&mut self) -> Handle {
self.rcdom.get_document()
}

fn get_template_contents(&mut self, target: &Handle) -> Handle {
self.rcdom.get_template_contents(target)
}

fn set_quirks_mode(&mut self, mode: QuirksMode) {
self.rcdom.set_quirks_mode(mode)
}

fn same_node(&self, x: &Handle, y: &Handle) -> bool {
self.rcdom.same_node(x, y)
}

fn elem_name<'a>(&'a self, target: &'a Handle) -> ExpandedName<'a> {
self.rcdom.elem_name(target)
}

fn create_element(
&mut self,
name: QualName,
attrs: Vec<Attribute>,
flags: ElementFlags,
) -> Handle {
self.line_vec.push((name.clone(), self.current_line));
self.rcdom.create_element(name, attrs, flags)
}

fn create_comment(&mut self, text: StrTendril) -> Handle {
self.rcdom.create_comment(text)
}

fn create_pi(&mut self, target: StrTendril, content: StrTendril) -> Handle {
self.rcdom.create_pi(target, content)
}

fn append(&mut self, parent: &Handle, child: NodeOrText<Handle>) {
self.rcdom.append(parent, child)
}

fn append_before_sibling(&mut self, sibling: &Handle, child: NodeOrText<Handle>) {
self.rcdom.append_before_sibling(sibling, child)
}

fn append_based_on_parent_node(
&mut self,
element: &Handle,
prev_element: &Handle,
child: NodeOrText<Handle>,
) {
self.rcdom
.append_based_on_parent_node(element, prev_element, child)
}

fn append_doctype_to_document(
&mut self,
name: StrTendril,
public_id: StrTendril,
system_id: StrTendril,
) {
self.rcdom
.append_doctype_to_document(name, public_id, system_id);
}

fn add_attrs_if_missing(&mut self, target: &Handle, attrs: Vec<Attribute>) {
self.rcdom.add_attrs_if_missing(target, attrs);
}

fn remove_from_parent(&mut self, target: &Handle) {
self.rcdom.remove_from_parent(target);
}

fn reparent_children(&mut self, node: &Handle, new_parent: &Handle) {
self.rcdom.reparent_children(node, new_parent);
}

fn mark_script_already_started(&mut self, target: &Handle) {
self.rcdom.mark_script_already_started(target);
}

fn set_current_line(&mut self, line_number: u64) {
self.current_line = line_number;
}
}

#[test]
fn check_four_lines() {
// Input
let sink = LineCountingDOM {
line_vec: vec![],
current_line: 1,
rcdom: RcDom::default(),
};
let opts = ParseOpts::default();
let mut resultTok = parse_document(sink, opts);
resultTok.process(StrTendril::from("<a>\n"));
resultTok.process(StrTendril::from("</a>\n"));
resultTok.process(StrTendril::from("<b>\n"));
resultTok.process(StrTendril::from("</b>"));
// Actual Output
let actual = resultTok.finish();
// Expected Output
let expected = vec![
(QualName::new(None, ns!(html), local_name!("html")), 1),
(QualName::new(None, ns!(html), local_name!("head")), 1),
(QualName::new(None, ns!(html), local_name!("body")), 1),
(QualName::new(None, ns!(html), local_name!("a")), 1),
(QualName::new(None, ns!(html), local_name!("b")), 3),
];
// Assertion
assert_eq!(actual.line_vec, expected);
}
}
3 changes: 0 additions & 3 deletions markup5ever/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,3 @@ phf_codegen = "0.8"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"

[dev-dependencies]
markup5ever_rcdom = { version = "0.1", path = "../rcdom" }
26 changes: 0 additions & 26 deletions markup5ever/interface/tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,32 +80,6 @@ pub struct ElementFlags {
/// # Examples
///
/// Create an element like `<div class="test-class-name"></div>`:
///
/// ```
/// # #[macro_use] extern crate markup5ever;
/// # extern crate markup5ever_rcdom as rcdom;
///
/// # fn main() {
/// use markup5ever::{QualName, Attribute};
/// use markup5ever::interface::create_element;
///
/// let mut dom = rcdom::RcDom::default();
/// let el = create_element(&mut dom,
/// // Namespaces and localnames use precomputed interned strings for
/// // speed. Use the macros ns! and local_name! to fetch them.
/// QualName::new(None, ns!(), local_name!("div")),
/// vec![
/// Attribute {
/// name: QualName::new(None, ns!(), local_name!("class")),
/// // In real scenarios, you would use a view onto an existing
/// // string if possible to avoid allocation. Tendrils have utilities
/// // for avoiding allocation & copying wherever possible.
/// value: String::from("test-class-name").into()
/// }
/// ]);
/// # }
///
/// ```
pub fn create_element<Sink>(sink: &mut Sink, name: QualName, attrs: Vec<Attribute>) -> Sink::Handle
where
Sink: TreeSink,
Expand Down
26 changes: 25 additions & 1 deletion rcdom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,34 @@ description = "Basic, unsupported DOM structure for use by tests in html5ever/xm
readme = "README.md"
documentation = "https://docs.rs/markup5ever_rcdom"
categories = [ "parser-implementations", "web-programming" ]
edition = "2018"
publish = false

[lib]
path = "lib.rs"

[dependencies]
tendril = "0.4"
markup5ever = { version = "0.10", path = "../markup5ever" }
html5ever = { version = "0.25", path = "../html5ever" }
markup5ever = { version = "0.10", path = "../markup5ever" }
xml5ever = { version = "0.16", path = "../xml5ever" }

[dev-dependencies]
serde_json = "1.0"
rustc-test = "0.3"

[[test]]
name = "html-tokenizer"
harness = false

[[test]]
name = "html-tree-builder"
harness = false

[[test]]
name = "xml-tree-builder"
harness = false

[[test]]
name = "xml-tokenizer"
harness = false
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions rcdom/tests/html-driver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use html5ever::driver;
use html5ever::serialize;
use html5ever::tendril::TendrilSink;
use markup5ever_rcdom::{RcDom, SerializableHandle};

#[test]
fn from_utf8() {
let dom = driver::parse_document(RcDom::default(), Default::default())
.from_utf8()
.one("<title>Test".as_bytes());
let mut serialized = Vec::new();
let document: SerializableHandle = dom.document.clone().into();
serialize::serialize(&mut serialized, &document, Default::default()).unwrap();
assert_eq!(
String::from_utf8(serialized).unwrap().replace(" ", ""),
"<html><head><title>Test</title></head><body></body></html>"
);
}
10 changes: 2 additions & 8 deletions html5ever/tests/serializer.rs → rcdom/tests/html-serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[macro_use]
extern crate html5ever;
extern crate markup5ever_rcdom as rcdom;

use std::default::Default;

use html5ever::driver::ParseOpts;
use html5ever::serialize::{Serialize, SerializeOpts, Serializer, TraversalScope};
use html5ever::tendril::{SliceExt, StrTendril, TendrilSink};
use html5ever::tokenizer::{TagKind, Token, TokenSink, TokenSinkResult, Tokenizer};
use html5ever::{parse_document, parse_fragment, serialize, QualName};
use rcdom::{RcDom, SerializableHandle};
use markup5ever::{local_name, namespace_url, ns};
use markup5ever_rcdom::{RcDom, SerializableHandle};

use std::io;

Expand Down Expand Up @@ -258,7 +253,6 @@ fn deep_tree() {
);
let src = String::from("<b>".repeat(60_000));
let dom = parser.one(src);
let document = &dom.document;
let opts = SerializeOpts::default();
let mut ret_val = Vec::new();
let document: SerializableHandle = dom.document.clone().into();
Expand Down
Loading

0 comments on commit 7e87faf

Please sign in to comment.