|
1 | | -using System; |
2 | | - |
3 | 1 | using NUnit.Framework; |
4 | | - |
| 2 | +using System; |
5 | 3 | using TextMateSharp.Grammars; |
6 | 4 |
|
7 | 5 | namespace TextMateSharp.Tests.Grammar |
@@ -351,15 +349,6 @@ public void GetHashCode_SameContent_ShouldReturnSameHash() |
351 | 349 | Assert.AreEqual(lineText1.GetHashCode(), lineText2.GetHashCode()); |
352 | 350 | } |
353 | 351 |
|
354 | | - [Test] |
355 | | - public void GetHashCode_DifferentContent_ShouldReturnDifferentHash() |
356 | | - { |
357 | | - LineText lineText1 = "hello"; |
358 | | - LineText lineText2 = "world"; |
359 | | - |
360 | | - Assert.AreNotEqual(lineText1.GetHashCode(), lineText2.GetHashCode()); |
361 | | - } |
362 | | - |
363 | 352 | [Test] |
364 | 353 | public void GetHashCode_EmptyLineText_ShouldReturnZero() |
365 | 354 | { |
@@ -390,10 +379,12 @@ public void GetHashCode_SameInstance_ShouldBeConsistent() |
390 | 379 | } |
391 | 380 |
|
392 | 381 | [Test] |
393 | | - public void GetHashCode_DifferentArraysSameContent_ShouldReturnSameHash() |
| 382 | + public void GetHashCode_DifferentStringInstances_SameContent_ShouldReturnSameHash() |
394 | 383 | { |
| 384 | + // avoid declaring these as const and use this pattern to dodge string interning |
| 385 | + // which would make them reference the same object and not test the content-based hash code properly |
395 | 386 | string buffer1 = "hello"; |
396 | | - string buffer2 = "hello"; |
| 387 | + string buffer2 = new string("hello".ToCharArray()); |
397 | 388 |
|
398 | 389 | LineText lineText1 = buffer1.AsMemory(); |
399 | 390 | LineText lineText2 = buffer2.AsMemory(); |
@@ -423,27 +414,12 @@ public void GetHashCode_UnicodeContent_ShouldWork() |
423 | 414 | } |
424 | 415 |
|
425 | 416 | [Test] |
426 | | - public void GetHashCode_SimilarStrings_ShouldProduceDifferentHashes() |
427 | | - { |
428 | | - // These are similar but should have different hashes |
429 | | - LineText lineText1 = "abc"; |
430 | | - LineText lineText2 = "abd"; |
431 | | - LineText lineText3 = "bbc"; |
432 | | - |
433 | | - Assert.AreNotEqual(lineText1.GetHashCode(), lineText2.GetHashCode()); |
434 | | - Assert.AreNotEqual(lineText1.GetHashCode(), lineText3.GetHashCode()); |
435 | | - Assert.AreNotEqual(lineText2.GetHashCode(), lineText3.GetHashCode()); |
436 | | - } |
437 | | - |
438 | | - [Test] |
439 | | - public void GetHashCode_SingleCharacter_ShouldWork() |
| 417 | + public void GetHashCode_SingleCharacter_WithSameContent_ShouldWork() |
440 | 418 | { |
441 | 419 | LineText lineText1 = "a"; |
442 | 420 | LineText lineText2 = "a"; |
443 | | - LineText lineText3 = "b"; |
444 | 421 |
|
445 | 422 | Assert.AreEqual(lineText1.GetHashCode(), lineText2.GetHashCode()); |
446 | | - Assert.AreNotEqual(lineText1.GetHashCode(), lineText3.GetHashCode()); |
447 | 423 | } |
448 | 424 |
|
449 | 425 | #endregion |
|
0 commit comments