diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-10-11 15:45:50 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-10-11 15:45:50 +0200 |
commit | 73d8609565b808ac73df5ac34e6d4f7f23c25ad6 (patch) | |
tree | 8b13c61bcd55380b36338473a74e172b63fb16d7 | |
parent | 070b3efeeebf34fbc435ffc7fea2bad95689664a (diff) | |
download | markdown-rs-73d8609565b808ac73df5ac34e6d4f7f23c25ad6.tar.gz markdown-rs-73d8609565b808ac73df5ac34e6d4f7f23c25ad6.tar.bz2 markdown-rs-73d8609565b808ac73df5ac34e6d4f7f23c25ad6.zip |
Refactor to use a bunch of `into`
Diffstat (limited to '')
43 files changed, 217 insertions, 234 deletions
@@ -48,7 +48,7 @@ async fn commonmark() { let parts = re_in_out.split(&case).collect::<Vec<_>>(); let input = format!("{}\n", parts[0]); let output = if parts[1].is_empty() { - "".to_string() + "".into() } else { format!("{}\n", parts[1]) }; diff --git a/src/construct/partial_mdx_expression.rs b/src/construct/partial_mdx_expression.rs index fbb13e0..f5d1c50 100644 --- a/src/construct/partial_mdx_expression.rs +++ b/src/construct/partial_mdx_expression.rs @@ -62,7 +62,7 @@ use crate::state::{Name as StateName, State}; use crate::tokenizer::Tokenizer; use crate::util::{constant::TAB_SIZE, mdx_collect::collect}; use crate::{MdxExpressionKind, MdxExpressionParse, MdxSignal}; -use alloc::{format, string::ToString}; +use alloc::format; /// Start of an MDX expression. /// @@ -93,7 +93,7 @@ pub fn before(tokenizer: &mut Tokenizer) -> State { "{}:{}: {}", tokenizer.point.line, tokenizer.point.column, tokenizer.tokenize_state.mdx_last_parse_error.take() - .unwrap_or_else(|| "Unexpected end of file in expression, expected a corresponding closing brace for `{`".to_string()) + .unwrap_or_else(|| "Unexpected end of file in expression, expected a corresponding closing brace for `{`".into()) )) } Some(b'\n') => { diff --git a/src/mdast.rs b/src/mdast.rs index 4485167..5e3fca6 100644 --- a/src/mdast.rs +++ b/src/mdast.rs @@ -250,7 +250,7 @@ impl ToString for Node { | Node::Image(_) | Node::ImageReference(_) | Node::ThematicBreak(_) - | Node::Definition(_) => "".to_string(), + | Node::Definition(_) => "".into(), } } } @@ -1152,12 +1152,12 @@ pub struct MdxJsxAttribute { mod tests { use super::*; use crate::unist::{Point, Position}; - use alloc::{string::ToString, vec}; + use alloc::vec; #[test] fn test() { let text = Text { - value: "a".to_string(), + value: "a".into(), position: Some(Position { start: Point { line: 1, diff --git a/src/state.rs b/src/state.rs index 1cc2720..cbe19a7 100644 --- a/src/state.rs +++ b/src/state.rs @@ -2,7 +2,7 @@ use crate::construct; use crate::tokenizer::Tokenizer; -use alloc::string::{String, ToString}; +use alloc::string::String; /// Result of a state. #[derive(Clone, Debug, Eq, PartialEq)] @@ -34,7 +34,7 @@ impl State { unreachable!("cannot turn intermediate state into result") } State::Ok => Ok(()), - State::Error(x) => Err(x.to_string()), + State::Error(x) => Err(x.into()), } } } diff --git a/src/to_html.rs b/src/to_html.rs index a0ab152..a851580 100644 --- a/src/to_html.rs +++ b/src/to_html.rs @@ -300,7 +300,7 @@ pub fn compile(events: &[Event], bytes: &[u8], options: &CompileOptions) -> Stri .buffers .get(0) .expect("expected 1 final buffer") - .to_string() + .into() } /// Handle the event at `index`. @@ -690,7 +690,7 @@ fn on_enter_paragraph(context: &mut CompileContext) { /// Handle [`Enter`][Kind::Enter]:[`Resource`][Name::Resource]. fn on_enter_resource(context: &mut CompileContext) { context.buffer(); // We can have line endings in the resource, ignore them. - context.media_stack.last_mut().unwrap().destination = Some("".to_string()); + context.media_stack.last_mut().unwrap().destination = Some("".into()); } /// Handle [`Enter`][Kind::Enter]:[`ResourceDestinationString`][Name::ResourceDestinationString]. @@ -1733,7 +1733,7 @@ fn generate_autolink( let url = if let Some(protocol) = protocol { format!("{}{}", protocol, value) } else { - value.to_string() + value.into() }; let url = if context.options.allow_dangerous_protocol { diff --git a/src/to_mdast.rs b/src/to_mdast.rs index c4650da..fe5bd82 100644 --- a/src/to_mdast.rs +++ b/src/to_mdast.rs @@ -1068,7 +1068,7 @@ fn on_exit_raw_text(context: &mut CompileContext) -> Result<(), String> { } if replace { - value = str::from_utf8(&bytes).unwrap().to_string(); + value = str::from_utf8(&bytes).unwrap().into(); } } @@ -1730,7 +1730,7 @@ fn trim_eol(value: String, at_start: bool, at_end: bool) -> String { } if start > 0 || end < bytes.len() { - str::from_utf8(&bytes[start..end]).unwrap().to_string() + str::from_utf8(&bytes[start..end]).unwrap().into() } else { value } @@ -1762,7 +1762,7 @@ fn on_mismatch_error( if let Some(left) = left { format!(" before the end of `{:?}`", left.name) } else { - "".to_string() + "".into() } )); } diff --git a/src/util/char.rs b/src/util/char.rs index b902fbe..70367f3 100644 --- a/src/util/char.rs +++ b/src/util/char.rs @@ -1,10 +1,7 @@ //! Deal with bytes, chars, and kinds. use crate::util::unicode::PUNCTUATION; -use alloc::{ - format, - string::{String, ToString}, -}; +use alloc::{format, string::String}; use core::str; /// Character kinds. @@ -119,7 +116,7 @@ pub fn classify_opt(char_opt: Option<char>) -> Kind { /// Format an optional `char` (`none` means eof). pub fn format_opt(char: Option<char>) -> String { match char { - None => "end of file".to_string(), + None => "end of file".into(), Some(char) => format!("character {}", format(char)), } } @@ -127,7 +124,7 @@ pub fn format_opt(char: Option<char>) -> String { /// Format an optional `byte` (`none` means eof). pub fn format_byte_opt(byte: Option<u8>) -> String { match byte { - None => "end of file".to_string(), + None => "end of file".into(), Some(byte) => format!("byte {}", format_byte(byte)), } } @@ -136,7 +133,7 @@ pub fn format_byte_opt(byte: Option<u8>) -> String { pub fn format(char: char) -> String { let representation = format!("U+{:>04X}", char as u32); let printable = match char { - '`' => Some("`` ` ``".to_string()), + '`' => Some("`` ` ``".into()), '!'..='~' => Some(format!("`{}`", char)), _ => None, }; @@ -152,7 +149,7 @@ pub fn format(char: char) -> String { pub fn format_byte(byte: u8) -> String { let representation = format!("U+{:>04X}", byte); let printable = match byte { - b'`' => Some("`` ` ``".to_string()), + b'`' => Some("`` ` ``".into()), b'!'..=b'~' => Some(format!("`{}`", str::from_utf8(&[byte]).unwrap())), _ => None, }; diff --git a/src/util/character_reference.rs b/src/util/character_reference.rs index ee2a65c..330293c 100644 --- a/src/util/character_reference.rs +++ b/src/util/character_reference.rs @@ -4,7 +4,7 @@ use crate::util::constant::{ CHARACTER_REFERENCES, CHARACTER_REFERENCES_HTML_4, CHARACTER_REFERENCE_DECIMAL_SIZE_MAX, CHARACTER_REFERENCE_HEXADECIMAL_SIZE_MAX, CHARACTER_REFERENCE_NAMED_SIZE_MAX, }; -use alloc::string::{String, ToString}; +use alloc::string::String; use core::str; /// Decode named character references. @@ -89,11 +89,11 @@ pub fn decode_numeric(value: &str, radix: u32) -> String { // Lone surrogates, noncharacters, and out of range are handled by // Rust. ) { - return char.to_string(); + return char.into(); } } - char::REPLACEMENT_CHARACTER.to_string() + char::REPLACEMENT_CHARACTER.into() } /// Decode a character reference. diff --git a/src/util/sanitize_uri.rs b/src/util/sanitize_uri.rs index 7006ace..cd0600d 100644 --- a/src/util/sanitize_uri.rs +++ b/src/util/sanitize_uri.rs @@ -1,11 +1,7 @@ //! Make urls safe. use crate::util::encode::encode; -use alloc::{ - format, - string::{String, ToString}, - vec::Vec, -}; +use alloc::{format, string::String, vec::Vec}; /// Make a value safe for injection as a URL. /// @@ -75,7 +71,7 @@ pub fn sanitize_with_protocols(value: &str, protocols: &[&str]) -> String { // If it is a protocol, it should be allowed. let protocol = value[0..colon].to_lowercase(); if !protocols.contains(&protocol.as_str()) { - return "".to_string(); + return "".into(); } } diff --git a/tests/attention.rs b/tests/attention.rs index 83e68d9..e627c4d 100644 --- a/tests/attention.rs +++ b/tests/attention.rs @@ -844,29 +844,29 @@ fn attention() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::Emphasis(Emphasis { children: vec![Node::Text(Text { - value: "alpha".to_string(), + value: "alpha".into(), position: Some(Position::new(1, 4, 3, 1, 9, 8)) }),], position: Some(Position::new(1, 3, 2, 1, 10, 9)) }), Node::Text(Text { - value: " b ".to_string(), + value: " b ".into(), position: Some(Position::new(1, 10, 9, 1, 13, 12)) }), Node::Strong(Strong { children: vec![Node::Text(Text { - value: "bravo".to_string(), + value: "bravo".into(), position: Some(Position::new(1, 15, 14, 1, 20, 19)) }),], position: Some(Position::new(1, 13, 12, 1, 22, 21)) }), Node::Text(Text { - value: " c.".to_string(), + value: " c.".into(), position: Some(Position::new(1, 22, 21, 1, 25, 24)) }) ], diff --git a/tests/autolink.rs b/tests/autolink.rs index 7ef3caa..d2b0956 100644 --- a/tests/autolink.rs +++ b/tests/autolink.rs @@ -279,33 +279,33 @@ fn autolink() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::Link(Link { - url: "https://alpha.com".to_string(), + url: "https://alpha.com".into(), title: None, children: vec![Node::Text(Text { - value: "https://alpha.com".to_string(), + value: "https://alpha.com".into(), position: Some(Position::new(1, 4, 3, 1, 21, 20)) }),], position: Some(Position::new(1, 3, 2, 1, 22, 21)) }), Node::Text(Text { - value: " b ".to_string(), + value: " b ".into(), position: Some(Position::new(1, 22, 21, 1, 25, 24)) }), Node::Link(Link { - url: "mailto:bravo@charlie.com".to_string(), + url: "mailto:bravo@charlie.com".into(), title: None, children: vec![Node::Text(Text { - value: "bravo@charlie.com".to_string(), + value: "bravo@charlie.com".into(), position: Some(Position::new(1, 26, 25, 1, 43, 42)) }),], position: Some(Position::new(1, 25, 24, 1, 44, 43)) }), Node::Text(Text { - value: " c.".to_string(), + value: " c.".into(), position: Some(Position::new(1, 44, 43, 1, 47, 46)) }) ], diff --git a/tests/block_quote.rs b/tests/block_quote.rs index 12db252..9d967ee 100644 --- a/tests/block_quote.rs +++ b/tests/block_quote.rs @@ -225,7 +225,7 @@ fn block_quote() -> Result<(), String> { children: vec![Node::BlockQuote(BlockQuote { children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "a".to_string(), + value: "a".into(), position: Some(Position::new(1, 3, 2, 1, 4, 3)) }),], position: Some(Position::new(1, 3, 2, 1, 4, 3)) diff --git a/tests/character_escape.rs b/tests/character_escape.rs index 54944aa..c5c9004 100644 --- a/tests/character_escape.rs +++ b/tests/character_escape.rs @@ -109,7 +109,7 @@ fn character_escape() -> Result<(), String> { Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "a * b".to_string(), + value: "a * b".into(), position: Some(Position::new(1, 1, 0, 1, 7, 6)) }),], position: Some(Position::new(1, 1, 0, 1, 7, 6)) diff --git a/tests/character_reference.rs b/tests/character_reference.rs index 1cc732e..4e9a436 100644 --- a/tests/character_reference.rs +++ b/tests/character_reference.rs @@ -220,7 +220,7 @@ fn character_reference() -> Result<(), String> { Node::Root(Root { children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "\u{a0} & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸".to_string(), + value: "\u{a0} & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸".into(), position: Some(Position::new(1, 1, 0, 3, 33, 109)) }),], position: Some(Position::new(1, 1, 0, 3, 33, 109)) diff --git a/tests/code_fenced.rs b/tests/code_fenced.rs index 6da38a9..c41bd43 100644 --- a/tests/code_fenced.rs +++ b/tests/code_fenced.rs @@ -287,9 +287,9 @@ fn code_fenced() -> Result<(), String> { )?, Node::Root(Root { children: vec![Node::Code(Code { - lang: Some("js".to_string()), - meta: Some("extra".to_string()), - value: "console.log(1)\nconsole.log(2)".to_string(), + lang: Some("js".into()), + meta: Some("extra".into()), + value: "console.log(1)\nconsole.log(2)".into(), position: Some(Position::new(1, 1, 0, 4, 4, 45)) })], position: Some(Position::new(1, 1, 0, 4, 4, 45)) @@ -303,7 +303,7 @@ fn code_fenced() -> Result<(), String> { children: vec![Node::Code(Code { lang: None, meta: None, - value: "asd".to_string(), + value: "asd".into(), position: Some(Position::new(1, 1, 0, 2, 4, 7)) })], position: Some(Position::new(1, 1, 0, 2, 4, 7)) diff --git a/tests/code_indented.rs b/tests/code_indented.rs index fd539d3..b02b092 100644 --- a/tests/code_indented.rs +++ b/tests/code_indented.rs @@ -212,7 +212,7 @@ fn code_indented() -> Result<(), String> { children: vec![Node::Code(Code { lang: None, meta: None, - value: "console.log(1)\nconsole.log(2)".to_string(), + value: "console.log(1)\nconsole.log(2)".into(), position: Some(Position::new(1, 1, 0, 2, 19, 34)) })], position: Some(Position::new(1, 1, 0, 3, 1, 35)) diff --git a/tests/code_text.rs b/tests/code_text.rs index 25882c8..89fa63f 100644 --- a/tests/code_text.rs +++ b/tests/code_text.rs @@ -187,15 +187,15 @@ fn code_text() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::InlineCode(InlineCode { - value: "alpha".to_string(), + value: "alpha".into(), position: Some(Position::new(1, 3, 2, 1, 10, 9)) }), Node::Text(Text { - value: " b.".to_string(), + value: " b.".into(), position: Some(Position::new(1, 10, 9, 1, 13, 12)) }) ], diff --git a/tests/definition.rs b/tests/definition.rs index 8357a67..376035a 100644 --- a/tests/definition.rs +++ b/tests/definition.rs @@ -506,10 +506,10 @@ fn definition() -> Result<(), String> { micromark_to_mdast("[a]: <b> 'c'", &ParseOptions::default())?, Node::Root(Root { children: vec![Node::Definition(Definition { - url: "b".to_string(), - identifier: "a".to_string(), - label: Some("a".to_string()), - title: Some("c".to_string()), + url: "b".into(), + identifier: "a".into(), + label: Some("a".into()), + title: Some("c".into()), position: Some(Position::new(1, 1, 0, 1, 13, 12)) })], position: Some(Position::new(1, 1, 0, 1, 13, 12)) diff --git a/tests/frontmatter.rs b/tests/frontmatter.rs index 335084e..be17a7a 100644 --- a/tests/frontmatter.rs +++ b/tests/frontmatter.rs @@ -78,7 +78,7 @@ fn frontmatter() -> Result<(), String> { micromark_to_mdast("---\na: b\n---", &frontmatter.parse)?, Node::Root(Root { children: vec![Node::Yaml(Yaml { - value: "a: b".to_string(), + value: "a: b".into(), position: Some(Position::new(1, 1, 0, 3, 4, 12)) })], position: Some(Position::new(1, 1, 0, 3, 4, 12)) @@ -90,7 +90,7 @@ fn frontmatter() -> Result<(), String> { micromark_to_mdast("+++\ntitle = \"Jupyter\"\n+++", &frontmatter.parse)?, Node::Root(Root { children: vec![Node::Toml(Toml { - value: "title = \"Jupyter\"".to_string(), + value: "title = \"Jupyter\"".into(), position: Some(Position::new(1, 1, 0, 3, 4, 25)) })], position: Some(Position::new(1, 1, 0, 3, 4, 25)) diff --git a/tests/gfm_autolink_literal.rs b/tests/gfm_autolink_literal.rs index 9297163..c608533 100644 --- a/tests/gfm_autolink_literal.rs +++ b/tests/gfm_autolink_literal.rs @@ -2752,72 +2752,72 @@ www.a/~ children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::Link(Link { - url: "https://alpha.com".to_string(), + url: "https://alpha.com".into(), title: None, children: vec![Node::Text(Text { - value: "https://alpha.com".to_string(), + value: "https://alpha.com".into(), position: Some(Position::new(1, 3, 2, 1, 20, 19)) }),], position: Some(Position::new(1, 3, 2, 1, 20, 19)) }), Node::Text(Text { - value: " b ".to_string(), + value: " b ".into(), position: Some(Position::new(1, 20, 19, 1, 23, 22)) }), Node::Link(Link { - url: "mailto:bravo@charlie.com".to_string(), + url: "mailto:bravo@charlie.com".into(), title: None, children: vec![Node::Text(Text { - value: "bravo@charlie.com".to_string(), + value: "bravo@charlie.com".into(), position: Some(Position::new(1, 23, 22, 1, 40, 39)) }),], position: Some(Position::new(1, 23, 22, 1, 40, 39)) }), Node::Text(Text { - value: " c ".to_string(), + value: " c ".into(), position: Some(Position::new(1, 40, 39, 1, 43, 42)) }), Node::Link(Link { - url: "http://www.delta.com".to_string(), + url: "http://www.delta.com".into(), title: None, children: vec![Node::Text(Text { - value: "www.delta.com".to_string(), + value: "www.delta.com".into(), position: Some(Position::new(1, 43, 42, 1, 56, 55)) }),], position: Some(Position::new(1, 43, 42, 1, 56, 55)) }), Node::Text(Text { - value: " d ".to_string(), + value: " d ".into(), position: Some(Position::new(1, 56, 55, 1, 59, 58)) }), Node::Link(Link { - url: "xmpp:echo@foxtrot.com".to_string(), + url: "xmpp:echo@foxtrot.com".into(), title: None, children: vec![Node::Text(Text { - value: "xmpp:echo@foxtrot.com".to_string(), + value: "xmpp:echo@foxtrot.com".into(), position: Some(Position::new(1, 59, 58, 1, 80, 79)) }),], position: Some(Position::new(1, 59, 58, 1, 80, 79)) }), Node::Text(Text { - value: " e ".to_string(), + value: " e ".into(), position: Some(Position::new(1, 80, 79, 1, 83, 82)) }), Node::Link(Link { - url: "mailto:golf@hotel.com".to_string(), + url: "mailto:golf@hotel.com".into(), title: None, children: vec![Node::Text(Text { - value: "mailto:golf@hotel.com".to_string(), + value: "mailto:golf@hotel.com".into(), position: Some(Position::new(1, 83, 82, 1, 104, 103)) }),], position: Some(Position::new(1, 83, 82, 1, 104, 103)) }), Node::Text(Text { - value: " f.".to_string(), + value: " f.".into(), position: Some(Position::new(1, 104, 103, 1, 107, 106)) }) ], diff --git a/tests/gfm_footnote.rs b/tests/gfm_footnote.rs index 29b0092..4b2be52 100644 --- a/tests/gfm_footnote.rs +++ b/tests/gfm_footnote.rs @@ -46,8 +46,8 @@ fn gfm_footnote() -> Result<(), String> { ..ParseOptions::default() }, compile: CompileOptions { - gfm_footnote_label: Some("Voetnoten".to_string()), - gfm_footnote_back_label: Some("Terug naar de inhoud".to_string()), + gfm_footnote_label: Some("Voetnoten".into()), + gfm_footnote_back_label: Some("Terug naar de inhoud".into()), ..CompileOptions::default() } } @@ -73,7 +73,7 @@ fn gfm_footnote() -> Result<(), String> { ..ParseOptions::default() }, compile: CompileOptions { - gfm_footnote_label_tag_name: Some("h1".to_string()), + gfm_footnote_label_tag_name: Some("h1".into()), ..CompileOptions::default() } } @@ -99,7 +99,7 @@ fn gfm_footnote() -> Result<(), String> { ..ParseOptions::default() }, compile: CompileOptions { - gfm_footnote_label_attributes: Some("class=\"footnote-heading\"".to_string()), + gfm_footnote_label_attributes: Some("class=\"footnote-heading\"".into()), ..CompileOptions::default() } } @@ -125,7 +125,7 @@ fn gfm_footnote() -> Result<(), String> { ..ParseOptions::default() }, compile: CompileOptions { - gfm_footnote_clobber_prefix: Some("".to_string()), + gfm_footnote_clobber_prefix: Some("".into()), ..CompileOptions::default() } } @@ -1632,28 +1632,28 @@ multi-paragraph list items. <a href="#user-content-fnref-longnote" data-footnote Node::FootnoteDefinition(FootnoteDefinition { children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "b\nc".to_string(), + value: "b\nc".into(), position: Some(Position::new(1, 7, 6, 2, 6, 10)) })], position: Some(Position::new(1, 7, 6, 2, 6, 10)) })], - identifier: "a".to_string(), - label: Some("a".to_string()), + identifier: "a".into(), + label: Some("a".into()), position: Some(Position::new(1, 1, 0, 3, 1, 11)) }), Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "d ".to_string(), + value: "d ".into(), position: Some(Position::new(4, 1, 12, 4, 3, 14)) }), Node::FootnoteReference(FootnoteReference { - identifier: "a".to_string(), - label: Some("a".to_string()), + identifier: "a".into(), + label: Some("a".into()), position: Some(Position::new(4, 3, 14, 4, 7, 18)) }), Node::Text(Text { - value: " e.".to_string(), + value: " e.".into(), position: Some(Position::new(4, 7, 18, 4, 10, 21)) }) ], diff --git a/tests/gfm_strikethrough.rs b/tests/gfm_strikethrough.rs index ac6b62c..6109814 100644 --- a/tests/gfm_strikethrough.rs +++ b/tests/gfm_strikethrough.rs @@ -405,18 +405,18 @@ u ~**xxx**~ zzz children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::Delete(Delete { children: vec![Node::Text(Text { - value: "alpha".to_string(), + value: "alpha".into(), position: Some(Position::new(1, 5, 4, 1, 10, 9)) }),], position: Some(Position::new(1, 3, 2, 1, 12, 11)) }), Node::Text(Text { - value: " b.".to_string(), + value: " b.".into(), position: Some(Position::new(1, 12, 11, 1, 15, 14)) }), ], diff --git a/tests/gfm_table.rs b/tests/gfm_table.rs index 1f0b93c..8e871f6 100644 --- a/tests/gfm_table.rs +++ b/tests/gfm_table.rs @@ -1849,28 +1849,28 @@ normal escape: <a href="https://github.com/github/cmark-gfm/issues/277">https:// children: vec![ Node::TableCell(TableCell { children: vec![Node::Text(Text { - value: "none".to_string(), + value: "none".into(), position: Some(Position::new(1, 3, 2, 1, 7, 6)) }),], position: Some(Position::new(1, 1, 0, 1, 8, 7)) }), Node::TableCell(TableCell { children: vec![Node::Text(Text { - value: "left".to_string(), + value: "left".into(), position: Some(Position::new(1, 10, 9, 1, 14, 13)) }),], position: Some(Position::new(1, 8, 7, 1, 15, 14)) }), Node::TableCell(TableCell { children: vec![Node::Text(Text { - value: "right".to_string(), + value: "right".into(), position: Some(Position::new(1, 17, 16, 1, 22, 21)) }),], position: Some(Position::new(1, 15, 14, 1, 23, 22)) }), Node::TableCell(TableCell { children: vec![Node::Text(Text { - value: "center".to_string(), + value: "center".into(), position: Some(Position::new(1, 25, 24, 1, 31, 30)) }),], position: Some(Position::new(1, 23, 22, 1, 33, 32)) @@ -1881,7 +1881,7 @@ normal escape: <a href="https://github.com/github/cmark-gfm/issues/277">https:// Node::TableRow(TableRow { children: vec![Node::TableCell(TableCell { children: vec![Node::Text(Text { - value: "a".to_string(), + value: "a".into(), position: Some(Position::new(3, 3, 57, 3, 4, 58)) }),], position: Some(Position::new(3, 1, 55, 3, 6, 60)) @@ -1892,35 +1892,35 @@ normal escape: <a href="https://github.com/github/cmark-gfm/issues/277">https:// children: vec![ Node::TableCell(TableCell { children: vec![Node::Text(Text { - value: "b".to_string(), + value: "b".into(), position: Some(Position::new(4, 3, 63, 4, 4, 64)) }),], position: Some(Position::new(4, 1, 61, 4, 5, 65)) }), Node::TableCell(TableCell { children: vec![Node::Text(Text { - value: "c".to_string(), + value: "c".into(), position: Some(Position::new(4, 7, 67, 4, 8, 68)) }),], position: Some(Position::new(4, 5, 65, 4, 9, 69)) }), Node::TableCell(TableCell { children: vec![Node::Text(Text { - value: "d".to_string(), + value: "d".into(), position: Some(Position::new(4, 11, 71, 4, 12, 72)) }),], position: Some(Position::new(4, 9, 69, 4, 13, 73)) }), Node::TableCell(TableCell { children: vec![Node::Text(Text { - value: "e".to_string(), + value: "e".into(), position: Some(Position::new(4, 15, 75, 4, 16, 76)) }),], position: Some(Position::new(4, 13, 73, 4, 17, 77)) }), Node::TableCell(TableCell { children: vec![Node::Text(Text { - value: "f".to_string(), + value: "f".into(), position: Some(Position::new(4, 19, 79, 4, 20, 80)) }),], position: Some(Position::new(4, 17, 77, 4, 22, 82)) @@ -1944,7 +1944,7 @@ normal escape: <a href="https://github.com/github/cmark-gfm/issues/277">https:// children: vec![Node::TableRow(TableRow { children: vec![Node::TableCell(TableCell { children: vec![Node::InlineCode(InlineCode { - value: "a|b".to_string(), + value: "a|b".into(), position: Some(Position::new(1, 3, 2, 1, 9, 8)) }),], position: Some(Position::new(1, 1, 0, 1, 11, 10)) diff --git a/tests/gfm_task_list_item.rs b/tests/gfm_task_list_item.rs index 8bc0d31..18ae1dd 100644 --- a/tests/gfm_task_list_item.rs +++ b/tests/gfm_task_list_item.rs @@ -261,7 +261,7 @@ Text.</li> spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "a".to_string(), + value: "a".into(), position: Some(Position::new(1, 7, 6, 1, 8, 7)) }),], position: Some(Position::new(1, 7, 6, 1, 8, 7)) @@ -273,7 +273,7 @@ Text.</li> spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "b".to_string(), + value: "b".into(), position: Some(Position::new(2, 7, 14, 2, 8, 15)) }),], position: Some(Position::new(2, 7, 14, 2, 8, 15)) @@ -285,7 +285,7 @@ Text.</li> spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "c".to_string(), + value: "c".into(), position: Some(Position::new(3, 3, 18, 3, 4, 19)) }),], position: Some(Position::new(3, 3, 18, 3, 4, 19)) diff --git a/tests/hard_break_escape.rs b/tests/hard_break_escape.rs index 2e88c95..9f17f10 100644 --- a/tests/hard_break_escape.rs +++ b/tests/hard_break_escape.rs @@ -69,14 +69,14 @@ fn hard_break_escape() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a".to_string(), + value: "a".into(), position: Some(Position::new(1, 1, 0, 1, 2, 1)) }), Node::Break(Break { position: Some(Position::new(1, 2, 1, 2, 1, 3)) }), Node::Text(Text { - value: "b.".to_string(), + value: "b.".into(), position: Some(Position::new(2, 1, 3, 2, 3, 5)) }), ], diff --git a/tests/hard_break_trailing.rs b/tests/hard_break_trailing.rs index 907356a..c724c85 100644 --- a/tests/hard_break_trailing.rs +++ b/tests/hard_break_trailing.rs @@ -135,14 +135,14 @@ fn hard_break_trailing() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a".to_string(), + value: "a".into(), position: Some(Position::new(1, 1, 0, 1, 2, 1)) }), Node::Break(Break { position: Some(Position::new(1, 2, 1, 2, 1, 4)) }), Node::Text(Text { - value: "b.".to_string(), + value: "b.".into(), position: Some(Position::new(2, 1, 4, 2, 3, 6)) }), ], diff --git a/tests/heading_atx.rs b/tests/heading_atx.rs index 1b6b8a3..736c50a 100644 --- a/tests/heading_atx.rs +++ b/tests/heading_atx.rs @@ -231,7 +231,7 @@ fn heading_atx() -> Result<(), String> { children: vec![Node::Heading(Heading { depth: 2, children: vec![Node::Text(Text { - value: "alpha".to_string(), + value: "alpha".into(), position: Some(Position::new(1, 4, 3, 1, 9, 8)) }),], position: Some(Position::new(1, 1, 0, 1, 11, 10)) diff --git a/tests/heading_setext.rs b/tests/heading_setext.rs index ed2dfa0..6f0e572 100644 --- a/tests/heading_setext.rs +++ b/tests/heading_setext.rs @@ -298,7 +298,7 @@ fn heading_setext() -> Result<(), String> { children: vec![Node::Heading(Heading { depth: 1, children: vec![Node::Text(Text { - value: "alpha\nbravo".to_string(), + value: "alpha\nbravo".into(), position: Some(Position::new(1, 1, 0, 2, 6, 11)) }),], position: Some(Position::new(1, 1, 0, 3, 3, 14)) diff --git a/tests/html_flow.rs b/tests/html_flow.rs index ca93510..adeebf6 100644 --- a/tests/html_flow.rs +++ b/tests/html_flow.rs @@ -52,7 +52,7 @@ fn html_flow() -> Result<(), String> { micromark_to_mdast("<div>\nstuff\n</div>", &ParseOptions::default())?, Node::Root(Root { children: vec![Node::Html(Html { - value: "<div>\nstuff\n</div>".to_string(), + value: "<div>\nstuff\n</div>".into(), position: Some(Position::new(1, 1, 0, 3, 7, 18)) })], position: Some(Position::new(1, 1, 0, 3, 7, 18)) diff --git a/tests/html_text.rs b/tests/html_text.rs index bc36bd7..2bdd79d 100644 --- a/tests/html_text.rs +++ b/tests/html_text.rs @@ -451,23 +451,23 @@ micromark_with_options("<x> a", &danger)?, children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "alpha ".to_string(), + value: "alpha ".into(), position: Some(Position::new(1, 1, 0, 1, 7, 6)) }), Node::Html(Html { - value: "<i>".to_string(), + value: "<i>".into(), position: Some(Position::new(1, 7, 6, 1, 10, 9)) }), Node::Text(Text { - value: "bravo".to_string(), + value: "bravo".into(), position: Some(Position::new(1, 10, 9, 1, 15, 14)) }), Node::Html(Html { - value: "</b>".to_string(), + value: "</b>".into(), position: Some(Position::new(1, 15, 14, 1, 19, 18)) }), Node::Text(Text { - value: " charlie.".to_string(), + value: " charlie.".into(), position: Some(Position::new(1, 19, 18, 1, 28, 27)) }) ], diff --git a/tests/image.rs b/tests/image.rs index f52025d..7b58e6d 100644 --- a/tests/image.rs +++ b/tests/image.rs @@ -245,27 +245,27 @@ fn image() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::Image(Image { - alt: "alpha".to_string(), + alt: "alpha".into(), url: String::new(), title: None, position: Some(Position::new(1, 3, 2, 1, 13, 12)) }), Node::Text(Text { - value: " b ".to_string(), + value: " b ".into(), position: Some(Position::new(1, 13, 12, 1, 16, 15)) }), Node::Image(Image { - alt: "bravo".to_string(), - url: "charlie".to_string(), - title: Some("delta".to_string()), + alt: "bravo".into(), + url: "charlie".into(), + title: Some("delta".into()), position: Some(Position::new(1, 16, 15, 1, 41, 40)) }), Node::Text(Text { - value: " c.".to_string(), + value: " c.".into(), position: Some(Position::new(1, 41, 40, 1, 44, 43)) }) ], @@ -284,49 +284,49 @@ fn image() -> Result<(), String> { Node::Root(Root { children: vec![ Node::Definition(Definition { - identifier: "x".to_string(), - label: Some("x".to_string()), - url: "y".to_string(), + identifier: "x".into(), + label: Some("x".into()), + url: "y".into(), title: None, position: Some(Position::new(1, 1, 0, 1, 7, 6)) }), Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(3, 1, 8, 3, 3, 10)) }), Node::ImageReference(ImageReference { reference_kind: ReferenceKind::Shortcut, - identifier: "x".to_string(), - label: Some("x".to_string()), - alt: "x".to_string(), + identifier: "x".into(), + label: Some("x".into()), + alt: "x".into(), position: Some(Position::new(3, 3, 10, 3, 7, 14)) }), Node::Text(Text { - value: " b ".to_string(), + value: " b ".into(), position: Some(Position::new(3, 7, 14, 3, 10, 17)) }), Node::ImageReference(ImageReference { reference_kind: ReferenceKind::Collapsed, - identifier: "x".to_string(), - label: Some("x".to_string()), - alt: "x".to_string(), + identifier: "x".into(), + label: Some("x".into()), + alt: "x".into(), position: Some(Position::new(3, 10, 17, 3, 16, 23)) }), Node::Text(Text { - value: " c ".to_string(), + value: " c ".into(), position: Some(Position::new(3, 16, 23, 3, 19, 26)) }), Node::ImageReference(ImageReference { reference_kind: ReferenceKind::Full, - identifier: "x".to_string(), - label: Some("x".to_string()), - alt: "d".to_string(), + identifier: "x".into(), + label: Some("x".into()), + alt: "d".into(), position: Some(Position::new(3, 19, 26, 3, 26, 33)) }), Node::Text(Text { - value: " e.".to_string(), + value: " e.".into(), position: Some(Position::new(3, 26, 33, 3, 29, 36)) }), ], diff --git a/tests/link_reference.rs b/tests/link_reference.rs index c21ca0b..5e00dab 100644 --- a/tests/link_reference.rs +++ b/tests/link_reference.rs @@ -436,58 +436,58 @@ fn link_reference() -> Result<(), String> { Node::Root(Root { children: vec![ Node::Definition(Definition { - identifier: "x".to_string(), - label: Some("x".to_string()), - url: "y".to_string(), + identifier: "x".into(), + label: Some("x".into()), + url: "y".into(), title: None, position: Some(Position::new(1, 1, 0, 1, 7, 6)) }), Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(3, 1, 8, 3, 3, 10)) }), Node::LinkReference(LinkReference { reference_kind: ReferenceKind::Shortcut, - identifier: "x".to_string(), - label: Some("x".to_string()), + identifier: "x".into(), + label: Some("x".into()), children: vec![Node::Text(Text { - value: "x".to_string(), + value: "x".into(), position: Some(Position::new(3, 4, 11, 3, 5, 12)) }),], position: Some(Position::new(3, 3, 10, 3, 6, 13)) }), Node::Text(Text { - value: " b ".to_string(), + value: " b ".into(), position: Some(Position::new(3, 6, 13, 3, 9, 16)) }), Node::LinkReference(LinkReference { reference_kind: ReferenceKind::Collapsed, - identifier: "x".to_string(), - label: Some("x".to_string()), + identifier: "x".into(), + label: Some("x".into()), children: vec![Node::Text(Text { - value: "x".to_string(), + value: "x".into(), position: Some(Position::new(3, 10, 17, 3, 11, 18)) }),], position: Some(Position::new(3, 9, 16, 3, 14, 21)) }), Node::Text(Text { - value: " c ".to_string(), + value: " c ".into(), position: Some(Position::new(3, 14, 21, 3, 17, 24)) }), Node::LinkReference(LinkReference { reference_kind: ReferenceKind::Full, - identifier: "x".to_string(), - label: Some("x".to_string()), + identifier: "x".into(), + label: Some("x".into()), children: vec![Node::Text(Text { - value: "d".to_string(), + value: "d".into(), position: Some(Position::new(3, 18, 25, 3, 19, 26)) }),], position: Some(Position::new(3, 17, 24, 3, 23, 30)) }), Node::Text(Text { - value: " e.".to_string(), + value: " e.".into(), position: Some(Position::new(3, 23, 30, 3, 26, 33)) }), ], diff --git a/tests/link_resource.rs b/tests/link_resource.rs index 9f136ef..4554d86 100644 --- a/tests/link_resource.rs +++ b/tests/link_resource.rs @@ -475,33 +475,33 @@ fn link_resource() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::Link(Link { url: String::new(), title: None, children: vec![Node::Text(Text { - value: "alpha".to_string(), + value: "alpha".into(), position: Some(Position::new(1, 4, 3, 1, 9, 8)) }),], position: Some(Position::new(1, 3, 2, 1, 12, 11)) }), Node::Text(Text { - value: " b ".to_string(), + value: " b ".into(), position: Some(Position::new(1, 12, 11, 1, 15, 14)) }), Node::Link(Link { - url: "charlie".to_string(), - title: Some("delta".to_string()), + url: "charlie".into(), + title: Some("delta".into()), children: vec![Node::Text(Text { - value: "bravo".to_string(), + value: "bravo".into(), position: Some(Position::new(1, 16, 15, 1, 21, 20)) }),], position: Some(Position::new(1, 15, 14, 1, 39, 38)) }), Node::Text(Text { - value: " c.".to_string(), + value: " c.".into(), position: Some(Position::new(1, 39, 38, 1, 42, 41)) }) ], diff --git a/tests/list.rs b/tests/list.rs index 560be82..88b7e52 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -602,7 +602,7 @@ fn list() -> Result<(), String> { spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "a".to_string(), + value: "a".into(), position: Some(Position::new(1, 3, 2, 1, 4, 3)) }),], position: Some(Position::new(1, 3, 2, 1, 4, 3)) @@ -628,7 +628,7 @@ fn list() -> Result<(), String> { spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "a".to_string(), + value: "a".into(), position: Some(Position::new(1, 4, 3, 1, 5, 4)) }),], position: Some(Position::new(1, 4, 3, 1, 5, 4)) @@ -656,14 +656,14 @@ fn list() -> Result<(), String> { children: vec![ Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "a".to_string(), + value: "a".into(), position: Some(Position::new(1, 3, 2, 1, 4, 3)) }),], position: Some(Position::new(1, 3, 2, 1, 4, 3)) }), Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "b".to_string(), + value: "b".into(), position: Some(Position::new(3, 3, 7, 3, 4, 8)) }),], position: Some(Position::new(3, 3, 7, 3, 4, 8)) @@ -676,7 +676,7 @@ fn list() -> Result<(), String> { spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "c".to_string(), + value: "c".into(), position: Some(Position::new(4, 3, 11, 4, 4, 12)) }),], position: Some(Position::new(4, 3, 11, 4, 4, 12)) diff --git a/tests/math_flow.rs b/tests/math_flow.rs index 4665eef..1cf0f65 100644 --- a/tests/math_flow.rs +++ b/tests/math_flow.rs @@ -260,8 +260,8 @@ fn math_flow() -> Result<(), String> { micromark_to_mdast("$$extra\nabc\ndef\n$$", &math.parse)?, Node::Root(Root { children: vec![Node::Math(Math { - meta: Some("extra".to_string()), - value: "abc\ndef".to_string(), + meta: Some("extra".into()), + value: "abc\ndef".into(), position: Some(Position::new(1, 1, 0, 4, 3, 18)) })], position: Some(Position::new(1, 1, 0, 4, 3, 18)) diff --git a/tests/math_text.rs b/tests/math_text.rs index 6282181..b4d64f8 100644 --- a/tests/math_text.rs +++ b/tests/math_text.rs @@ -214,15 +214,15 @@ fn math_text() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::InlineMath(InlineMath { - value: "alpha".to_string(), + value: "alpha".into(), position: Some(Position::new(1, 3, 2, 1, 10, 9)) }), Node::Text(Text { - value: " b.".to_string(), + value: " b.".into(), position: Some(Position::new(1, 10, 9, 1, 13, 12)) }) ], diff --git a/tests/mdx_esm.rs b/tests/mdx_esm.rs index 31f493b..f6c2b4d 100644 --- a/tests/mdx_esm.rs +++ b/tests/mdx_esm.rs @@ -249,7 +249,7 @@ fn mdx_esm() -> Result<(), String> { micromark_to_mdast("import a from 'b'\nexport {a}", &swc.parse)?, Node::Root(Root { children: vec![Node::MdxjsEsm(MdxjsEsm { - value: "import a from 'b'\nexport {a}".to_string(), + value: "import a from 'b'\nexport {a}".into(), position: Some(Position::new(1, 1, 0, 2, 11, 28)), stops: vec![(0, 0), (17, 17), (18, 18)] })], diff --git a/tests/mdx_expression_flow.rs b/tests/mdx_expression_flow.rs index c9ff560..8217c94 100644 --- a/tests/mdx_expression_flow.rs +++ b/tests/mdx_expression_flow.rs @@ -93,7 +93,7 @@ fn mdx_expression_flow_agnostic() -> Result<(), String> { micromark_to_mdast("{alpha +\nbravo}", &mdx.parse)?, Node::Root(Root { children: vec![Node::MdxFlowExpression(MdxFlowExpression { - value: "alpha +\nbravo".to_string(), + value: "alpha +\nbravo".into(), position: Some(Position::new(1, 1, 0, 2, 7, 15)), stops: vec![(0, 1), (7, 8), (8, 9)] })], diff --git a/tests/mdx_expression_text.rs b/tests/mdx_expression_text.rs index 0aee081..e0f1f3f 100644 --- a/tests/mdx_expression_text.rs +++ b/tests/mdx_expression_text.rs @@ -208,16 +208,16 @@ fn mdx_expression_text_agnostic() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::MdxTextExpression(MdxTextExpression { - value: "alpha".to_string(), + value: "alpha".into(), position: Some(Position::new(1, 3, 2, 1, 10, 9)), stops: vec![(0, 3)] }), Node::Text(Text { - value: " b.".to_string(), + value: " b.".into(), position: Some(Position::new(1, 10, 9, 1, 13, 12)) }) ], diff --git a/tests/mdx_jsx_flow.rs b/tests/mdx_jsx_flow.rs index 46d2559..5216c82 100644 --- a/tests/mdx_jsx_flow.rs +++ b/tests/mdx_jsx_flow.rs @@ -167,7 +167,7 @@ fn mdx_jsx_flow_essence() -> Result<(), String> { spread: false, children: vec![Node::Paragraph(Paragraph { children: vec![Node::Text(Text { - value: "a".to_string(), + value: "a".into(), position: Some(Position::new(2, 5, 7, 2, 6, 8)) }),], position: Some(Position::new(2, 5, 7, 2, 6, 8)) diff --git a/tests/mdx_jsx_text.rs b/tests/mdx_jsx_text.rs index 22a701a..cf0201e 100644 --- a/tests/mdx_jsx_text.rs +++ b/tests/mdx_jsx_text.rs @@ -58,17 +58,17 @@ fn mdx_jsx_text_core() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::MdxJsxTextElement(MdxJsxTextElement { - name: Some("b".to_string()), + name: Some("b".into()), attributes: vec![], children: vec![], position: Some(Position::new(1, 3, 2, 1, 8, 7)) }), Node::Text(Text { - value: " c.".to_string(), + value: " c.".into(), position: Some(Position::new(1, 8, 7, 1, 11, 10)) }) ], @@ -85,17 +85,17 @@ fn mdx_jsx_text_core() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::Text(Text { - value: "a ".to_string(), + value: "a ".into(), position: Some(Position::new(1, 1, 0, 1, 3, 2)) }), Node::MdxJsxTextElement(MdxJsxTextElement { - name: Some("b".to_string()), + name: Some("b".into()), attributes: vec![], children: vec![ Node::Emphasis(Emphasis { children: vec![ Node::Text(Text { - value: "c".to_string(), + value: "c".into(), position: Some(Position::new(1, 7, 6, 1, 8, 7)) }), ], @@ -105,7 +105,7 @@ fn mdx_jsx_text_core() -> Result<(), String> { position: Some(Position::new(1, 3, 2, 1, 13, 12)) }), Node::Text(Text { - value: " d.".to_string(), + value: " d.".into(), position: Some(Position::new(1, 13, 12, 1, 16, 15)) }) ], @@ -122,13 +122,13 @@ fn mdx_jsx_text_core() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::MdxJsxTextElement(MdxJsxTextElement { - name: Some("a:b".to_string()), + name: Some("a:b".into()), attributes: vec![], children: vec![], position: Some(Position::new(1, 1, 0, 1, 8, 7)) }), Node::Text(Text { - value: ".".to_string(), + value: ".".into(), position: Some(Position::new(1, 8, 7, 1, 9, 8)) }) ], @@ -145,13 +145,13 @@ fn mdx_jsx_text_core() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::MdxJsxTextElement(MdxJsxTextElement { - name: Some("a.b.c".to_string()), + name: Some("a.b.c".into()), attributes: vec![], children: vec![], position: Some(Position::new(1, 1, 0, 1, 10, 9)) }), Node::Text(Text { - value: ".".to_string(), + value: ".".into(), position: Some(Position::new(1, 10, 9, 1, 11, 10)) }) ], @@ -168,16 +168,13 @@ fn mdx_jsx_text_core() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::MdxJsxTextElement(MdxJsxTextElement { - name: Some("a".to_string()), - attributes: vec![AttributeContent::Expression( - "...b".to_string(), - vec![(0, 4)] - )], + name: Some("a".into()), + attributes: vec![AttributeContent::Expression("...b".into(), vec![(0, 4)])], children: vec![], position: Some(Position::new(1, 1, 0, 1, 13, 12)) }), Node::Text(Text { - value: ".".to_string(), + value: ".".into(), position: Some(Position::new(1, 13, 12, 1, 14, 13)) }) ], @@ -194,14 +191,14 @@ fn mdx_jsx_text_core() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::MdxJsxTextElement(MdxJsxTextElement { - name: Some("a".to_string()), + name: Some("a".into()), attributes: vec![ AttributeContent::Property(MdxJsxAttribute { - name: "b".to_string(), + name: "b".into(), value: None, }), AttributeContent::Property(MdxJsxAttribute { - name: "c:d".to_string(), + name: "c:d".into(), value: None, }) ], @@ -209,7 +206,7 @@ fn mdx_jsx_text_core() -> Result<(), String> { position: Some(Position::new(1, 1, 0, 1, 12, 11)) }), Node::Text(Text { - value: ".".to_string(), + value: ".".into(), position: Some(Position::new(1, 12, 11, 1, 13, 12)) }) ], @@ -226,29 +223,26 @@ fn mdx_jsx_text_core() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::MdxJsxTextElement(MdxJsxTextElement { - name: Some("a".to_string()), + name: Some("a".into()), attributes: vec![ AttributeContent::Property(MdxJsxAttribute { - name: "b".to_string(), - value: Some(AttributeValue::Literal("c".to_string())), + name: "b".into(), + value: Some(AttributeValue::Literal("c".into())), }), AttributeContent::Property(MdxJsxAttribute { - name: "d".to_string(), - value: Some(AttributeValue::Literal("e".to_string())), + name: "d".into(), + value: Some(AttributeValue::Literal("e".into())), }), AttributeContent::Property(MdxJsxAttribute { - name: "f".to_string(), - value: Some(AttributeValue::Expression( - "g".to_string(), - vec![(0, 18)] - )), + name: "f".into(), + value: Some(AttributeValue::Expression("g".into(), vec![(0, 18)])), }), ], children: vec![], position: Some(Position::new(1, 1, 0, 1, 24, 23)) }), Node::Text(Text { - value: ".".to_string(), + value: ".".into(), position: Some(Position::new(1, 24, 23, 1, 25, 24)) }) ], @@ -265,10 +259,10 @@ fn mdx_jsx_text_core() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::MdxJsxTextElement(MdxJsxTextElement { - name: Some("a".to_string()), + name: Some("a".into()), attributes: vec![ AttributeContent::Property(MdxJsxAttribute { - name: "b".to_string(), + name: "b".into(), value: Some(AttributeValue::Literal("\u{a0} & © Æ Ď ¾ ℋ ⅆ ∲ ≧̸".into())), }), ], @@ -276,7 +270,7 @@ fn mdx_jsx_text_core() -> Result<(), String> { position: Some(Position::new(1, 1, 0, 1, 120, 119)) }), Node::Text(Text { - value: ".".to_string(), + value: ".".into(), position: Some(Position::new(1, 120, 119, 1, 121, 120)) }) ], @@ -296,14 +290,14 @@ fn mdx_jsx_text_core() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::MdxJsxTextElement(MdxJsxTextElement { - name: Some("a".to_string()), + name: Some("a".into()), attributes: vec![ AttributeContent::Property(MdxJsxAttribute { - name: "b".to_string(), + name: "b".into(), value: Some(AttributeValue::Literal("# Ӓ Ϡ �".into())), }), AttributeContent::Property(MdxJsxAttribute { - name: "c".to_string(), + name: "c".into(), value: Some(AttributeValue::Literal("\" ആ ಫ".into())), }), ], @@ -311,7 +305,7 @@ fn mdx_jsx_text_core() -> Result<(), String> { position: Some(Position::new(1, 1, 0, 1, 63, 62)) }), Node::Text(Text { - value: ".".to_string(), + value: ".".into(), position: Some(Position::new(1, 63, 62, 1, 64, 63)) }) ], @@ -328,10 +322,10 @@ fn mdx_jsx_text_core() -> Result<(), String> { children: vec![Node::Paragraph(Paragraph { children: vec![ Node::MdxJsxTextElement(MdxJsxTextElement { - name: Some("a".to_string()), + name: Some("a".into()), attributes: vec![ AttributeContent::Property(MdxJsxAttribute { - name: "b".to_string(), + name: "b".into(), value: Some(AttributeValue::Literal("  &x; &#; &#x; � &#abcdef0; &ThisIsNotDefined; &hi?;".into())), }) ], @@ -339,7 +333,7 @@ fn mdx_jsx_text_core() -> Result<(), String> { position: Some(Position::new(1, 1, 0, 1, 78, 77)) }), Node::Text(Text { - value: ".".to_string(), + value: ".".into(), position: Some(Position::new(1, 78, 77, 1, 79, 78)) }) ], diff --git a/tests/test_utils/hast.rs b/tests/test_utils/hast.rs index 48460ca..db5326c 100644 --- a/tests/test_utils/hast.rs +++ b/tests/test_utils/hast.rs @@ -68,7 +68,7 @@ impl ToString for Node { Node::MdxExpression(x) => x.value.clone(), Node::MdxjsEsm(x) => x.value.clone(), // Voids. - Node::Doctype(_) => "".to_string(), + Node::Doctype(_) => "".into(), } } } diff --git a/tests/test_utils/swc.rs b/tests/test_utils/swc.rs index 78859b6..7e44898 100644 --- a/tests/test_utils/swc.rs +++ b/tests/test_utils/swc.rs @@ -19,7 +19,7 @@ use swc_ecma_visit::VisitMutWith; /// Lex ESM in MDX with SWC. #[allow(dead_code)] pub fn parse_esm(value: &str) -> MdxSignal { - let (file, syntax, version) = create_config(value.to_string()); + let (file, syntax, version) = create_config(value.into()); let mut errors = vec![]; let result = parse_file_as_module(&file, syntax, version, None, &mut errors); @@ -43,7 +43,7 @@ pub fn parse_esm_to_tree( stops: &[Stop], location: Option<&Location>, ) -> Result<swc_ecma_ast::Module, String> { - let (file, syntax, version) = create_config(value.to_string()); + let (file, syntax, version) = create_config(value.into()); let mut errors = vec![]; let result = parse_file_as_module(&file, syntax, version, None, &mut errors); let mut rewrite_context = RewriteContext { @@ -210,7 +210,7 @@ pub fn serialize(module: &Module) -> String { emitter.emit_module(module).unwrap(); } - String::from_utf8_lossy(&buf).to_string() + String::from_utf8_lossy(&buf).into() } /// Check that the resulting AST of ESM is OK. @@ -225,7 +225,7 @@ fn check_esm_ast(tree: &Module) -> MdxSignal { if !node.is_module_decl() { let relative = fix_swc_position(node.span().lo.to_usize(), 0); return MdxSignal::Error( - "Unexpected statement in code: only import/exports are supported".to_string(), + "Unexpected statement in code: only import/exports are supported".into(), relative, ); } @@ -253,10 +253,7 @@ fn check_expression_ast(tree: &Expr, kind: &MdxExpressionKind) -> MdxSignal { }) .is_none() { - MdxSignal::Error( - "Expected a single spread value, such as `...x`".to_string(), - 0, - ) + MdxSignal::Error("Expected a single spread value, such as `...x`".into(), 0) } else { MdxSignal::Ok } @@ -360,8 +357,7 @@ fn whitespace_and_comments(mut index: usize, value: &str) -> MdxSignal { // Outside comment, not whitespace. else { return MdxSignal::Error( - "Could not parse expression with swc: Unexpected content after expression" - .to_string(), + "Could not parse expression with swc: Unexpected content after expression".into(), index, ); } @@ -371,14 +367,14 @@ fn whitespace_and_comments(mut index: usize, value: &str) -> MdxSignal { if in_multiline { MdxSignal::Error( - "Could not parse expression with swc: Unexpected unclosed multiline comment, expected closing: `*/`".to_string(), + "Could not parse expression with swc: Unexpected unclosed multiline comment, expected closing: `*/`".into(), index, ) } else if in_line { // EOF instead of EOL is specifically not allowed, because that would // mean the closing brace is on the commented-out line MdxSignal::Error( - "Could not parse expression with swc: Unexpected unclosed line comment, expected line ending: `\\n`".to_string(), + "Could not parse expression with swc: Unexpected unclosed line comment, expected line ending: `\\n`".into(), index, ) } else { |