Change the AsciiGraphDrawer interface form &[u8] to &str

This commit is contained in:
Michael Forster 2023-01-16 10:08:48 +01:00 committed by Mike Forster
parent 84fc66fe50
commit cf809aefc4
2 changed files with 164 additions and 153 deletions

View file

@ -1710,12 +1710,13 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
&diff_formats,
)?;
}
let node_symbol = if is_checkout { b"@" } else { b"o" };
let node_symbol = if is_checkout { "@" } else { "o" };
graph.add_node(
&index_entry.position(),
&graphlog_edges,
node_symbol,
&buffer,
&String::from_utf8_lossy(&buffer),
)?;
}
} else {
@ -1823,11 +1824,16 @@ fn cmd_obslog(ui: &mut Ui, command: &CommandHelper, args: &ObslogArgs) -> Result
)?;
}
let node_symbol = if Some(commit.id()) == wc_commit_id {
b"@"
"@"
} else {
b"o"
"o"
};
graph.add_node(commit.id(), &edges, node_symbol, &buffer)?;
graph.add_node(
commit.id(),
&edges,
node_symbol,
&String::from_utf8_lossy(&buffer),
)?;
}
} else {
for commit in commits {
@ -3505,8 +3511,13 @@ fn cmd_op_log(
if !buffer.ends_with(b"\n") {
buffer.push(b'\n');
}
let node_symbol = if is_head_op { b"@" } else { b"o" };
graph.add_node(op.id(), &edges, node_symbol, &buffer)?;
let node_symbol = if is_head_op { "@" } else { "o" };
graph.add_node(
op.id(),
&edges,
node_symbol,
&String::from_utf8_lossy(&buffer),
)?;
}
Ok(())

View file

@ -46,7 +46,7 @@ impl<T> Edge<T> {
pub struct AsciiGraphDrawer<'writer, K> {
writer: &'writer mut dyn Write,
edges: Vec<Edge<K>>,
pending_text: Vec<Vec<u8>>,
pending_text: Vec<String>,
}
impl<'writer, K> AsciiGraphDrawer<'writer, K>
@ -65,14 +65,14 @@ where
&mut self,
id: &K,
edges: &[Edge<K>],
node_symbol: &[u8],
text: &[u8],
node_symbol: &str,
text: &str,
) -> io::Result<()> {
assert!(self.pending_text.is_empty());
for line in text.split(|x| x == &b'\n') {
self.pending_text.push(line.to_vec());
for line in text.split(|x| x == '\n') {
self.pending_text.push(line.into());
}
if self.pending_text.last() == Some(&vec![]) {
if self.pending_text.last() == Some(&"".into()) {
self.pending_text.pop().unwrap();
}
self.pending_text.reverse();
@ -91,12 +91,12 @@ where
AsciiGraphDrawer::straight_edge(&mut self.writer, edge)?;
}
for _ in 0..i - 2 {
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
}
for _ in edge_index + 1..self.edges.len() {
self.writer.write_all(b" \\")?;
write!(self.writer, " \\")?;
}
self.writer.write_all(b"\n")?;
write!(self.writer, "\n")?;
}
}
@ -111,21 +111,21 @@ where
AsciiGraphDrawer::straight_edge(&mut self.writer, edge)?;
}
// Draw the new node
self.writer.write_all(node_symbol)?;
write!(self.writer, "{node_symbol}")?;
// If it's a merge of many nodes, draw a vertical line to the right
for _ in 3..edges.len() {
self.writer.write_all(b"--")?;
write!(self.writer, "--")?;
}
if edges.len() > 2 {
self.writer.write_all(b"-.")?;
write!(self.writer, "-.")?;
}
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
// Draw the edges to the right of the new node
for edge in self.edges.iter().skip(edge_index) {
AsciiGraphDrawer::straight_edge(&mut self.writer, edge)?;
}
if edges.len() > 1 {
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
}
self.maybe_write_pending_text()?;
@ -142,9 +142,9 @@ where
}
AsciiGraphDrawer::straight_edge_no_space(&mut self.writer, &self.edges[edge_index])?;
for _ in edge_index + 1..self.edges.len() {
self.writer.write_all(b"\\ ")?;
write!(self.writer, "\\ ")?;
}
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
self.maybe_write_pending_text()?;
}
@ -184,7 +184,7 @@ where
AsciiGraphDrawer::straight_edge(&mut self.writer, edge)?;
}
for _ in self.edges.len()..pad_to_index {
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
}
self.maybe_write_pending_text()?;
}
@ -206,7 +206,7 @@ where
/// whole struct.
fn straight_edge(writer: &mut dyn Write, edge: &Edge<K>) -> io::Result<()> {
AsciiGraphDrawer::straight_edge_no_space(writer, edge)?;
writer.write_all(b" ")
write!(writer, " ")
}
/// Not an instance method so the caller doesn't need mutable access to the
@ -214,13 +214,13 @@ where
fn straight_edge_no_space(writer: &mut dyn Write, edge: &Edge<K>) -> io::Result<()> {
match edge {
Edge::Present { direct: true, .. } => {
writer.write_all(b"|")?;
write!(writer, "|")?;
}
Edge::Present { direct: false, .. } => {
writer.write_all(b":")?;
write!(writer, ":")?;
}
Edge::Missing => {
writer.write_all(b"|")?;
write!(writer, "|")?;
}
}
Ok(())
@ -236,11 +236,11 @@ where
// If we're merging exactly one step to the left, draw a '/' to join the lines.
AsciiGraphDrawer::straight_edge_no_space(&mut self.writer, &self.edges[target])?;
for _ in source..self.edges.len() + 1 {
self.writer.write_all(b"/ ")?;
write!(self.writer, "/ ")?;
}
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
for _ in self.edges.len() + 1..pad_to_index {
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
}
} else {
// If we're merging more than one step to the left, we need two rows:
@ -249,15 +249,15 @@ where
AsciiGraphDrawer::straight_edge(&mut self.writer, &self.edges[target])?;
for i in target + 1..source - 1 {
AsciiGraphDrawer::straight_edge_no_space(&mut self.writer, &self.edges[i])?;
self.writer.write_all(b"_")?;
write!(self.writer, "_")?;
}
AsciiGraphDrawer::straight_edge_no_space(&mut self.writer, &self.edges[source - 1])?;
for _ in source..self.edges.len() + 1 {
self.writer.write_all(b"/ ")?;
write!(self.writer, "/ ")?;
}
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
for _ in self.edges.len() + 1..pad_to_index {
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
}
self.maybe_write_pending_text()?;
@ -265,12 +265,12 @@ where
AsciiGraphDrawer::straight_edge(&mut self.writer, &self.edges[i])?;
}
AsciiGraphDrawer::straight_edge_no_space(&mut self.writer, &self.edges[target])?;
self.writer.write_all(b"/")?;
write!(self.writer, "/")?;
for i in target + 1..self.edges.len() {
AsciiGraphDrawer::straight_edge(&mut self.writer, &self.edges[i])?;
}
for _ in self.edges.len()..pad_to_index {
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
}
}
self.maybe_write_pending_text()?;
@ -283,13 +283,13 @@ where
for i in 0..source {
AsciiGraphDrawer::straight_edge(&mut self.writer, &self.edges[i])?;
}
self.writer.write_all(b"~")?;
write!(self.writer, "~")?;
for _ in source..self.edges.len() {
self.writer.write_all(b"/ ")?;
write!(self.writer, "/ ")?;
}
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
for _ in self.edges.len() + 1..pad_to_index {
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
}
self.maybe_write_pending_text()
}
@ -298,22 +298,22 @@ where
for i in 0..source {
AsciiGraphDrawer::straight_edge(&mut self.writer, &self.edges[i])?;
}
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
for _ in source..self.edges.len() {
self.writer.write_all(b"/ ")?;
write!(self.writer, "/ ")?;
}
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
for _ in self.edges.len() + 1..pad_to_index {
self.writer.write_all(b" ")?;
write!(self.writer, " ")?;
}
self.maybe_write_pending_text()
}
fn maybe_write_pending_text(&mut self) -> io::Result<()> {
if let Some(text) = self.pending_text.pop() {
self.writer.write_all(&text)?;
write!(self.writer, "{text}")?;
}
self.writer.write_all(b"\n")
write!(self.writer, "\n")
}
}
@ -325,7 +325,7 @@ mod tests {
fn single_node() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&1, &[], b"@", b"node 1")?;
graph.add_node(&1, &[], "@", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
@ node 1
@ -338,8 +338,8 @@ mod tests {
fn long_description() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&2, &[Edge::direct(1)], b"@", b"many\nlines\nof\ntext\n")?;
graph.add_node(&1, &[], b"o", b"single line")?;
graph.add_node(&2, &[Edge::direct(1)], "@", "many\nlines\nof\ntext\n")?;
graph.add_node(&1, &[], "o", "single line")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
@ many
@ -359,10 +359,10 @@ mod tests {
graph.add_node(
&2,
&[Edge::direct(1)],
b"@",
b"\n\nmany\n\nlines\n\nof\n\ntext\n\n\n",
"@",
"\n\nmany\n\nlines\n\nof\n\ntext\n\n\n",
)?;
graph.add_node(&1, &[], b"o", b"single line")?;
graph.add_node(&1, &[], "o", "single line")?;
// A final newline is ignored but all other newlines are respected.
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
@ -387,9 +387,9 @@ mod tests {
fn chain() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&3, &[Edge::direct(2)], b"@", b"node 3")?;
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&3, &[Edge::direct(2)], "@", "node 3")?;
graph.add_node(&2, &[Edge::direct(1)], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
@ node 3
@ -404,13 +404,13 @@ mod tests {
fn interleaved_chains() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&7, &[Edge::direct(5)], b"o", b"node 7")?;
graph.add_node(&6, &[Edge::direct(4)], b"o", b"node 6")?;
graph.add_node(&5, &[Edge::direct(3)], b"o", b"node 5")?;
graph.add_node(&4, &[Edge::direct(2)], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::direct(1)], b"@", b"node 3")?;
graph.add_node(&2, &[], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&7, &[Edge::direct(5)], "o", "node 7")?;
graph.add_node(&6, &[Edge::direct(4)], "o", "node 6")?;
graph.add_node(&5, &[Edge::direct(3)], "o", "node 5")?;
graph.add_node(&4, &[Edge::direct(2)], "o", "node 4")?;
graph.add_node(&3, &[Edge::direct(1)], "@", "node 3")?;
graph.add_node(&2, &[], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 7
@ -429,9 +429,9 @@ mod tests {
fn independent_nodes() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&3, &[Edge::missing()], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::missing()], b"o", b"node 2")?;
graph.add_node(&1, &[Edge::missing()], b"@", b"node 1")?;
graph.add_node(&3, &[Edge::missing()], "o", "node 3")?;
graph.add_node(&2, &[Edge::missing()], "o", "node 2")?;
graph.add_node(&1, &[Edge::missing()], "@", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 3
@ -449,10 +449,10 @@ mod tests {
fn left_chain_ends() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&4, &[Edge::direct(2)], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::missing()], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&4, &[Edge::direct(2)], "o", "node 4")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(&2, &[Edge::missing()], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 4
@ -469,10 +469,10 @@ mod tests {
fn left_chain_ends_with_no_missing_edge() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&4, &[Edge::direct(2)], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&2, &[], b"o", b"node 2\nmore\ntext")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&4, &[Edge::direct(2)], "o", "node 4")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(&2, &[], "o", "node 2\nmore\ntext")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 4
@ -490,10 +490,10 @@ mod tests {
fn right_chain_ends() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&4, &[Edge::direct(1)], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::direct(2)], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::missing()], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1\nmore\ntext")?;
graph.add_node(&4, &[Edge::direct(1)], "o", "node 4")?;
graph.add_node(&3, &[Edge::direct(2)], "o", "node 3")?;
graph.add_node(&2, &[Edge::missing()], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1\nmore\ntext")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 4
@ -512,14 +512,14 @@ mod tests {
fn right_chain_ends_long_description() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(
&2,
&[Edge::missing()],
b"o",
b"node 2\nwith\nlong\ndescription",
"o",
"node 2\nwith\nlong\ndescription",
)?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 3
@ -537,10 +537,10 @@ mod tests {
fn fork_multiple() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&4, &[Edge::direct(1)], b"@", b"node 4")?;
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&4, &[Edge::direct(1)], "@", "node 4")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(&2, &[Edge::direct(1)], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
@ node 4
@ -558,16 +558,16 @@ mod tests {
fn fork_multiple_chains() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&10, &[Edge::direct(7)], b"o", b"node 10")?;
graph.add_node(&9, &[Edge::direct(6)], b"o", b"node 9")?;
graph.add_node(&8, &[Edge::direct(5)], b"o", b"node 8")?;
graph.add_node(&7, &[Edge::direct(4)], b"o", b"node 7")?;
graph.add_node(&6, &[Edge::direct(3)], b"o", b"node 6")?;
graph.add_node(&5, &[Edge::direct(2)], b"o", b"node 5")?;
graph.add_node(&4, &[Edge::direct(1)], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&10, &[Edge::direct(7)], "o", "node 10")?;
graph.add_node(&9, &[Edge::direct(6)], "o", "node 9")?;
graph.add_node(&8, &[Edge::direct(5)], "o", "node 8")?;
graph.add_node(&7, &[Edge::direct(4)], "o", "node 7")?;
graph.add_node(&6, &[Edge::direct(3)], "o", "node 6")?;
graph.add_node(&5, &[Edge::direct(2)], "o", "node 5")?;
graph.add_node(&4, &[Edge::direct(1)], "o", "node 4")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(&2, &[Edge::direct(1)], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 10
@ -591,11 +591,11 @@ mod tests {
fn cross_over() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&5, &[Edge::direct(1)], b"o", b"node 5")?;
graph.add_node(&4, &[Edge::direct(2)], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&5, &[Edge::direct(1)], "o", "node 5")?;
graph.add_node(&4, &[Edge::direct(2)], "o", "node 4")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(&2, &[Edge::direct(1)], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 5
@ -615,13 +615,13 @@ mod tests {
fn cross_over_multiple() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&7, &[Edge::direct(1)], b"o", b"node 7")?;
graph.add_node(&6, &[Edge::direct(3)], b"o", b"node 6")?;
graph.add_node(&5, &[Edge::direct(2)], b"o", b"node 5")?;
graph.add_node(&4, &[Edge::direct(1)], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&7, &[Edge::direct(1)], "o", "node 7")?;
graph.add_node(&6, &[Edge::direct(3)], "o", "node 6")?;
graph.add_node(&5, &[Edge::direct(2)], "o", "node 5")?;
graph.add_node(&4, &[Edge::direct(1)], "o", "node 4")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(&2, &[Edge::direct(1)], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 7
@ -644,12 +644,12 @@ mod tests {
fn cross_over_new_on_left() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&6, &[Edge::direct(3)], b"o", b"node 6")?;
graph.add_node(&5, &[Edge::direct(2)], b"o", b"node 5")?;
graph.add_node(&4, &[Edge::direct(1)], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&6, &[Edge::direct(3)], "o", "node 6")?;
graph.add_node(&5, &[Edge::direct(2)], "o", "node 5")?;
graph.add_node(&4, &[Edge::direct(1)], "o", "node 4")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(&2, &[Edge::direct(1)], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 6
@ -678,13 +678,13 @@ mod tests {
Edge::direct(3),
Edge::direct(4),
],
b"@",
b"node 5\nmore\ntext",
"@",
"node 5\nmore\ntext",
)?;
graph.add_node(&4, &[Edge::missing()], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::missing()], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::missing()], b"o", b"node 2")?;
graph.add_node(&1, &[Edge::missing()], b"o", b"node 1")?;
graph.add_node(&4, &[Edge::missing()], "o", "node 4")?;
graph.add_node(&3, &[Edge::missing()], "o", "node 3")?;
graph.add_node(&2, &[Edge::missing()], "o", "node 2")?;
graph.add_node(&1, &[Edge::missing()], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
@---. node 5
@ -707,19 +707,19 @@ mod tests {
fn fork_merge_in_central_edge() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&8, &[Edge::direct(1)], b"o", b"node 8")?;
graph.add_node(&7, &[Edge::direct(5)], b"o", b"node 7")?;
graph.add_node(&8, &[Edge::direct(1)], "o", "node 8")?;
graph.add_node(&7, &[Edge::direct(5)], "o", "node 7")?;
graph.add_node(
&6,
&[Edge::direct(2)],
b"o",
b"node 6\nwith\nsome\nmore\nlines",
"o",
"node 6\nwith\nsome\nmore\nlines",
)?;
graph.add_node(&5, &[Edge::direct(4), Edge::direct(3)], b"o", b"node 5")?;
graph.add_node(&4, &[Edge::direct(1)], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&5, &[Edge::direct(4), Edge::direct(3)], "o", "node 5")?;
graph.add_node(&4, &[Edge::direct(1)], "o", "node 4")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(&2, &[Edge::direct(1)], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 8
@ -747,17 +747,17 @@ mod tests {
fn fork_merge_multiple() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&6, &[Edge::direct(5)], b"o", b"node 6")?;
graph.add_node(&6, &[Edge::direct(5)], "o", "node 6")?;
graph.add_node(
&5,
&[Edge::direct(2), Edge::direct(3), Edge::direct(4)],
b"o",
b"node 5",
"o",
"node 5",
)?;
graph.add_node(&4, &[Edge::direct(1)], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&4, &[Edge::direct(1)], "o", "node 4")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(&2, &[Edge::direct(1)], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 6
@ -778,9 +778,9 @@ mod tests {
fn fork_merge_multiple_in_central_edge() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&10, &[Edge::direct(1)], b"o", b"node 10")?;
graph.add_node(&9, &[Edge::direct(7)], b"o", b"node 9")?;
graph.add_node(&8, &[Edge::direct(2)], b"o", b"node 8")?;
graph.add_node(&10, &[Edge::direct(1)], "o", "node 10")?;
graph.add_node(&9, &[Edge::direct(7)], "o", "node 9")?;
graph.add_node(&8, &[Edge::direct(2)], "o", "node 8")?;
graph.add_node(
&7,
&[
@ -789,15 +789,15 @@ mod tests {
Edge::direct(4),
Edge::direct(3),
],
b"o",
b"node 7",
"o",
"node 7",
)?;
graph.add_node(&6, &[Edge::direct(1)], b"o", b"node 6")?;
graph.add_node(&5, &[Edge::direct(1)], b"o", b"node 5")?;
graph.add_node(&4, &[Edge::direct(1)], b"o", b"node 4")?;
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&2, &[Edge::direct(1)], b"o", b"node 2")?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&6, &[Edge::direct(1)], "o", "node 6")?;
graph.add_node(&5, &[Edge::direct(1)], "o", "node 5")?;
graph.add_node(&4, &[Edge::direct(1)], "o", "node 4")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(&2, &[Edge::direct(1)], "o", "node 2")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 10
@ -835,8 +835,8 @@ mod tests {
Edge::missing(),
Edge::missing(),
],
b"@",
b"node 1\nwith\nmany\nlines\nof\ntext",
"@",
"node 1\nwith\nmany\nlines\nof\ntext",
)?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
@ -855,7 +855,7 @@ mod tests {
fn merge_missing_edges_and_fork() -> io::Result<()> {
let mut buffer = vec![];
let mut graph = AsciiGraphDrawer::new(&mut buffer);
graph.add_node(&3, &[Edge::direct(1)], b"o", b"node 3")?;
graph.add_node(&3, &[Edge::direct(1)], "o", "node 3")?;
graph.add_node(
&2,
&[
@ -864,10 +864,10 @@ mod tests {
Edge::missing(),
Edge::indirect(1),
],
b"o",
b"node 2\nwith\nmany\nlines\nof\ntext",
"o",
"node 2\nwith\nmany\nlines\nof\ntext",
)?;
graph.add_node(&1, &[], b"o", b"node 1")?;
graph.add_node(&1, &[], "o", "node 1")?;
insta::assert_snapshot!(String::from_utf8_lossy(&buffer), @r###"
o node 3