MediaWiki REL1_33
MWMessagePackTest.php
Go to the documentation of this file.
1<?php
6class MWMessagePackTest extends PHPUnit\Framework\TestCase {
7
8 use MediaWikiCoversValidator;
9
18 public static function providePacks() {
19 $tests = [
20 [ 'nil', null, 'c0' ],
21 [ 'bool', true, 'c3' ],
22 [ 'bool', false, 'c2' ],
23 [ 'positive fixnum', 0, '00' ],
24 [ 'positive fixnum', 1, '01' ],
25 [ 'positive fixnum', 5, '05' ],
26 [ 'positive fixnum', 35, '23' ],
27 [ 'uint 8', 128, 'cc80' ],
28 [ 'uint 16', 1000, 'cd03e8' ],
29 [ 'uint 32', 100000, 'ce000186a0' ],
30 [ 'negative fixnum', -1, 'ff' ],
31 [ 'negative fixnum', -2, 'fe' ],
32 [ 'int 8', -128, 'd080' ],
33 [ 'int 8', -35, 'd0dd' ],
34 [ 'int 16', -1000, 'd1fc18' ],
35 [ 'int 32', -100000, 'd2fffe7960' ],
36 [ 'double', 0.1, 'cb3fb999999999999a' ],
37 [ 'double', 1.1, 'cb3ff199999999999a' ],
38 [ 'double', 123.456, 'cb405edd2f1a9fbe77' ],
39 [ 'fix raw', '', 'a0' ],
40 [ 'fix raw', 'foobar', 'a6666f6f626172' ],
41 [
42 'raw 16',
43 'Lorem ipsum dolor sit amet amet.',
44 'da00204c6f72656d20697073756d20646f6c6f722073697420616d657420616d65742e'
45 ],
46 [
47 'fix array',
48 [ 'abc', 'def', 'ghi' ],
49 '93a3616263a3646566a3676869'
50 ],
51 [
52 'fix map',
53 [ 'one' => 1, 'two' => 2 ],
54 '82a36f6e6501a374776f02'
55 ],
56 ];
57
58 if ( PHP_INT_SIZE > 4 ) {
59 $tests[] = [ 'uint 64', 10000000000, 'cf00000002540be400' ];
60 $tests[] = [ 'int 64', -10000000000, 'd3fffffffdabf41c00' ];
61 $tests[] = [ 'int 64', -223372036854775807, 'd3fce66c50e2840001' ];
62 $tests[] = [ 'int 64', -9223372036854775807, 'd38000000000000001' ];
63 }
64
65 return $tests;
66 }
67
73 public function testPack( $type, $value, $expected ) {
74 $actual = bin2hex( MWMessagePack::pack( $value ) );
75 $this->assertEquals( $expected, $actual, $type );
76 }
77}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
PHP Unit tests for MWMessagePack MWMessagePack.
testPack( $type, $value, $expected)
Verify that values are serialized correctly.
static providePacks()
Provides test cases for MWMessagePackTest::testMessagePack.
static pack( $value)
Encode a value using MessagePack.