Skip to content

Commit b0e23d6

Browse files
authored
Merge pull request #79 from boydm/boyd
Add missing tests
2 parents 252c404 + dc123d1 commit b0e23d6

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

lib/scenic/cache/term.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule Scenic.Cache.Term do
1111
alias Scenic.Cache
1212
alias Scenic.Cache.Hash
1313

14-
# import IEx
14+
# import IEx
1515

1616
# --------------------------------------------------------
1717
def load(path, hash, opts \\ [])

test/scenic/cache/file_test.exs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ defmodule Scenic.Cache.FileReadTest do
8888
decompress: true
8989
) == {:error, :hash_failure}
9090
end
91+
92+
test "read passes through errors" do
93+
# missing term file
94+
assert Cache.File.read(
95+
"not/valid/path",
96+
@invalid_sha256,
97+
hash: :sha256
98+
) == {:error, :enoent}
99+
end
91100
end
92101

93102
defmodule Scenic.Cache.FileLoadTest do
@@ -187,4 +196,13 @@ defmodule Scenic.Cache.FileLoadTest do
187196
decompress: true
188197
) == {:error, :hash_failure}
189198
end
199+
200+
test "load passes through errors" do
201+
# missing term file
202+
assert Cache.File.load(
203+
"not/valid/path",
204+
@invalid_sha256,
205+
hash: :sha256
206+
) == {:error, :enoent}
207+
end
190208
end

test/scenic/cache/term_test.exs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ defmodule Scenic.Cache.TermReadTest do
7575
@sample_sha
7676
) == {:error, :invalid_term}
7777
end
78+
79+
test "read passes through errors" do
80+
# missing term file
81+
assert Cache.Term.read(
82+
"not/valid/path",
83+
@invalid_sha256,
84+
hash: :sha256
85+
) == {:error, :enoent}
86+
end
7887
end
7988

8089
defmodule Scenic.Cache.TermLoadTest do
@@ -98,6 +107,9 @@ defmodule Scenic.Cache.TermLoadTest do
98107
@sample_path "test/artifacts/sample_file"
99108
@sample_sha "2PGNXGkoTc4stYncIe-qCdZFuw0"
100109

110+
@non_term_path "test/artifacts/sample_file"
111+
@non_term_sha "2PGNXGkoTc4stYncIe-qCdZFuw0"
112+
101113
@cache_table :scenic_cache_key_table
102114
@scope_table :scenic_cache_scope_table
103115

@@ -155,4 +167,19 @@ defmodule Scenic.Cache.TermLoadTest do
155167
@sample_sha
156168
) == {:error, :invalid_term}
157169
end
170+
171+
test "load passes through errors" do
172+
# missing term file
173+
assert Cache.Term.load(
174+
"not/valid/path",
175+
@invalid_sha256,
176+
hash: :sha256
177+
) == {:error, :enoent}
178+
179+
# badly formatted term file
180+
assert Cache.Term.load(
181+
@non_term_path,
182+
@non_term_sha
183+
) == {:error, :invalid_term}
184+
end
158185
end

test/scenic/graph_test.exs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,25 @@ defmodule Scenic.GraphTest do
441441
# # assert Map.get(merged, :input) == [:key, :char, :cursor_down]
442442
# end
443443

444+
# ============================================================================
445+
# add
446+
447+
test "add a pre-built primitive to a graph" do
448+
p = Primitive.Line.build({{0, 0}, {2, 2}}, id: :added)
449+
graph = Graph.add(@graph_find, p)
450+
Graph.get!(graph, :added)
451+
end
452+
453+
test "add a new primitive to a graph" do
454+
count = Graph.count(@graph_find)
455+
456+
post_add_count =
457+
Graph.add(@graph_find, Primitive.Line, {{0, 0}, {2, 2}})
458+
|> Graph.count()
459+
460+
assert post_add_count > count
461+
end
462+
444463
# ============================================================================
445464
# def modify( graph, uid, action )
446465

@@ -639,4 +658,8 @@ defmodule Scenic.GraphTest do
639658
assert Map.get(graph.primitives[t1], :transforms) == @transform
640659
assert Map.get(graph.primitives[other], :transforms) == nil
641660
end
661+
662+
test "style_stack returns an empty map for invalid uid" do
663+
assert Graph.style_stack(@graph_find, 1234) == %{}
664+
end
642665
end

0 commit comments

Comments
 (0)