-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataEncodeDecodeProvider.php
More file actions
36 lines (31 loc) · 1.19 KB
/
Copy pathDataEncodeDecodeProvider.php
File metadata and controls
36 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace Podoko\Bencode\Tests;
use function random_bytes;
class DataEncodeDecodeProvider
{
public static function data_list(): iterable
{
yield '0' => [0, 'i0e'];
yield '-153985' => [-153985, 'i-153985e'];
yield 'empty string' => ['', '0:'];
yield 'string' => ['string', '6:string'];
yield 'some thing' => ['some thing', '10:some thing'];
yield 'Hindi' => ['नमस्ते', '18:नमस्ते'];
yield 'empty list' => [[], 'le'];
yield 'complex lsit' => [[5, 'caribou', 'how', 'are', 'you', -153], 'li5e7:caribou3:how3:are3:youi-153ee'];
yield 'dictionary' => [['foo' => 'bar'], 'd3:foo3:bare'];
$bytes = random_bytes(1024);
$key = random_bytes(10);
yield 'random bytes' => [
['foo' => ['0' . $key => $bytes, '1foo' => 5]],
'd3:food11:0' . $key . strlen($bytes) . ':' . $bytes . '4:1fooi5eee'
];
}
public static function data_from_files(): iterable
{
foreach (glob(__DIR__ . '/assets/*.json') ?: [] as $source) {
$expected = substr($source, 0, -5) . '.bencode';
yield $source => [$source, $expected];
}
}
}