@@ -135,6 +135,21 @@ public void testLocationEquality() throws Exception
135
135
JsonLocation loc2 = new JsonLocation (_sourceRef (src2 ),
136
136
10L , 10L , 1 , 2 );
137
137
assertEquals (loc1 , loc2 );
138
+
139
+ // Also make sure to consider offset/length
140
+ final byte [] bogus = "BOGUS" .getBytes ();
141
+
142
+ // If same, equals:
143
+ assertEquals (new JsonLocation (_sourceRef (bogus , 0 , 5 ), 5L , 0L , 1 , 2 ),
144
+ new JsonLocation (_sourceRef (bogus , 0 , 5 ), 5L , 0L , 1 , 2 ));
145
+
146
+ // If different, not equals
147
+ loc1 = new JsonLocation (_sourceRef (bogus , 0 , 5 ),
148
+ 5L , 0L , 1 , 2 );
149
+ loc2 = new JsonLocation (_sourceRef (bogus , 1 , 4 ),
150
+ 5L , 0L , 1 , 2 );
151
+ assertFalse (loc1 .equals (loc2 ));
152
+ assertFalse (loc2 .equals (loc1 ));
138
153
}
139
154
140
155
private ContentReference _sourceRef (String rawSrc ) {
@@ -149,6 +164,10 @@ private ContentReference _sourceRef(byte[] rawSrc) {
149
164
return ContentReference .construct (true , rawSrc , 0 , rawSrc .length );
150
165
}
151
166
167
+ private ContentReference _sourceRef (byte [] rawSrc , int offset , int length ) {
168
+ return ContentReference .construct (true , rawSrc , offset , length );
169
+ }
170
+
152
171
private ContentReference _sourceRef (InputStream rawSrc ) {
153
172
return ContentReference .construct (true , rawSrc , -1 , -1 );
154
173
}
@@ -160,4 +179,4 @@ private ContentReference _sourceRef(File rawSrc) {
160
179
private ContentReference _rawSourceRef (boolean textual , Object rawSrc ) {
161
180
return ContentReference .rawReference (textual , rawSrc );
162
181
}
163
- }
182
+ }
0 commit comments