Skip to content

Commit

Permalink
Merge pull request #62 from Paalon/master
Browse files Browse the repository at this point in the history
Add double quotations for labels for savedot
  • Loading branch information
gdalle authored May 30, 2023
2 parents 063399b + a650dc0 commit 5c98f33
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "MetaGraphsNext"
uuid = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
version = "0.5.0"
version = "0.6.0-DEV"

[deps]
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
Expand Down
2 changes: 1 addition & 1 deletion src/MetaGraphsNext.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
MetaGraphsNext
A package for graphs with vertex labels and metadata in Julia. Its main export is the [`MetaGraph`](@ref) type.
A package for graphs with vertex labels and metadata in Julia. Its main export is the `MetaGraph` type.
"""
module MetaGraphsNext

Expand Down
6 changes: 6 additions & 0 deletions src/persistence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,24 @@ function savedot(io::IO, meta_graph::MetaGraph)

for label in keys(meta_graph.vertex_properties)
write(io, " ")
write(io, '"')
write(io, label)
write(io, '"')
show_meta_list(io, meta_graph[label])
write(io, '\n')
end

for (label_1, label_2) in keys(edge_data)
write(io, " ")
write(io, '"')
write(io, label_1)
write(io, '"')
write(io, ' ')
write(io, dash)
write(io, ' ')
write(io, '"')
write(io, label_2)
write(io, '"')
show_meta_list(io, edge_data[arrange(meta_graph, label_1, label_2)])
write(io, "\n")
end
Expand Down
56 changes: 51 additions & 5 deletions test/tutorial/3_files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ simple_str = mktemp() do file, io
read(file, String)
end

print(simple_str) #md
@test simple_str == "graph T {\n a\n b\n a -- b\n}\n" #src
simple_str_true = """
graph T {
"a"
"b"
"a" -- "b"
}
"""

simple_str == simple_str_true
@test simple_str == simple_str_true #src

#-

Expand All @@ -58,6 +66,44 @@ complicated_str = mktemp() do file, io
read(file, String)
end

print(complicated_str) #md
@test complicated_str == #src
"digraph G {\n tagged = true\n a [code_1 = 1, code_2 = 2]\n b [code = 2]\n a -> b [code = 12]\n}\n" #src
complicated_str_true = """
digraph G {
tagged = true
"a" [code_1 = 1, code_2 = 2]
"b" [code = 2]
"a" -> "b" [code = 12]
}
"""

@test complicated_str == complicated_str_true #src

#-

with_spaces = MetaGraph(
DiGraph();
label_type=String,
vertex_data_type=Dict{Symbol,String},
edge_data_type=Dict{Symbol,String},
)

with_spaces["a b"] = Dict(:label => "A B")

with_spaces["c d"] = Dict(:label => "C D")

with_spaces["a b", "c d"] = Dict(:label => "A B to C D")

with_spaces_str = mktemp() do file, io
savegraph(file, with_spaces, DOTFormat())
read(file, String)
end

with_spaces_str_true = """
digraph G {
"a b" [label = "A B"]
"c d" [label = "C D"]
"a b" -> "c d" [label = "A B to C D"]
}
"""

with_spaces_str == with_spaces_str_true
@test with_spaces_str == with_spaces_str_true #src

0 comments on commit 5c98f33

Please sign in to comment.