THRIFT-3434 Dart generator produces empty name in pubspec.yaml for includes w/o namespace
Client: Dart
Patch: Mark Erickson <mark.erickson@workiva.com>

This closes #706
diff --git a/compiler/cpp/src/generate/t_dart_generator.cc b/compiler/cpp/src/generate/t_dart_generator.cc
index f064161..f48559b 100644
--- a/compiler/cpp/src/generate/t_dart_generator.cc
+++ b/compiler/cpp/src/generate/t_dart_generator.cc
@@ -221,6 +221,7 @@
    * Helper rendering functions
    */
 
+  std::string find_library_name(t_program* program);
   std::string dart_library(string file_name);
   std::string service_imports();
   std::string dart_thrift_imports();
@@ -261,12 +262,8 @@
   MKDIR(get_out_dir().c_str());
 
   if (library_name_.empty()) {
-    library_name_ = program_->get_namespace("dart");
+    library_name_ = find_library_name(program_);
   }
-  if (library_name_.empty()) {
-    library_name_ = program_->get_name();
-  }
-  library_name_ = replace_all(library_name_, ".", "_");
 
   string subdir = get_out_dir() + "/" + library_name_;
   MKDIR(subdir.c_str());
@@ -280,6 +277,16 @@
   src_dir_ = subdir;
 }
 
+string t_dart_generator::find_library_name(t_program* program) {
+  string name = program->get_namespace("dart");
+  if (name.empty()) {
+    name = program->get_name();
+  }
+  name = replace_all(name, ".", "_");
+  name = replace_all(name, "-", "_");
+  return name;
+}
+
 /**
  * The Dart library
  *
@@ -318,7 +325,7 @@
   // add imports for included thrift files
   const vector<t_program*>& includes = program_->get_includes();
   for (size_t i = 0; i < includes.size(); ++i) {
-    string include_name = includes[i]->get_namespace("dart");
+    string include_name = find_library_name(includes[i]);
     imports += "import 'package:" + include_name + "/" + include_name + ".dart';" + endl;
   }
 
@@ -375,7 +382,7 @@
   // add included thrift files as dependencies
   const vector<t_program*>& includes = program_->get_includes();
   for (size_t i = 0; i < includes.size(); ++i) {
-    string include_name = includes[i]->get_namespace("dart");
+    string include_name = find_library_name(includes[i]);
     indent(f_pubspec) << include_name << ":" << endl;
     indent_up();
     indent(f_pubspec) << "path: ../" << include_name << endl;