FOSSology  4.4.0
Open Source License Compliance by Open Source Software
StringOperationTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 
9 namespace Fossology\Lib\Util;
10 
11 class StringOperationTest extends \PHPUnit\Framework\TestCase
12 {
13 
14  protected function setUp() : void
15  {
16  $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
17  }
18 
19  protected function tearDown() : void
20  {
21  $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount()-$this->assertCountBefore);
22  }
23 
24  public function testGetCommonHead()
25  {
26  assertThat(StringOperation::getCommonHead('abc','abc'), equalTo('abc'));
27  assertThat(StringOperation::getCommonHead('abcd','abc'), equalTo('abc'));
28  assertThat(StringOperation::getCommonHead('abc','abcd'), equalTo('abc'));
29  assertThat(StringOperation::getCommonHead('abcd','abce'), equalTo('abc'));
30  assertThat(StringOperation::getCommonHead('abcdf','abcef'), equalTo('abc'));
31  assertThat(StringOperation::getCommonHead('abc',''), equalTo(''));
32  assertThat(StringOperation::getCommonHead('','abc'), equalTo(''));
33  }
34 
43  {
44  assertThat(StringOperation::replaceUnicodeControlChar('␌Y', '?'),
45  equalTo('?Y'));
46  assertThat(StringOperation::replaceUnicodeControlChar('“IND'),
47  equalTo('“IND'));
48  assertThat(StringOperation::replaceUnicodeControlChar('y’©', 'a'),
49  equalTo('y’©'));
51  equalTo('eys'));
52  assertThat(StringOperation::replaceUnicodeControlChar('नमस्ते', '.'),
53  equalTo('नमस्ते'));
54  assertThat(StringOperation::replaceUnicodeControlChar('abc', ''),
55  equalTo('abc'));
57  equalTo('ab c'));
58  assertThat(StringOperation::replaceUnicodeControlChar("abc\r\na", ''),
59  equalTo("abc\r\na"));
61  equalTo("ab\tc"));
62  assertThat(StringOperation::replaceUnicodeControlChar('', 'abc'),
63  equalTo(''));
64  }
65 }
static replaceUnicodeControlChar($input, $replace="")