Skip to content

Commit

Permalink
Add testDecodeWithSpecial
Browse files Browse the repository at this point in the history
  • Loading branch information
danny50610 committed Aug 20, 2023
1 parent 06bdc70 commit 0ba62de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<coverage/>
<testsuites>
Expand Down
2 changes: 1 addition & 1 deletion src/Encoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function decode(array $tokens): string
{
$result = '';
foreach ($tokens as $token) {
$out = $this->decodeMergeableRanks[$token];
$out = $this->decodeMergeableRanks[$token] ?? null;
if (is_null($out)) {
$out = $this->decodeSpecialTokens[$token];
}
Expand Down
8 changes: 8 additions & 0 deletions tests/EncodingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,13 @@ public static function specialDataProvider()
];
}

public function testDecodeWithSpecial()
{
$enc = EncodingFactory::createByEncodingName('cl100k_base');
$text = $enc->decode([9906, 4435, 100257, 9906, 294, 13184, 13]);

$this->assertSame('Hello World<|endoftext|>Hello danny.', $text);
}

// TODO: test: encodeOrdinary === encode($text, disallowedSpecial: [])
}

0 comments on commit 0ba62de

Please sign in to comment.