1
1
// Protocol Buffers - Google's data interchange format
2
// Copyright 2008 Google Inc.
2
// Copyright 2008 Google Inc. All rights reserved.
3
3
// http://code.google.com/p/protobuf/
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
9
// http://www.apache.org/licenses/LICENSE-2.0
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are
9
// * Redistributions of source code must retain the above copyright
10
// notice, this list of conditions and the following disclaimer.
11
// * Redistributions in binary form must reproduce the above
12
// copyright notice, this list of conditions and the following disclaimer
13
// in the documentation and/or other materials provided with the
15
// * Neither the name of Google Inc. nor the names of its
16
// contributors may be used to endorse or promote products derived from
17
// this software without specific prior written permission.
19
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
31
package com.google.protobuf;
250
264
TestUtil.assertAllExtensionsSet(builder.build());
267
public void testParseCompatibility() throws Exception {
268
String original = "repeated_float: inf\n" +
269
"repeated_float: -inf\n" +
270
"repeated_float: nan\n" +
271
"repeated_float: inff\n" +
272
"repeated_float: -inff\n" +
273
"repeated_float: nanf\n" +
274
"repeated_float: 1.0f\n" +
275
"repeated_float: infinityf\n" +
276
"repeated_float: -Infinityf\n" +
277
"repeated_double: infinity\n" +
278
"repeated_double: -infinity\n" +
279
"repeated_double: nan\n";
280
String canonical = "repeated_float: Infinity\n" +
281
"repeated_float: -Infinity\n" +
282
"repeated_float: NaN\n" +
283
"repeated_float: Infinity\n" +
284
"repeated_float: -Infinity\n" +
285
"repeated_float: NaN\n" +
286
"repeated_float: 1.0\n" +
287
"repeated_float: Infinity\n" +
288
"repeated_float: -Infinity\n" +
289
"repeated_double: Infinity\n" +
290
"repeated_double: -Infinity\n" +
291
"repeated_double: NaN\n";
292
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
293
TextFormat.merge(original, builder);
294
assertEquals(canonical, builder.build().toString());
253
297
public void testParseExotic() throws Exception {
254
298
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
255
299
TextFormat.merge(exoticText, builder);
291
335
assertEquals(1, builder.getOptionalGroup().getA());
338
public void testParseComment() throws Exception {
339
TestAllTypes.Builder builder = TestAllTypes.newBuilder();
341
"# this is a comment\n" +
342
"optional_int32: 1 # another comment\n" +
343
"optional_int64: 2\n" +
344
"# EOF comment", builder);
345
assertEquals(1, builder.getOptionalInt32());
346
assertEquals(2, builder.getOptionalInt64());
294
349
private void assertParseError(String error, String text) {
295
350
TestAllTypes.Builder builder = TestAllTypes.newBuilder();