@@ -46,6 +46,42 @@ func TestGetJavaPackageOption(t *testing.T) {
4646 }
4747}
4848
49+ // TestParseScalaImportNamedLiteral asserts the ability to parse
50+ // a subset of scala import expressions.
51+ func TestParseScalaImportNamedLiteral (t * testing.T ) {
52+ for name , tc := range map [string ]struct {
53+ imp string
54+ want []string
55+ }{
56+ "degenerate" : {
57+ want : []string {"" },
58+ },
59+ "single import" : {
60+ imp : "a.b.c.Foo" ,
61+ want : []string {"a.b.c.Foo" },
62+ },
63+ "multiple import" : {
64+ imp : "a.b.c.{Foo,Bar}" ,
65+ want : []string {"a.b.c.Foo" , "a.b.c.Bar" },
66+ },
67+ "multiple import +ws" : {
68+ imp : "a.b.c.{ Foo , Bar } " ,
69+ want : []string {"a.b.c.Foo" , "a.b.c.Bar" },
70+ },
71+ "alias import" : {
72+ imp : "a.b.c.{ Foo => Fog , Bar => Baz }" ,
73+ want : []string {"a.b.c.Foo" , "a.b.c.Bar" },
74+ },
75+ } {
76+ t .Run (name , func (t * testing.T ) {
77+ got := parseScalaImportNamedLiteral (tc .imp )
78+ if diff := cmp .Diff (tc .want , got ); diff != "" {
79+ t .Errorf ("(-want +got):\n %s" , diff )
80+ }
81+ })
82+ }
83+ }
84+
4985// TestGetScalapbImports shows that an import named in (scalapb.options) works as expected.
5086func TestGetScalapbImports (t * testing.T ) {
5187 for name , tc := range map [string ]struct {
@@ -74,6 +110,18 @@ option (scalapb.options) = {
74110 },
75111 want : []string {"corp.common.utils.WithORM" },
76112 },
113+ "with scalapb import (aliased)" : {
114+ in : map [string ]string {
115+ "foo.proto" : `syntax = "proto3";
116+ import "scalapb/scalapb.proto";
117+
118+ option (scalapb.options) = {
119+ import: "corp.common.utils.{WithORM => WithORMAlias}"
120+ };` ,
121+ },
122+ want : []string {"corp.common.utils.WithORM" },
123+ },
124+
77125 "with field type" : {
78126 in : map [string ]string {
79127 "foo.proto" : `
0 commit comments