Skip to content

rustfmt for libgraphviz #29414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions src/libgraphviz/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
//! }
//!
//! impl<'a> dot::Labeller<'a, Nd, Ed> for Edges {
//! fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new("example1").unwrap() }
//! fn graph_id(&'a self) -> dot::Id<'a> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't look right either

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//! dot::Id::new("example1").unwrap() }
//!
//! fn node_id(&'a self, n: &Nd) -> dot::Id<'a> {
//! dot::Id::new(format!("N{}", *n)).unwrap()
Expand Down Expand Up @@ -169,7 +170,8 @@
//! }
//!
//! impl<'a> dot::Labeller<'a, Nd, Ed<'a>> for Graph {
//! fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new("example2").unwrap() }
//! fn graph_id(&'a self) -> dot::Id<'a> {
//! dot::Id::new("example2").unwrap() }
//! fn node_id(&'a self, n: &Nd) -> dot::Id<'a> {
//! dot::Id::new(format!("N{}", n)).unwrap()
//! }
Expand All @@ -183,7 +185,8 @@
//!
//! impl<'a> dot::GraphWalk<'a, Nd, Ed<'a>> for Graph {
//! fn nodes(&self) -> dot::Nodes<'a,Nd> { (0..self.nodes.len()).collect() }
//! fn edges(&'a self) -> dot::Edges<'a,Ed<'a>> { self.edges.iter().collect() }
//! fn edges(&'a self) -> dot::Edges<'a,Ed<'a>> {
//! self.edges.iter().collect() }
//! fn source(&self, e: &Ed) -> Nd { let & &(s,_) = e; s }
//! fn target(&self, e: &Ed) -> Nd { let & &(_,t) = e; t }
//! }
Expand Down Expand Up @@ -228,7 +231,8 @@
//! }
//!
//! impl<'a> dot::Labeller<'a, Nd<'a>, Ed<'a>> for Graph {
//! fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new("example3").unwrap() }
//! fn graph_id(&'a self) -> dot::Id<'a> {
//! dot::Id::new("example3").unwrap() }
//! fn node_id(&'a self, n: &Nd<'a>) -> dot::Id<'a> {
//! dot::Id::new(format!("N{}", n.0)).unwrap()
//! }
Expand Down Expand Up @@ -417,10 +421,10 @@ impl<'a> Id<'a> {
_ => return Err(()),
}
if !chars.all(is_constituent) {
return Err(())
return Err(());
}
}
return Ok(Id{ name: name });
return Ok(Id { name: name });

