17
17
import static com .google .common .truth .Truth .assertThat ;
18
18
import static junit .framework .Assert .assertEquals ;
19
19
20
+ import com .google .api .generator .gapic .model .SourceCodeInfoLocation ;
20
21
import com .google .protobuf .DescriptorProtos .FileDescriptorProto ;
21
22
import com .google .protobuf .DescriptorProtos .FileDescriptorSet ;
22
- import com .google .protobuf .DescriptorProtos .SourceCodeInfo .Location ;
23
23
import com .google .protobuf .Descriptors .Descriptor ;
24
24
import com .google .protobuf .Descriptors .EnumDescriptor ;
25
25
import com .google .protobuf .Descriptors .FileDescriptor ;
@@ -46,48 +46,47 @@ public void setUp() throws Exception {
46
46
47
47
@ Test
48
48
public void getServiceInfo () {
49
- Location location = parser .getLocation (protoFile .findServiceByName ("FooService" ));
49
+ SourceCodeInfoLocation location = parser .getLocation (protoFile .findServiceByName ("FooService" ));
50
50
assertEquals (
51
- " This is a service description.\n It takes up multiple lines, like so.\n " ,
51
+ "This is a service description. It takes up multiple lines, like so." ,
52
52
location .getLeadingComments ());
53
53
54
54
location = parser .getLocation (protoFile .findServiceByName ("BarService" ));
55
- assertEquals (" This is another service description.\n " , location .getLeadingComments ());
55
+ assertEquals ("This is another service description." , location .getLeadingComments ());
56
56
}
57
57
58
58
@ Test
59
59
public void getMethodInfo () {
60
60
ServiceDescriptor service = protoFile .findServiceByName ("FooService" );
61
- Location location = parser .getLocation (service .findMethodByName ("FooMethod" ));
61
+ SourceCodeInfoLocation location = parser .getLocation (service .findMethodByName ("FooMethod" ));
62
62
assertEquals (
63
- " FooMethod does something.\n This comment also takes up multiple lines.\n " ,
63
+ "FooMethod does something. This comment also takes up multiple lines." ,
64
64
location .getLeadingComments ());
65
65
66
66
service = protoFile .findServiceByName ("BarService" );
67
67
location = parser .getLocation (service .findMethodByName ("BarMethod" ));
68
- assertEquals (" BarMethod does another thing.\n " , location .getLeadingComments ());
68
+ assertEquals ("BarMethod does another thing." , location .getLeadingComments ());
69
69
}
70
70
71
71
@ Test
72
72
public void getOuterMessageInfo () {
73
73
Descriptor message = protoFile .findMessageTypeByName ("FooMessage" );
74
- Location location = parser .getLocation (message );
74
+ SourceCodeInfoLocation location = parser .getLocation (message );
75
75
assertEquals (
76
- " This is a message descxription.\n "
77
- + " Lorum ipsum dolor sit amet consectetur adipiscing elit.\n " ,
76
+ "This is a message descxription. Lorum ipsum dolor sit amet consectetur adipiscing elit." ,
78
77
location .getLeadingComments ());
79
78
80
79
// Fields.
81
80
location = parser .getLocation (message .findFieldByName ("field_one" ));
82
81
assertEquals (
83
- " This is a field description for field_one.\n "
84
- + " And here is the second line of that description.\n " ,
82
+ "This is a field description for field_one. And here is the second line of that "
83
+ + " description." ,
85
84
location .getLeadingComments ());
86
- assertEquals (" A field trailing comment.\n " , location .getTrailingComments ());
85
+ assertEquals ("A field trailing comment." , location .getTrailingComments ());
87
86
88
87
location = parser .getLocation (message .findFieldByName ("field_two" ));
89
- assertEquals (" This is another field description.\n " , location .getLeadingComments ());
90
- assertEquals (" Another field trailing comment.\n " , location .getTrailingComments ());
88
+ assertEquals ("This is another field description." , location .getLeadingComments ());
89
+ assertEquals ("Another field trailing comment." , location .getTrailingComments ());
91
90
}
92
91
93
92
@ Test
@@ -96,52 +95,52 @@ public void getInnerMessageInfo() {
96
95
assertThat (message ).isNotNull ();
97
96
message = message .findNestedTypeByName ("BarMessage" );
98
97
99
- Location location = parser .getLocation (message );
98
+ SourceCodeInfoLocation location = parser .getLocation (message );
100
99
assertEquals (
101
- " This is an inner message description for BarMessage.\n " , location .getLeadingComments ());
100
+ "This is an inner message description for BarMessage." , location .getLeadingComments ());
102
101
103
102
// Fields.
104
103
location = parser .getLocation (message .findFieldByName ("field_three" ));
105
- assertEquals (" A third leading comment for field_three.\n " , location .getLeadingComments ());
104
+ assertEquals ("A third leading comment for field_three." , location .getLeadingComments ());
106
105
107
106
location = parser .getLocation (message .findFieldByName ("field_two" ));
108
- assertEquals ("\n This is a block comment for field_two.\n " , location .getLeadingComments ());
107
+ assertEquals ("This is a block comment for field_two." , location .getLeadingComments ());
109
108
}
110
109
111
110
@ Test
112
111
public void getOuterEnumInfo () {
113
112
EnumDescriptor protoEnum = protoFile .findEnumTypeByName ("OuterEnum" );
114
- Location location = parser .getLocation (protoEnum );
115
- assertEquals (" This is an outer enum.\n " , location .getLeadingComments ());
113
+ SourceCodeInfoLocation location = parser .getLocation (protoEnum );
114
+ assertEquals ("This is an outer enum." , location .getLeadingComments ());
116
115
117
116
// Enum fields.
118
117
location = parser .getLocation (protoEnum .findValueByName ("VALUE_UNSPECIFIED" ));
119
- assertEquals (" Another unspecified value.\n " , location .getLeadingComments ());
118
+ assertEquals ("Another unspecified value." , location .getLeadingComments ());
120
119
}
121
120
122
121
@ Test
123
122
public void getInnerEnumInfo () {
124
123
Descriptor message = protoFile .findMessageTypeByName ("FooMessage" );
125
124
EnumDescriptor protoEnum = message .findEnumTypeByName ("FoodEnum" );
126
- Location location = parser .getLocation (protoEnum );
127
- assertEquals (" An inner enum.\n " , location .getLeadingComments ());
125
+ SourceCodeInfoLocation location = parser .getLocation (protoEnum );
126
+ assertEquals ("An inner enum." , location .getLeadingComments ());
128
127
129
128
// Enum fields.
130
129
location = parser .getLocation (protoEnum .findValueByName ("RICE" ));
131
- assertEquals (" 😋 🍚.\n " , location .getLeadingComments ());
130
+ assertEquals ("😋 🍚." , location .getLeadingComments ());
132
131
location = parser .getLocation (protoEnum .findValueByName ("CHOCOLATE" ));
133
- assertEquals (" 🤤 🍫.\n " , location .getLeadingComments ());
132
+ assertEquals ("🤤 🍫." , location .getLeadingComments ());
134
133
}
135
134
136
135
@ Test
137
136
public void getOnoeofInfo () {
138
137
Descriptor message = protoFile .findMessageTypeByName ("FooMessage" );
139
138
OneofDescriptor protoOneof = message .getOneofs ().get (0 );
140
- Location location = parser .getLocation (protoOneof );
141
- assertEquals (" An inner oneof.\n " , location .getLeadingComments ());
139
+ SourceCodeInfoLocation location = parser .getLocation (protoOneof );
140
+ assertEquals ("An inner oneof." , location .getLeadingComments ());
142
141
143
142
location = parser .getLocation (protoOneof .getField (0 ));
144
- assertEquals (" An InnerOneof comment for its field.\n " , location .getLeadingComments ());
143
+ assertEquals ("An InnerOneof comment for its field." , location .getLeadingComments ());
145
144
}
146
145
147
146
/**
0 commit comments