MCPcopy
hub / github.com/libgdx/libgdx / replaceTest

Method replaceTest

gdx/test/com/badlogic/gdx/utils/CharArrayTest.java:476–510  ·  view source on GitHub ↗

Test replace methods

()

Source from the content-addressed store, hash-verified

474
475 /** Test replace methods */
476 @Test
477 public void replaceTest () {
478 CharArray array = new CharArray("Hello World!");
479
480 // Replace first char
481 Assert.assertTrue(array.replaceFirst('l', 'L'));
482 Assert.assertEquals("HeLlo World!", array.toString());
483 Assert.assertFalse(array.replaceFirst('z', 'Z'));
484
485 // Replace all chars
486 array = new CharArray("Hello World!");
487 int count = array.replaceAll('l', 'L');
488 Assert.assertEquals(3, count);
489 Assert.assertEquals("HeLLo WorLd!", array.toString());
490
491 // Replace string range
492 array = new CharArray("Hello World!");
493 array.replace(0, 5, "Hi");
494 Assert.assertEquals("Hi World!", array.toString());
495
496 // Replace all strings
497 array = new CharArray("Hello World! Hello!");
498 array.replaceAll("Hello", "Hi");
499 Assert.assertEquals("Hi World! Hi!", array.toString());
500
501 // Replace first string
502 array = new CharArray("Hello World! Hello!");
503 array.replaceFirst("Hello", "Hi");
504 Assert.assertEquals("Hi World! Hello!", array.toString());
505
506 // Replace char with string
507 array = new CharArray("a-b-c");
508 array.replace('-', " to ");
509 Assert.assertEquals("a to b to c", array.toString());
510 }
511
512 /** Test insert methods */
513 @Test

Callers

nothing calls this directly

Calls 5

replaceFirstMethod · 0.95
toStringMethod · 0.95
replaceAllMethod · 0.95
replaceMethod · 0.95
assertEqualsMethod · 0.45

Tested by

no test coverage detected