Skip to content

Commit

Permalink
v2 test with reamdme
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFoxTail committed Jan 22, 2022
1 parent a941034 commit dadae28
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/vendor/

.phpunit.result.cache
\.idea/
48 changes: 23 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,37 @@ install using composer:

Usage
------------
The return value is the *Hangul Compatibility Jamo* between `U+3130` and `U+318F`
반환 값은 `U+3130``U+318F` 사이의 *Hangul Compatibility Jamo*가 반환 됩니다.
조회시 반환 값은 `U+3130``U+318F` 사이의 *Hangul Compatibility Jamo*가 반환 됩니다.
- See [Hangul Compatibility Jamo](https://unicode.org/charts/PDF/U3130.pdf)

```php
use AcidF0x\KoreanHandler\aaaaaaa;
use AcidF0x\KoreanHandler\Seperator;

$separator = new aaaaaaa();
$separator = new Seperator();

$separator->separate("가");
$separator->getChoseong(); // "ㄱ"
$separator->getJungseong(); // "ㅏ"
$separator->getJongseong(); // null
$separator->getSplit(); // ["ㄱ","ㅏ"]

$separator->separate("셥");
$separator->getChoseong(); // "ㅅ"
$separator->getJungseong(); // "ㅕ"
$separator->getJongseong(); // "ㅂ"
$separator->getSplit(); // ["ㅅ", "ㅕ", "ㅂ"]
$result = $separator->separate("수상하게 돈이 많은");
print_r($result->getSplitList()); // ["ㅅ","ㅜ","ㅅ","ㅏ","ㅇ","ㅎ","ㅏ","ㄱ","ㅔ","ㄷ","ㅗ","ㄴ","ㅇ","ㅣ","ㅁ","ㅏ","ㄶ","ㅇ","ㅡ","ㄴ"]
print_r($result->getChoseongList()); // ["ㅅ", "ㅅ", "ㅎ", "ㄱ", "ㄷ", "ㅇ", "ㅁ", "ㅇ"]
print_r($result->getJungseongList()); // ["ㅜ", "ㅏ", "ㅏ", "ㅔ", "ㅗ", "ㅣ", "ㅏ", "ㅡ"]
print_r($result->getJongseongList()); // ["ㅇ","ㄴ","ㄶ","ㄴ"]
```
And Also, You can use the `strict mode` to get the correct *Hangul Jamo*
The return value is the *Hangul Jamo* between `U+1100` and `U+11FF`
엄격한 모드를 사용하여 `U+1100``U+11FF` 사이의 정확한 한글 자모로 분리 할 수 있습니다.
- See [Hangul Jamo](https://unicode.org/charts/PDF/U1100.pdf)
`separate` 메서드의 리턴 값은 `ArrayAccess`, `Iterator` 인터페이스를 구현하였으므로
각 결과에 대해 `Array`처럼 접근 하여 사용이 가능합니다

```php
use AcidF0x\KoreanHandler\aaaaaaa;
$result = $this->separator->separate("황소");

$result[0]->getChoseong(); // ㅎ
$result[0]->getJungseong(); // ㅘ
$result[0]->getJongseong(); // ㅇ
$result[1]->getChoseong(); // ㅅ
$result[1]->getJungseong(); // ㅗ
$result[1]->getJongseong(); // null

$result[0]->getSplit(); // ["ㅎ", "ㅘ", "ㅇ"]

$separator = new aaaaaaa();
$separator->strictMode();

$separator->separate("가");
$separator->getChoseong(); // "ᄀ" (U+1100)
$separator->getJungseong(); //"ᅡ" (U+1161)
foreach ($result as $character) {
$character->getChoseong();
}
```
2 changes: 1 addition & 1 deletion src/Separator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private function doSeparator(string $char): ?Character
$jungseongBase = ($base / 28) % 21;
$jongseongBase = $base % 28 - 1;

$choseong = Constants::CHOSEONG_LIST[(int) $choseongBase];
$choseong = Constants::CHOSEONG_LIST[$choseongBase];
$jungseong = Constants::JUNGSEONG_LIST[$jungseongBase];
$jongseong = $jongseongBase > 0
? Constants::JONGSEONG_LIST[$jongseongBase]
Expand Down
75 changes: 75 additions & 0 deletions tests/SeparatorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php


use AcidF0x\KoreanHandler\Separator;
use PHPUnit\Framework\TestCase;

class SeparatorTest extends TestCase
{
private Separator $separator;

protected function setUp(): void
{
parent::setUp();
$this->separator = new Separator();
}

/**
* @dataProvider oneCharterProvider
*/
public function testSeparate($char, $expectChoseong, $expectJungseong, $expectJongseong)
{
$result = $this->separator->separate($char);

$this->assertSame($expectChoseong, $result[0]->getChoseong());
$this->assertSame($expectJungseong, $result[0]->getJungseong());
$this->assertSame($expectJongseong, $result[0]->getJongseong());
}

public function testGetLists()
{
$result = $this->separator->separate("안녕하세요");

$this->assertSame(
["","","","",""],
$result->getChoseongList()
);

$this->assertSame(
["","","","",""],
$result->getJungseongList()
);

$this->assertSame(
["", ""],
$result->getJongseongList()
);

$this->assertSame(
["","","","","","","","","","","",""],
$result->getSplitList()
);
}

public function oneCharterProvider(): array
{
return [
["", "", "", null],
["", "", "", null],
["", "", "", null],
["", "", "", null],
["", "", "", null],
["", "", "", null],
["", "", "", null],
["", "", "", ""],
["", "", "", ""],
["", "", "", ""],
["", "", "", ""],
["", "", "", ""],
["", "", "", ""],
["", "", "", ""],
["", "", "", ""],
["", "", "", ""],
];
}
}

0 comments on commit dadae28

Please sign in to comment.