Changeset View
Changeset View
Standalone View
Standalone View
src/parser/__tests__/ArcanistBundleTestCase.php
| Show First 20 Lines • Show All 657 Lines • ▼ Show 20 Lines | public function testEncodeBase85() { | ||||
| for ($ii = 0; $ii <= 255; $ii++) { | for ($ii = 0; $ii <= 255; $ii++) { | ||||
| $data .= chr($ii); | $data .= chr($ii); | ||||
| } | } | ||||
| for ($ii = 255; $ii >= 0; $ii--) { | for ($ii = 255; $ii >= 0; $ii--) { | ||||
| $data .= chr($ii); | $data .= chr($ii); | ||||
| } | } | ||||
| $expect = Filesystem::readFile(dirname(__FILE__).'/base85/expect1.txt'); | $expect = Filesystem::readFile(dirname(__FILE__).'/base85/expect1.txt'); | ||||
| $expect = trim($expect); | $this->assertBase85($expect, $data, pht('Byte Sequences')); | ||||
| $this->assertEqual( | |||||
| $expect, | |||||
| ArcanistBundle::encodeBase85($data)); | |||||
| // This is just a large block of random binary data, it has no special | // This is just a large block of random binary data, it has no special | ||||
| // significance. | // significance. | ||||
| $data = | $data = | ||||
| "\x56\x4c\xb3\x63\xe5\x4a\x9f\x03\xa3\x4c\xdd\x5d\x85\x86\x10". | "\x56\x4c\xb3\x63\xe5\x4a\x9f\x03\xa3\x4c\xdd\x5d\x85\x86\x10". | ||||
| "\x30\x3f\xc1\x28\x51\xd8\xb2\x1a\xc3\x79\x15\x85\x31\x66\xf9". | "\x30\x3f\xc1\x28\x51\xd8\xb2\x1a\xc3\x79\x15\x85\x31\x66\xf9". | ||||
| "\x8e\xe1\x20\x8f\x12\xa1\x94\x0e\xbf\xb6\x9c\xb5\xc0\x15\x43". | "\x8e\xe1\x20\x8f\x12\xa1\x94\x0e\xbf\xb6\x9c\xb5\xc0\x15\x43". | ||||
| ▲ Show 20 Lines • Show All 264 Lines • ▼ Show 20 Lines | $data = | ||||
| "\x2e\x19\xac\x06\xb9\x4e\x56\x8e\x74\xef\x2a\x04\xd8\x75\x04". | "\x2e\x19\xac\x06\xb9\x4e\x56\x8e\x74\xef\x2a\x04\xd8\x75\x04". | ||||
| "\x38\x2a\xc7\xa0\xa4\x89\xf3\xa4\x8a\xd4\x2c\x2c\x58\x6f\x00". | "\x38\x2a\xc7\xa0\xa4\x89\xf3\xa4\x8a\xd4\x2c\x2c\x58\x6f\x00". | ||||
| "\x03\x23\xb8\xaf\x02\x48\x7d\x50\x46\x6f\x5a\x08\x41\xe3\x56". | "\x03\x23\xb8\xaf\x02\x48\x7d\x50\x46\x6f\x5a\x08\x41\xe3\x56". | ||||
| "\x6d\xcb\xe2\x4f\xea\x8e\xab\x74\xcd\xf9\xef\xcf\xf9\x1e\xf1". | "\x6d\xcb\xe2\x4f\xea\x8e\xab\x74\xcd\xf9\xef\xcf\xf9\x1e\xf1". | ||||
| "\xf8\xb9\x6c\xaa\x3b\x37\xd1\x21\x42\x67\xec\xd6\x44\x55\x33". | "\xf8\xb9\x6c\xaa\x3b\x37\xd1\x21\x42\x67\xec\xd6\x44\x55\x33". | ||||
| "\xe8\x1d\xa4\x18\xf3\x73\x82\xb4\x50\x59\xc2\x34\x36\x05\xeb"; | "\xe8\x1d\xa4\x18\xf3\x73\x82\xb4\x50\x59\xc2\x34\x36\x05\xeb"; | ||||
| $expect = Filesystem::readFile(dirname(__FILE__).'/base85/expect2.txt'); | $expect = Filesystem::readFile(dirname(__FILE__).'/base85/expect2.txt'); | ||||
| $expect = trim($expect); | |||||
| $this->assertBase85($expect, $data, pht('Random Data')); | |||||
| } | |||||
| private function assertBase85($expect, $data, $label) { | |||||
| $modes = array( | |||||
| '32bit', | |||||
| ); | |||||
| // If this is a 64-bit machine, we can also test 64-bit mode. | |||||
| $has_64bit = (PHP_INT_SIZE >= 8); | |||||
amckinley: My kingdom for an #IFDEF! I googled for a second, and I'm shocked to learn that this is… | |||||
Not Done Inline ActionsWe could do something like define('IS_64_BIT', PHP_INT_SIZE >= 8); but I'm hesitant to start using define() for anything. Or we could do something like phutil_is_64bit(), but I think we only do this in ~4 places (two here, two around newsfeed?) and it seems unlikely to break. epriestley: We could do something like `define('IS_64_BIT', PHP_INT_SIZE >= 8);` but I'm hesitant to start… | |||||
| if ($has_64bit) { | |||||
| $modes[] = '64bit'; | |||||
| } | |||||
| foreach ($modes as $mode) { | |||||
| $this->assertEqual( | $this->assertEqual( | ||||
| $expect, | $expect, | ||||
| ArcanistBundle::encodeBase85($data)); | ArcanistBundle::newBase85Data($data, "\n", $mode), | ||||
| pht('base85/%s: %s', $mode, $label)); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
My kingdom for an #IFDEF! I googled for a second, and I'm shocked to learn that this is apparently the standard way to detect a 64-bit OS ¯\_(ツ)_/¯