88/// Tests covering accessors for singular bool, int32, int64, and bytes fields
99/// on proto3.
1010use googletest:: prelude:: * ;
11- use matchers:: { is_set, is_unset} ;
1211use protobuf:: Optional ;
1312use unittest_proto3:: { TestAllTypes , TestAllTypes_ } ;
1413use unittest_proto3_optional:: { TestProto3Optional , TestProto3Optional_ } ;
@@ -17,38 +16,27 @@ use unittest_proto3_optional::{TestProto3Optional, TestProto3Optional_};
1716fn test_fixed32_accessors ( ) {
1817 let mut msg = TestAllTypes :: new ( ) ;
1918 assert_that ! ( msg. optional_fixed32( ) , eq( 0 ) ) ;
20- assert_that ! ( msg. optional_fixed32_mut( ) . get( ) , eq( 0 ) ) ;
2119
2220 msg. set_optional_fixed32 ( 42 ) ;
23- assert_that ! ( msg. optional_fixed32_mut( ) . get( ) , eq( 42 ) ) ;
2421 assert_that ! ( msg. optional_fixed32( ) , eq( 42 ) ) ;
2522
2623 msg. set_optional_fixed32 ( u32:: default ( ) ) ;
2724 assert_that ! ( msg. optional_fixed32( ) , eq( 0 ) ) ;
28- assert_that ! ( msg. optional_fixed32_mut( ) . get( ) , eq( 0 ) ) ;
2925
30- msg. optional_fixed32_mut ( ) . set ( 43 ) ;
26+ msg. set_optional_fixed32 ( 43 ) ;
3127 assert_that ! ( msg. optional_fixed32( ) , eq( 43 ) ) ;
32- assert_that ! ( msg. optional_fixed32_mut( ) . get( ) , eq( 43 ) ) ;
3328}
3429
3530#[ test]
3631fn test_bool_accessors ( ) {
3732 let mut msg = TestAllTypes :: new ( ) ;
3833 assert_that ! ( msg. optional_bool( ) , eq( false ) ) ;
39- assert_that ! ( msg. optional_bool_mut( ) . get( ) , eq( false ) ) ;
4034
4135 msg. set_optional_bool ( true ) ;
4236 assert_that ! ( msg. optional_bool( ) , eq( true ) ) ;
43- assert_that ! ( msg. optional_bool_mut( ) . get( ) , eq( true ) ) ;
4437
4538 msg. set_optional_bool ( bool:: default ( ) ) ;
4639 assert_that ! ( msg. optional_bool( ) , eq( false ) ) ;
47- assert_that ! ( msg. optional_bool_mut( ) . get( ) , eq( false ) ) ;
48-
49- msg. optional_bool_mut ( ) . set ( true ) ;
50- assert_that ! ( msg. optional_bool( ) , eq( true ) ) ;
51- assert_that ! ( msg. optional_bool_mut( ) . get( ) , eq( true ) ) ;
5240}
5341
5442#[ test]
@@ -57,72 +45,40 @@ fn test_bytes_accessors() {
5745 // Note: even though it's named 'optional_bytes', the field is actually not
5846 // proto3 optional, so it does not support presence.
5947 assert_that ! ( * msg. optional_bytes( ) , empty( ) ) ;
60- assert_that ! ( * msg. optional_bytes_mut( ) . get( ) , empty( ) ) ;
6148
6249 msg. set_optional_bytes ( b"accessors_test" ) ;
6350 assert_that ! ( msg. optional_bytes( ) , eq( b"accessors_test" ) ) ;
64- assert_that ! ( msg. optional_bytes_mut( ) . get( ) , eq( b"accessors_test" ) ) ;
6551
6652 {
6753 let s = Vec :: from ( & b"hello world" [ ..] ) ;
6854 msg. set_optional_bytes ( & s[ ..] ) ;
6955 }
7056 assert_that ! ( msg. optional_bytes( ) , eq( b"hello world" ) ) ;
71- assert_that ! ( msg. optional_bytes_mut( ) . get( ) , eq( b"hello world" ) ) ;
72-
73- msg. optional_bytes_mut ( ) . clear ( ) ;
74- assert_that ! ( * msg. optional_bytes( ) , empty( ) ) ;
75- assert_that ! ( * msg. optional_bytes_mut( ) . get( ) , empty( ) ) ;
7657
7758 msg. set_optional_bytes ( b"" ) ;
7859 assert_that ! ( * msg. optional_bytes( ) , empty( ) ) ;
79- assert_that ! ( * msg. optional_bytes_mut( ) . get( ) , empty( ) ) ;
8060}
8161
8262#[ test]
8363fn test_optional_bytes_accessors ( ) {
8464 let mut msg = TestProto3Optional :: new ( ) ;
8565 assert_that ! ( * msg. optional_bytes( ) , empty( ) ) ;
8666 assert_that ! ( msg. optional_bytes_opt( ) , eq( Optional :: Unset ( & b"" [ ..] ) ) ) ;
87- assert_that ! ( * msg. optional_bytes_mut( ) . get( ) , empty( ) ) ;
88- assert_that ! ( msg. optional_bytes_mut( ) , is_unset( ) ) ;
8967
9068 {
9169 let s = Vec :: from ( & b"hello world" [ ..] ) ;
9270 msg. set_optional_bytes ( & s[ ..] ) ;
9371 }
9472 assert_that ! ( msg. optional_bytes( ) , eq( b"hello world" ) ) ;
9573 assert_that ! ( msg. optional_bytes_opt( ) , eq( Optional :: Set ( & b"hello world" [ ..] ) ) ) ;
96- assert_that ! ( msg. optional_bytes_mut( ) , is_set( ) ) ;
97- assert_that ! ( msg. optional_bytes_mut( ) . get( ) , eq( b"hello world" ) ) ;
98-
99- msg. optional_bytes_mut ( ) . or_default ( ) . set ( b"accessors_test" ) ;
100- assert_that ! ( msg. optional_bytes( ) , eq( b"accessors_test" ) ) ;
101- assert_that ! ( msg. optional_bytes_opt( ) , eq( Optional :: Set ( & b"accessors_test" [ ..] ) ) ) ;
102- assert_that ! ( msg. optional_bytes_mut( ) , is_set( ) ) ;
103- assert_that ! ( msg. optional_bytes_mut( ) . get( ) , eq( b"accessors_test" ) ) ;
104- assert_that ! ( msg. optional_bytes_mut( ) . or_default( ) . get( ) , eq( b"accessors_test" ) ) ;
105-
106- msg. optional_bytes_mut ( ) . clear ( ) ;
107- assert_that ! ( * msg. optional_bytes( ) , empty( ) ) ;
108- assert_that ! ( msg. optional_bytes_opt( ) , eq( Optional :: Unset ( & b"" [ ..] ) ) ) ;
109- assert_that ! ( msg. optional_bytes_mut( ) , is_unset( ) ) ;
11074
11175 msg. set_optional_bytes ( b"" ) ;
11276 assert_that ! ( * msg. optional_bytes( ) , empty( ) ) ;
11377 assert_that ! ( msg. optional_bytes_opt( ) , eq( Optional :: Set ( & b"" [ ..] ) ) ) ;
11478
115- msg. optional_bytes_mut ( ) . clear ( ) ;
116- msg. optional_bytes_mut ( ) . or_default ( ) ;
117- assert_that ! ( * msg. optional_bytes( ) , empty( ) ) ;
118- assert_that ! ( msg. optional_bytes_opt( ) , eq( Optional :: Set ( & b"" [ ..] ) ) ) ;
119-
120- msg. optional_bytes_mut ( ) . or_default ( ) . set ( b"\xff binary\x85 non-utf8" ) ;
79+ msg. set_optional_bytes ( b"\xff binary\x85 non-utf8" ) ;
12180 assert_that ! ( msg. optional_bytes( ) , eq( b"\xff binary\x85 non-utf8" ) ) ;
12281 assert_that ! ( msg. optional_bytes_opt( ) , eq( Optional :: Set ( & b"\xff binary\x85 non-utf8" [ ..] ) ) ) ;
123- assert_that ! ( msg. optional_bytes_mut( ) , is_set( ) ) ;
124- assert_that ! ( msg. optional_bytes_mut( ) . get( ) , eq( b"\xff binary\x85 non-utf8" ) ) ;
125- assert_that ! ( msg. optional_bytes_mut( ) . or_default( ) . get( ) , eq( b"\xff binary\x85 non-utf8" ) ) ;
12682}
12783
12884#[ test]
@@ -131,65 +87,40 @@ fn test_string_accessors() {
13187 // Note: even though it's named 'optional_string', the field is actually not
13288 // proto3 optional, so it does not support presence.
13389 assert_that ! ( * msg. optional_string( ) . as_bytes( ) , empty( ) ) ;
134- assert_that ! ( * msg. optional_string_mut( ) . get( ) . as_bytes( ) , empty( ) ) ;
13590
13691 msg. set_optional_string ( "accessors_test" ) ;
13792 assert_that ! ( msg. optional_string( ) , eq( "accessors_test" ) ) ;
138- assert_that ! ( msg. optional_string_mut( ) . get( ) , eq( "accessors_test" ) ) ;
13993
14094 {
14195 let s = String :: from ( "hello world" ) ;
14296 msg. set_optional_string ( & s[ ..] ) ;
14397 }
14498 assert_that ! ( msg. optional_string( ) , eq( "hello world" ) ) ;
145- assert_that ! ( msg. optional_string_mut( ) . get( ) , eq( "hello world" ) ) ;
146-
147- msg. optional_string_mut ( ) . clear ( ) ;
148- assert_that ! ( * msg. optional_string( ) . as_bytes( ) , empty( ) ) ;
149- assert_that ! ( * msg. optional_string_mut( ) . get( ) . as_bytes( ) , empty( ) ) ;
15099
151100 msg. set_optional_string ( "" ) ;
152101 assert_that ! ( * msg. optional_string( ) . as_bytes( ) , empty( ) ) ;
153- assert_that ! ( * msg. optional_string_mut( ) . get( ) . as_bytes( ) , empty( ) ) ;
154102}
155103
156104#[ test]
157105fn test_optional_string_accessors ( ) {
158106 let mut msg = TestProto3Optional :: new ( ) ;
159107 assert_that ! ( * msg. optional_string( ) . as_bytes( ) , empty( ) ) ;
160108 assert_that ! ( msg. optional_string_opt( ) , eq( Optional :: Unset ( "" . into( ) ) ) ) ;
161- assert_that ! ( * msg. optional_string_mut( ) . get( ) . as_bytes( ) , empty( ) ) ;
162- assert_that ! ( msg. optional_string_mut( ) , is_unset( ) ) ;
163109
164110 {
165111 let s = String :: from ( "hello world" ) ;
166112 msg. set_optional_string ( & s[ ..] ) ;
167113 }
168114 assert_that ! ( msg. optional_string( ) , eq( "hello world" ) ) ;
169115 assert_that ! ( msg. optional_string_opt( ) , eq( Optional :: Set ( "hello world" . into( ) ) ) ) ;
170- assert_that ! ( msg. optional_string_mut( ) , is_set( ) ) ;
171- assert_that ! ( msg. optional_string_mut( ) . get( ) , eq( "hello world" ) ) ;
172116
173- msg. optional_string_mut ( ) . or_default ( ) . set ( "accessors_test" ) ;
117+ msg. set_optional_string ( "accessors_test" ) ;
174118 assert_that ! ( msg. optional_string( ) , eq( "accessors_test" ) ) ;
175119 assert_that ! ( msg. optional_string_opt( ) , eq( Optional :: Set ( "accessors_test" . into( ) ) ) ) ;
176- assert_that ! ( msg. optional_string_mut( ) , is_set( ) ) ;
177- assert_that ! ( msg. optional_string_mut( ) . get( ) , eq( "accessors_test" ) ) ;
178- assert_that ! ( msg. optional_string_mut( ) . or_default( ) . get( ) , eq( "accessors_test" ) ) ;
179-
180- msg. optional_string_mut ( ) . clear ( ) ;
181- assert_that ! ( * msg. optional_string( ) . as_bytes( ) , empty( ) ) ;
182- assert_that ! ( msg. optional_string_opt( ) , eq( Optional :: Unset ( "" . into( ) ) ) ) ;
183- assert_that ! ( msg. optional_string_mut( ) , is_unset( ) ) ;
184120
185121 msg. set_optional_string ( "" ) ;
186122 assert_that ! ( * msg. optional_string( ) . as_bytes( ) , empty( ) ) ;
187123 assert_that ! ( msg. optional_string_opt( ) , eq( Optional :: Set ( "" . into( ) ) ) ) ;
188-
189- msg. optional_string_mut ( ) . clear ( ) ;
190- msg. optional_string_mut ( ) . or_default ( ) ;
191- assert_that ! ( * msg. optional_string( ) . as_bytes( ) , empty( ) ) ;
192- assert_that ! ( msg. optional_string_opt( ) , eq( Optional :: Set ( "" . into( ) ) ) ) ;
193124}
194125
195126#[ test]
@@ -198,15 +129,12 @@ fn test_nested_enum_accessors() {
198129
199130 let mut msg = TestAllTypes :: new ( ) ;
200131 assert_that ! ( msg. optional_nested_enum( ) , eq( NestedEnum :: Zero ) ) ;
201- assert_that ! ( msg. optional_nested_enum_mut( ) . get( ) , eq( NestedEnum :: Zero ) ) ;
202132
203133 msg. set_optional_nested_enum ( NestedEnum :: Baz ) ;
204- assert_that ! ( msg. optional_nested_enum_mut( ) . get( ) , eq( NestedEnum :: Baz ) ) ;
205134 assert_that ! ( msg. optional_nested_enum( ) , eq( NestedEnum :: Baz ) ) ;
206135
207136 msg. set_optional_nested_enum ( NestedEnum :: default ( ) ) ;
208137 assert_that ! ( msg. optional_nested_enum( ) , eq( NestedEnum :: Zero ) ) ;
209- assert_that ! ( msg. optional_nested_enum_mut( ) . get( ) , eq( NestedEnum :: Zero ) ) ;
210138}
211139
212140#[ test]
@@ -216,29 +144,14 @@ fn test_optional_nested_enum_accessors() {
216144 let mut msg = TestProto3Optional :: new ( ) ;
217145 assert_that ! ( msg. optional_nested_enum( ) , eq( NestedEnum :: Unspecified ) ) ;
218146 assert_that ! ( msg. optional_nested_enum_opt( ) , eq( Optional :: Unset ( NestedEnum :: Unspecified ) ) ) ;
219- assert_that ! ( msg. optional_nested_enum_mut( ) . get( ) , eq( NestedEnum :: Unspecified ) ) ;
220147
221148 msg. set_optional_nested_enum ( NestedEnum :: Baz ) ;
222- assert_that ! ( msg. optional_nested_enum_mut( ) . get( ) , eq( NestedEnum :: Baz ) ) ;
223149 assert_that ! ( msg. optional_nested_enum_opt( ) , eq( Optional :: Set ( NestedEnum :: Baz ) ) ) ;
224150 assert_that ! ( msg. optional_nested_enum( ) , eq( NestedEnum :: Baz ) ) ;
225151
226152 msg. set_optional_nested_enum ( NestedEnum :: default ( ) ) ;
227153 assert_that ! ( msg. optional_nested_enum( ) , eq( NestedEnum :: Unspecified ) ) ;
228154 assert_that ! ( msg. optional_nested_enum_opt( ) , eq( Optional :: Set ( NestedEnum :: Unspecified ) ) ) ;
229- assert_that ! ( msg. optional_nested_enum_mut( ) . get( ) , eq( NestedEnum :: Unspecified ) ) ;
230-
231- msg. optional_nested_enum_mut ( ) . clear ( ) ;
232- assert_that ! ( msg. optional_nested_enum( ) , eq( NestedEnum :: Unspecified ) ) ;
233- assert_that ! ( msg. optional_nested_enum_opt( ) , eq( Optional :: Unset ( NestedEnum :: Unspecified ) ) ) ;
234- assert_that ! ( msg. optional_nested_enum_mut( ) . get( ) , eq( NestedEnum :: Unspecified ) ) ;
235-
236- let mut field_mut = msg. optional_nested_enum_mut ( ) . or_default ( ) ;
237- assert_that ! ( field_mut. get( ) , eq( NestedEnum :: Unspecified ) ) ;
238- field_mut. set ( NestedEnum :: Bar ) ;
239- assert_that ! ( msg. optional_nested_enum( ) , eq( NestedEnum :: Bar ) ) ;
240- assert_that ! ( msg. optional_nested_enum_opt( ) , eq( Optional :: Set ( NestedEnum :: Bar ) ) ) ;
241- assert_that ! ( msg. optional_nested_enum_mut( ) . get( ) , eq( NestedEnum :: Bar ) ) ;
242155}
243156
244157#[ test]
@@ -247,15 +160,12 @@ fn test_foreign_enum_accessors() {
247160
248161 let mut msg = TestAllTypes :: new ( ) ;
249162 assert_that ! ( msg. optional_foreign_enum( ) , eq( ForeignEnum :: ForeignZero ) ) ;
250- assert_that ! ( msg. optional_foreign_enum_mut( ) . get( ) , eq( ForeignEnum :: ForeignZero ) ) ;
251163
252164 msg. set_optional_foreign_enum ( ForeignEnum :: ForeignBaz ) ;
253- assert_that ! ( msg. optional_foreign_enum_mut( ) . get( ) , eq( ForeignEnum :: ForeignBaz ) ) ;
254165 assert_that ! ( msg. optional_foreign_enum( ) , eq( ForeignEnum :: ForeignBaz ) ) ;
255166
256167 msg. set_optional_foreign_enum ( ForeignEnum :: default ( ) ) ;
257168 assert_that ! ( msg. optional_foreign_enum( ) , eq( ForeignEnum :: ForeignZero ) ) ;
258- assert_that ! ( msg. optional_foreign_enum_mut( ) . get( ) , eq( ForeignEnum :: ForeignZero ) ) ;
259169}
260170
261171#[ test]
@@ -283,7 +193,7 @@ fn test_oneof_accessors() {
283193 assert_that ! ( msg. oneof_uint32_opt( ) , eq( Optional :: Unset ( 0 ) ) ) ;
284194 assert_that ! ( msg. oneof_field( ) , matches_pattern!( OneofBytes ( eq( b"123" ) ) ) ) ;
285195
286- msg. oneof_bytes_mut ( ) . clear ( ) ;
196+ msg. clear_oneof_bytes ( ) ;
287197 assert_that ! ( msg. oneof_field( ) , matches_pattern!( not_set( _) ) ) ;
288198}
289199
0 commit comments