Repository: yshavit/mdq (rust)

Issue:
get rid of `#[macro_export]`
replace with `pub(crate) use <macro>`

Pull request description:
replace `macro_export` with `pub(crate) use`
I don't want to export these as part of the API.

resolves #308

Patch:
diff --git a/src/cli.rs b/src/cli.rs
index 9cf6912..e745e62 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -209,7 +209,7 @@ impl Display for OutputFormat {
 #[cfg(test)]
 mod tests {
     use crate::cli::Cli;
-    use crate::unwrap;
+    use crate::utils_for_test::*;
     use clap::{Error, Parser};
 
     #[test]
diff --git a/src/fmt_md.rs b/src/fmt_md.rs
index ad95d29..686112e 100644
--- a/src/fmt_md.rs
+++ b/src/fmt_md.rs
@@ -502,17 +502,15 @@ pub mod tests {
 
     use crate::fmt_md::MdOptions;
     use crate::link_transform::LinkTransform;
-    use crate::m_node;
-    use crate::md_elem;
-    use crate::md_elems;
-    use crate::mdq_inline;
     use crate::output::Output;
     use crate::tree::*;
     use crate::tree_ref::MdElemRef;
+    use crate::tree_test_utils::*;
+    use crate::utils_for_test::*;
 
     use super::{write_md, ReferencePlacement};
 
-    crate::variants_checker!(VARIANTS_CHECKER = MdElemRef {
+    variants_checker!(VARIANTS_CHECKER = MdElemRef {
         Doc(..),
         Section(_),
         ListItem(..),
@@ -607,8 +605,6 @@ pub mod tests {
     }
 
     mod header {
-        use crate::mdq_inline;
-
         use super::*;
 
         #[test]
@@ -2103,7 +2099,6 @@ pub mod tests {
 
     mod annotation_and_footnote_layouts {
         use super::*;
-        use crate::md_elems;
         use indoc::indoc;
 
         #[test]
diff --git a/src/fmt_md_inlines.rs b/src/fmt_md_inlines.rs
index 1088960..15f5e70 100644
--- a/src/fmt_md_inlines.rs
+++ b/src/fmt_md_inlines.rs
@@ -457,13 +457,12 @@ mod tests {
     use super::*;
     use crate::output::{Output, OutputOpts};
     use crate::tree::{MdDoc, ReadOptions};
-    use crate::unwrap;
-    use crate::utils_for_test::get_only;
+    use crate::utils_for_test::*;
 
     mod title_quoting {
         use super::*;
 
-        crate::variants_checker!(TITLE_QUOTING_CHECKER = TitleQuote { Double, Single, Paren });
+        variants_checker!(TITLE_QUOTING_CHECKER = TitleQuote { Double, Single, Paren });
 
         #[test]
         fn bareword_uses_double() {
diff --git a/src/fmt_plain.rs b/src/fmt_plain.rs
index 6fbe967..38742fd 100644
--- a/src/fmt_plain.rs
+++ b/src/fmt_plain.rs
@@ -154,11 +154,12 @@ mod test {
     use super::*;
     use crate::tree::*;
     use crate::tree_ref::{MdElemRef, TableSlice};
-    use crate::{checked_elem_ref, m_node, md_elem, md_elems, mdq_inline};
+    use crate::tree_test_utils::*;
+    use crate::utils_for_test::*;
     use indoc::indoc;
     use markdown::mdast;
 
-    crate::variants_checker!(VARIANTS_CHECKER = MdElemRef {
+    variants_checker!(VARIANTS_CHECKER = MdElemRef {
         Doc(_),
         BlockQuote(_),
         CodeBlock(_),
diff --git a/src/fmt_str.rs b/src/fmt_str.rs
index e494ca3..f22a45b 100644
--- a/src/fmt_str.rs
+++ b/src/fmt_str.rs
@@ -33,10 +33,10 @@ mod tests {
     use indoc::indoc;
 
     use crate::tree::{FormattingVariant, Inline, MdDoc, MdElem, ReadOptions, TextVariant};
-    use crate::unwrap;
+    use crate::utils_for_test::*;
     use markdown::ParseOptions;
 
-    crate::variants_checker!(VARIANTS_CHECKER = Inline {
+    variants_checker!(VARIANTS_CHECKER = Inline {
         Formatting(Formatting{ variant: FormattingVariant::Delete, .. }),
         Formatting(Formatting{ variant: FormattingVariant::Emphasis, .. }),
         Formatting(Formatting{ variant: FormattingVariant::Strong, .. }),
diff --git a/src/link_transform.rs b/src/link_transform.rs
index b16e610..d1e5978 100644
--- a/src/link_transform.rs
+++ b/src/link_transform.rs
@@ -204,9 +204,9 @@ fn inlines_to_string<'md>(inline_writer: &mut MdInlinesWriter<'md>, inlines: &'m
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::mdq_inline;
     use crate::tree::{Link, LinkDefinition, MdContext, Text, TextVariant};
-    use crate::variants_checker;
+    use crate::tree_test_utils::*;
+    use crate::utils_for_test::*;
 
     enum Combo {
         Of(LinkTransform, LinkReference),
diff --git a/src/select/api.rs b/src/select/api.rs
index cd6765e..0f041f8 100644
--- a/src/select/api.rs
+++ b/src/select/api.rs
@@ -239,10 +239,10 @@ impl<'md> SearchContext<'md> {
 mod test {
     /// Only a smoke test, because the code is pretty straightforward, and I don't feel like writing more. :-)
     mod find_children_smoke {
-        use crate::mdq_inline;
         use crate::select::api::{SearchContext, SelectorAdapter};
         use crate::tree::{Inline, Link, LinkDefinition, LinkReference, MdContext, Text, TextVariant};
         use crate::tree_ref::MdElemRef;
+        use crate::tree_test_utils::*;
 
         #[test]
         fn link_direct() {
diff --git a/src/select/sel_table.rs b/src/select/sel_table.rs
index 492305e..7c12a86 100644
--- a/src/select/sel_table.rs
+++ b/src/select/sel_table.rs
@@ -42,7 +42,7 @@ mod tests {
 
     use crate::select::Selector;
     use crate::tree::{Inline, Line, Table, Text, TextVariant};
-    use crate::unwrap;
+    use crate::utils_for_test::*;
     use markdown::mdast;
 
     #[test]
diff --git a/src/tree.rs b/src/tree.rs
index 58bbef8..b74723f 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -313,7 +313,6 @@ macro_rules! mdx_nodes {
 /// ```compile_fail
 /// A::B(B::C(C { foo: 123 }))
 /// ```
-#[macro_export]
 macro_rules! m_node {
     // Terminal cases for Foo{ bar: bazz } in its various configurations
     ($last:ident { $($args:tt)* }) => {
@@ -332,6 +331,7 @@ macro_rules! m_node {
         $head::$next( m_node!($next $(:: $($tail)::*)? $({ $($args)* })?) )
     };
 }
+pub(crate) use m_node;
 
 impl MdDoc {
     pub fn read(node: mdast::Node, opts: &ReadOptions) -> Result<Self, InvalidMd> {
@@ -801,9 +801,8 @@ impl Lookups {
 #[cfg(test)]
 mod tests {
     use super::*;
-    use crate::md_elem;
-    use crate::md_elems;
-    use crate::mdq_inline;
+    use crate::tree_test_utils::*;
+    use crate::utils_for_test::*;
 
     impl MdContext {
         pub fn empty() -> Self {
@@ -832,7 +831,6 @@ mod tests {
     /// For example, footnote are `[^a]` in markdown; does that identifier get parsed as `"^a"` or `"a"`?
     mod all_nodes {
         use super::*;
-        use crate::unwrap;
         use indoc::indoc;
         use markdown::mdast::Node;
         use markdown::{mdast, ParseOptions};
@@ -1955,7 +1953,7 @@ mod tests {
             (root, lookups)
         }
 
-        crate::variants_checker!(NODES_CHECKER = Node {
+        variants_checker!(NODES_CHECKER = Node {
             Blockquote(_),
             Break(_),
             Code(_),
diff --git a/src/tree_ref.rs b/src/tree_ref.rs
index 986f13b..d5c4f15 100644
--- a/src/tree_ref.rs
+++ b/src/tree_ref.rs
@@ -242,18 +242,6 @@ impl<'md> From<TableSlice<'md>> for MdElemRef<'md> {
     }
 }
 
-#[macro_export]
-macro_rules! wrap_mdq_refs {
-    ($variant:ident: $source:expr) => {{
-        let source = $source;
-        let mut result: Vec<MdElemRef> = Vec::with_capacity(source.len());
-        for elem in source {
-            result.push(MdElemRef::$variant(elem));
-        }
-        result
-    }};
-}
-
 #[cfg(test)]
 mod tests {
     mod tables {
diff --git a/src/tree_ref_serde.rs b/src/tree_ref_serde.rs
index e20232b..f97adbc 100644
--- a/src/tree_ref_serde.rs
+++ b/src/tree_ref_serde.rs
@@ -305,13 +305,11 @@ mod tests {
     use super::*;
     use crate::fmt_md_inlines::MdInlinesWriterOptions;
     use crate::link_transform::LinkTransform;
-    use crate::m_node;
-    use crate::md_elems;
     use crate::tree::MdElem;
     use crate::tree::*;
     use crate::tree_ref::ListItemRef;
-    use crate::variants_checker;
-    use crate::{md_elem, mdq_inline};
+    use crate::tree_test_utils::*;
+    use crate::utils_for_test::*;
 
     variants_checker!(CHECKER = MdElemRef {
         Doc(_),


Test patch:
diff --git a/src/tree_test_utils.rs b/src/tree_test_utils.rs
index e931a57..6ac7633 100644
--- a/src/tree_test_utils.rs
+++ b/src/tree_test_utils.rs
@@ -1,26 +1,28 @@
+#[cfg(test)]
+pub(crate) use test_utils::*;
+
 #[cfg(test)]
 mod test_utils {
-    #[macro_export]
     macro_rules! md_elem {
         ( $($node_names:ident)::* {$($attr:ident: $val:expr),* $(,)?}) => {
-            crate::m_node!(MdElem::$($node_names)::* {$($attr: $val),*})
+            crate::tree::m_node!(MdElem::$($node_names)::* {$($attr: $val),*})
         };
         ($paragraph_text:literal) => {
-            crate::m_node!(MdElem::Paragraph{body: vec![crate::mdq_inline!($paragraph_text)]})
+            crate::tree::m_node!(MdElem::Paragraph{body: vec![mdq_inline!($paragraph_text)]})
         };
     }
+    pub(crate) use md_elem;
 
-    #[macro_export]
     macro_rules! md_elems {
         [$($first:tt $( $(:: $($rest:ident)::* )? {$($attr:ident: $val:expr),*$(,)?})? ),*$(,)?] => {
             vec![$(
-                crate::md_elem!($first$( $(:: $($rest)::*)? { $($attr: $val),* })?)
+                md_elem!($first$( $(:: $($rest)::*)? { $($attr: $val),* })?)
                 ),*
             ]
         };
     }
+    pub(crate) use md_elems;
 
-    #[macro_export]
     macro_rules! mdq_inline {
         (span $which:ident [$($contents:expr),*$(,)?]) => {
             crate::tree::Inline::Formatting(Formatting {
@@ -35,4 +37,5 @@ mod test_utils {
             })
         };
     }
+    pub(crate) use mdq_inline;
 }
diff --git a/src/utils_for_test.rs b/src/utils_for_test.rs
index 1607c96..576e3e5 100644
--- a/src/utils_for_test.rs
+++ b/src/utils_for_test.rs
@@ -1,5 +1,5 @@
 #[cfg(test)]
-pub use test_utils::*;
+pub(crate) use test_utils::*;
 
 // We this file's contents from prod by putting them in a submodule guarded by cfg(test), but then "pub use" it to
 // export its contents.
@@ -63,7 +63,6 @@ mod test_utils {
     }
 
     /// Turn a pattern match into an `if let ... { else panic! }`.
-    #[macro_export]
     macro_rules! unwrap {
         ($enum_value:expr, $enum_variant:pat) => {
             let node = $enum_value;
@@ -73,8 +72,8 @@ mod test_utils {
             };
         };
     }
+    pub(crate) use unwrap;
 
-    #[macro_export]
     macro_rules! test_delay_ms {
         ($i:literal) => {{
             time::Duration::from_millis(
@@ -84,9 +83,9 @@ mod test_utils {
             )
         }};
     }
+    pub(crate) use test_delay_ms;
 
     /// Converts an `MdElem` into an `MdElemRef`, checking that it got converted to the right one
-    #[macro_export]
     macro_rules! checked_elem_ref {
         ($input:expr => $variant:pat) => {{
             let as_ref: crate::tree_ref::MdElemRef = (&($input)).into();
@@ -101,6 +100,7 @@ mod test_utils {
             as_ref
         }};
     }
+    pub(crate) use checked_elem_ref;
 
     /// Creates a static object named `$name` that looks for all the variants of enum `E`.
     ///
@@ -136,7 +136,6 @@ mod test_utils {
     ///
     /// This requires that each pattern matches exactly one shape of item; in other words, that there aren't any
     /// dead-code branches.
-    #[macro_export]
     macro_rules! variants_checker {
         ($name:ident = $enum_type:ty { $($variant:pat),* $(,)? } $(ignore { $($ignore_variant:pat),* $(,)? })?) => {
 
@@ -159,7 +158,7 @@ mod test_utils {
                     fn wait_for_all(&self) {
                         use std::{thread, time};
 
-                        let timeout = crate::test_delay_ms!(500);
+                        let timeout = test_delay_ms!(500);
                         let retry_delay = time::Duration::from_millis(50);
                         let start = time::Instant::now();
                         loop {
@@ -201,4 +200,5 @@ mod test_utils {
             }
         };
     }
+    pub(crate) use variants_checker;
 }