Skip to content

Commit

Permalink
Bugfix. solved overtrue#39
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Apr 5, 2016
1 parent 9350810 commit a89aa81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/Pinyin/Pinyin.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ class Pinyin
*/
private function __construct()
{
if (empty(static::$dictionary)) {
$list = json_decode(file_get_contents(dirname(__DIR__).'/data/dict.php'), true);
static::appends($list);
}
$list = json_decode(file_get_contents(dirname(__DIR__).'/data/dict.php'), true);
static::appends($list);
}

/**
Expand Down Expand Up @@ -202,6 +200,7 @@ public static function parse($string, array $settings = array())
public static function appends(array $appends)
{
$list = static::formatWords($appends);

foreach ($list as $key => $value) {
$firstChar = mb_substr($key, 0, 1, static::$internalCharset);
self::$dictionary[$firstChar][$key] = $value;
Expand Down
13 changes: 12 additions & 1 deletion tests/FeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public function testAppends()
'' => 're4',
);
Pinyin::appends($appends);
$this->assertEquals('', Pinyin::trans(''));
Pinyin::set('accent',false);
$this->assertEquals('re', Pinyin::trans(''));
$this->assertEquals('yin yue', Pinyin::trans('音乐'));
Pinyin::set('accent',true);
}

// test temporary changes delimiter
Expand Down Expand Up @@ -230,4 +233,12 @@ public function testOnlyChinese()
$this->assertEquals('d z x w q l', Pinyin::letter("带着希望去了china", array('only_chinese' => true)));
$this->assertEquals('d z x w q l', Pinyin::letter("带着le5希望56去了china", array('only_chinese' => true)));
}

/**
* 混合内容
*/
public function testFixedTest()
{
$this->assertEquals('java gong cheng shi', Pinyin::trans("java工程师", ['accent' => false]));
}
}

0 comments on commit a89aa81

Please sign in to comment.