fn is_letter_or_underscore(c: char) -> bool {
in_range('a', c, 'z') || in_range('A', c, 'Z') || c == '_'
Expand Down Expand Up @@ -497,11 +501,10 @@ pub trait Labeller<'a,N,E> {
/// Escape tags in such a way that it is suitable for inclusion in a
/// Graphviz HTML label.
pub fn escape_html(s: &str) -> String {
s
.replace("&", "&amp;")
.replace("\"", "&quot;")
.replace("<", "&lt;")
.replace(">", "&gt;")
s.replace("&", "&amp;")
.replace("\"", "&quot;")
.replace("<", "&lt;")
.replace(">", "&gt;")
}

impl<'a> LabelText<'a> {
Expand Down Expand Up @@ -739,7 +742,12 @@ mod tests {
}

fn edge(from: usize, to: usize, label: &'static str, style: Style) -> Edge {
Edge { from: from, to: to, label: label, style: style }
Edge {
from: from,
to: to,
label: label,
style: style,
}
}

struct LabelledGraph {
Expand Down Expand Up @@ -916,7 +924,7 @@ mod tests {
let labels: Trivial = UnlabelledNodes(0);
let r = test_input(LabelledGraph::new("empty_graph", labels, vec![], None));
assert_eq!(r.unwrap(),
r#"digraph empty_graph {
r#"digraph empty_graph {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
"#);
}
Expand All @@ -926,7 +934,7 @@ r#"digraph empty_graph {
let labels: Trivial = UnlabelledNodes(1);
let r = test_input(LabelledGraph::new("single_node", labels, vec![], None));
assert_eq!(r.unwrap(),
r#"digraph single_node {
r#"digraph single_node {
N0[label="N0"];
}
"#);
Expand All @@ -938,7 +946,7 @@ r#"digraph single_node {
let styles = Some(vec![Style::Dashed]);
let r = test_input(LabelledGraph::new("single_node", labels, vec![], styles));
assert_eq!(r.unwrap(),
r#"digraph single_node {
r#"digraph single_node {
N0[label="N0"][style="dashed"];
}
"#);
Expand All @@ -952,7 +960,7 @@ r#"digraph single_node {
vec![edge(0, 1, "E", Style::None)],
None));
assert_eq!(result.unwrap(),
r#"digraph single_edge {
r#"digraph single_edge {
N0[label="N0"];
N1[label="N1"];
N0 -> N1[label="E"];
Expand All @@ -968,7 +976,7 @@ r#"digraph single_edge {
vec![edge(0, 1, "E", Style::Bold)],
None));
assert_eq!(result.unwrap(),
r#"digraph single_edge {
r#"digraph single_edge {
N0[label="N0"];
N1[label="N1"];
N0 -> N1[label="E"][style="bold"];
Expand All @@ -985,7 +993,7 @@ r#"digraph single_edge {
vec![edge(0, 1, "A-1", Style::None)],
styles));
assert_eq!(result.unwrap(),
r#"digraph test_some_labelled {
r#"digraph test_some_labelled {
N0[label="A"];
N1[label="N1"][style="dotted"];
N0 -> N1[label="A-1"];
Expand All @@ -1001,7 +1009,7 @@ r#"digraph test_some_labelled {
vec![edge(0, 0, "E", Style::None)],
None));
assert_eq!(r.unwrap(),
r#"digraph single_cyclic_node {
r#"digraph single_cyclic_node {
N0[label="N0"];
N0 -> N0[label="E"];
}
Expand All @@ -1010,7 +1018,7 @@ r#"digraph single_cyclic_node {

#[test]
fn hasse_diagram() {
let labels = AllNodesLabelled(vec!("{x,y}", "{x}", "{y}", "{}"));
let labels = AllNodesLabelled(vec!["{x,y}", "{x}", "{y}", "{}"]);
let r = test_input(LabelledGraph::new("hasse_diagram",
labels,
vec![edge(0, 1, "", Style::None),
Expand All @@ -1019,7 +1027,7 @@ r#"digraph single_cyclic_node {
edge(2, 3, "", Style::None)],
None));
assert_eq!(r.unwrap(),
r#"digraph hasse_diagram {
r#"digraph hasse_diagram {
N0[label="{x,y}"];
N1[label="{x}"];
N2[label="{y}"];
Expand All @@ -1034,17 +1042,11 @@ r#"digraph hasse_diagram {

#[test]
fn left_aligned_text() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be #[rustfmt_skip] since the formatting is significant.

let labels = AllNodesLabelled(vec!(
"if test {\
\\l branch1\
\\l} else {\
\\l branch2\
\\l}\
\\lafterward\
\\l",
"branch1",
"branch2",
"afterward"));
let labels = AllNodesLabelled(vec!["if test {\\l branch1\\l} else {\\l \
branch2\\l}\\lafterward\\l",
"branch1",
"branch2",
"afterward"]);

let mut writer = Vec::new();

Expand All @@ -1060,7 +1062,7 @@ r#"digraph hasse_diagram {
Read::read_to_string(&mut &*writer, &mut r).unwrap();

assert_eq!(r,
r#"digraph syntax_tree {
r#"digraph syntax_tree {
N0[label="if test {\l branch1\l} else {\l branch2\l}\lafterward\l"];
N1[label="branch1"];
N2[label="branch2"];
Expand Down