1a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// Protocol Buffers - Google's data interchange format
2a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// Copyright 2008 Google Inc.  All rights reserved.
3afb4b72037e3f13db208590fc782c4bc8e27f862Jeff Davidson// https://developers.google.com/protocol-buffers/
4a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson//
5a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// Redistribution and use in source and binary forms, with or without
6a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// modification, are permitted provided that the following conditions are
7a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// met:
8a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson//
9a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson//     * Redistributions of source code must retain the above copyright
10a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// notice, this list of conditions and the following disclaimer.
11a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson//     * Redistributions in binary form must reproduce the above
12a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// copyright notice, this list of conditions and the following disclaimer
13a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// in the documentation and/or other materials provided with the
14a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// distribution.
15a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson//     * Neither the name of Google Inc. nor the names of its
16a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// contributors may be used to endorse or promote products derived from
17a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// this software without specific prior written permission.
18a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson//
19a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
31a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsonpackage com.google.protobuf;
32a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
33a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidsonimport junit.framework.TestCase;
34a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson
35a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson/**
36b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer * Test @{link TextFormatParseLocation}.
37a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson */
38b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammerpublic class TextFormatParseLocationTest extends TestCase {
39b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer
40b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  public void testCreateEmpty() {
41b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    TextFormatParseLocation location = TextFormatParseLocation.create(-1, -1);
42b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    assertEquals(TextFormatParseLocation.EMPTY, location);
43b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  }
44b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer
45b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  public void testCreate() {
46b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    TextFormatParseLocation location = TextFormatParseLocation.create(2, 1);
47b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    assertEquals(2, location.getLine());
48b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    assertEquals(1, location.getColumn());
49b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  }
50b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer
51b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  public void testCreateThrowsIllegalArgumentExceptionForInvalidIndex() {
52b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    try {
53b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer      TextFormatParseLocation.create(-1, 0);
54b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer      fail("Should throw IllegalArgumentException if line is less than 0");
55b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    } catch (IllegalArgumentException unused) {
56b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer      // pass
57a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson    }
58b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    try {
59b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer      TextFormatParseLocation.create(0, -1);
60b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer      fail("Should throw, column < 0");
61b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    } catch (IllegalArgumentException unused) {
62b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer      // pass
63a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson    }
64a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson  }
65b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer
66b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  public void testHashCode() {
67b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    TextFormatParseLocation loc0 = TextFormatParseLocation.create(2, 1);
68b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    TextFormatParseLocation loc1 = TextFormatParseLocation.create(2, 1);
69b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer
70b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    assertEquals(loc0.hashCode(), loc1.hashCode());
71b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    assertEquals(
72b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer        TextFormatParseLocation.EMPTY.hashCode(), TextFormatParseLocation.EMPTY.hashCode());
73b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  }
74b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer
75b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer  public void testEquals() {
76b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    TextFormatParseLocation loc0 = TextFormatParseLocation.create(2, 1);
77b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    TextFormatParseLocation loc1 = TextFormatParseLocation.create(1, 2);
78b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    TextFormatParseLocation loc2 = TextFormatParseLocation.create(2, 2);
79b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    TextFormatParseLocation loc3 = TextFormatParseLocation.create(2, 1);
80b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer
81b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    assertEquals(loc0, loc3);
82b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    assertNotSame(loc0, loc1);
83b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    assertNotSame(loc0, loc2);
84b0575e93e4c39dec69365b850088a1eb7f82c5b3Tamas Berghammer    assertNotSame(loc1, loc2);
85a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson  }
86a3b2a6da25a76f17c73d31def3952feb0fd2296eJeff Davidson}
87