From ef9b6efe2474aad7cee6d9b0e1e82742c36c108a Mon Sep 17 00:00:00 2001 From: Tony Han Date: Fri, 23 Feb 2018 13:03:13 +0800 Subject: [PATCH] fix #27: error when package name is nor present --- lib/protobuf/protoc/generator/util.ex | 1 + test/protobuf/protoc/generator/util_test.exs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test/protobuf/protoc/generator/util_test.exs diff --git a/lib/protobuf/protoc/generator/util.ex b/lib/protobuf/protoc/generator/util.ex index d2a9294d..d42eb9ba 100644 --- a/lib/protobuf/protoc/generator/util.ex +++ b/lib/protobuf/protoc/generator/util.ex @@ -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 diff --git a/test/protobuf/protoc/generator/util_test.exs b/test/protobuf/protoc/generator/util_test.exs new file mode 100644 index 00000000..3e3219c1 --- /dev/null +++ b/test/protobuf/protoc/generator/util_test.exs @@ -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