Skip to content

Commit

Permalink
fix #27: error when package name is nor present
Browse files Browse the repository at this point in the history
  • Loading branch information
tony612 committed Feb 23, 2018
1 parent 14f1e05 commit ef9b6ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/protobuf/protoc/generator/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Protobuf.Protoc.Generator.Util do
end

def attach_pkg(name, ""), do: name
def attach_pkg(name, nil), do: name
def attach_pkg(name, pkg), do: normalize_pkg_name(pkg) <> "." <> name

def options_to_str(opts) do
Expand Down
17 changes: 17 additions & 0 deletions test/protobuf/protoc/generator/util_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule Protobuf.Protoc.Generator.UtilTest do
use ExUnit.Case, async: true

import Protobuf.Protoc.Generator.Util

test "attach_pkg can handle nil package" do
assert attach_pkg("name", nil) == "name"
end

test "attach_pkg can handle empty package" do
assert attach_pkg("name", "") == "name"
end

test "attach_pkg normolizes package name" do
assert attach_pkg("Name", "foo.bar") == "Foo.Bar.Name"
end
end

0 comments on commit ef9b6ef

Please sign in to comment.