Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

more JSON tests

  • Loading branch information...
commit 07ee4da6030774eb69fd23599a55590f1379045f 1 parent fecece4
@bfontaine authored
Showing with 71 additions and 0 deletions.
  1. +71 −0 tests/json_tests.rb
View
71 tests/json_tests.rb
@@ -60,3 +60,74 @@ def setup
end
end
+
+class JSON_test < Test::Unit::TestCase
+
+ # == JSON::parse == #
+
+ def test_parse_empty_graph
+ g = JSONGraph::parse('')
+
+ assert_equal([], g.nodes)
+ assert_equal([], g.edges)
+ end
+
+ def test_parse_empty_graph_with_nodes_list
+
+ s = '{"nodes":[]}'
+
+ g = JSONGraph::parse(s)
+
+ assert_equal([], g.nodes)
+ assert_equal([], g.edges)
+ end
+
+ def test_parse_empty_graph_with_nodes_and_edges_lists
+ s = '{"nodes":[],"edges":[]}'
+ g = JSONGraph::parse(s)
+
+ assert_equal([], g.nodes)
+ assert_equal([], g.edges)
+ end
+
+ def test_parse_one_node_no_edge
+ s = '{"nodes":[{"label":"foo"}]}'
+ g = JSONGraph::parse(s)
+
+ assert_equal(1, g.nodes.length)
+ assert_equal('foo', g.nodes[0]['label'])
+ assert_equal([], g.edges)
+ end
+
+ def test_parse_sample_graph
+ g = JSONGraph::parse(JSONUtils::get_sample_graph)
+
+ assert_equal(2, g.nodes.length)
+ assert_equal(1, g.edges.length)
+
+ assert_equal('foo', g.nodes[0]['label'])
+ assert_equal('bar', g.nodes[1]['label'])
+
+ assert_equal('bar', g.edges[0]['node1'])
+ assert_equal('foo', g.edges[0]['node2'])
+
+ end
+
+ # == JSON::unparse == #
+
+ def test_unparse_empty_graph
+ g = Graph.new
+
+ s = JSONGraph::unparse(g)
+
+ assert_equal('{"nodes":[],"edges":[]}', s)
+ end
+
+ def test_unparse_sample_graph
+ g1 = JSONGraph::parse(JSONUtils::get_sample_graph)
+ g2 = JSONGraph::parse(JSONGraph::unparse(g1))
+
+ assert_equal(g1, g2)
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.