Skip to content

Commit

Permalink
adds Ast.encode/1
Browse files Browse the repository at this point in the history
  • Loading branch information
c-brenn committed Mar 26, 2017
1 parent 6d25953 commit 663fbd4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
6 changes: 1 addition & 5 deletions panacea/lib/panacea/pml/analysis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ defmodule Panacea.Pml.Analysis do
defstruct [:ast, :clashes, :drugs, :unnamed]

def run(ast) do
encoded_ast =
ast
|> :erlang.term_to_binary()
|> Base.encode64()

encoded_ast = Panacea.Pml.Ast.encode(ast)
clashes = Clashes.run(ast)
drugs = Drugs.run(ast)
unnamed = Unnamed.run(ast)
Expand Down
6 changes: 6 additions & 0 deletions panacea/lib/panacea/pml/ast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ defmodule Panacea.Pml.Ast do
do_unquote(ast, 0)
end

def encode(ast) do
ast
|> :erlang.term_to_binary()
|> Base.encode64()
end

def decode(ast) do
ast
|> decode64()
Expand Down
4 changes: 1 addition & 3 deletions panacea/test/controllers/asclepius_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ defmodule Panacea.AsclepiusControllerTest do
}
"""
{:ok, ast} = Panacea.Pml.Parser.parse(pml)
ast
|> :erlang.term_to_binary()
|> Base.encode64()
Panacea.Pml.Ast.encode(ast)
end

describe "AsclepiusController.uris_for_labels/2" do
Expand Down
6 changes: 1 addition & 5 deletions panacea/test/controllers/ast_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ defmodule Panacea.AstControllerTest do
|> String.replace_trailing("\n", "")

{:ok, ast} = Panacea.Pml.Parser.parse(pml)

encoded_ast =
ast
|> :erlang.term_to_binary()
|> Base.encode64()
encoded_ast = Panacea.Pml.Ast.encode(ast)

conn = get conn, ast_path(conn, :to_pml), %{ast: encoded_ast}

Expand Down
5 changes: 2 additions & 3 deletions panacea/test/controllers/pml_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ defmodule Panacea.PmlControllerTest do
|> File.read!()
|> Panacea.Pml.Parser.parse()

received_ast =
{:ok, received_ast} =
conn
|> response_body()
|> Map.get("ast")
|> Base.decode64!()
|> :erlang.binary_to_term()
|> Panacea.Pml.Ast.decode()

assert received_ast == ast
end
Expand Down

0 comments on commit 663fbd4

Please sign in to comment.