-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Closed
rustfmt for libgraphviz #29414
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> { | ||
//! dot::Id::new("example1").unwrap() } | ||
//! | ||
//! fn node_id(&'a self, n: &Nd) -> dot::Id<'a> { | ||
//! dot::Id::new(format!("N{}", *n)).unwrap() | ||
|
@@ -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() | ||
//! } | ||
|
@@ -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 } | ||
//! } | ||
|
@@ -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() | ||
//! } | ||
|
@@ -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 == '_' | ||
|
@@ -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("&", "&") | ||
.replace("\"", """) | ||
.replace("<", "<") | ||
.replace(">", ">") | ||
s.replace("&", "&") | ||
.replace("\"", """) | ||
.replace("<", "<") | ||
.replace(">", ">") | ||
} | ||
|
||
impl<'a> LabelText<'a> { | ||
|
@@ -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 { | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and below: https://github.com/nrc/rustfmt/issues/559 |
||
} | ||
"#); | ||
} | ||
|
@@ -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"]; | ||
} | ||
"#); | ||
|
@@ -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"]; | ||
} | ||
"#); | ||
|
@@ -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"]; | ||
|
@@ -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"]; | ||
|
@@ -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"]; | ||
|
@@ -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"]; | ||
} | ||
|
@@ -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), | ||
|
@@ -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}"]; | ||
|
@@ -1034,17 +1042,11 @@ r#"digraph hasse_diagram { | |
|
||
#[test] | ||
fn left_aligned_text() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably be |
||
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(); | ||
|
||
|
@@ -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"]; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/nrc/rustfmt/issues/554