示例#1
0
function test_all_containers()
{
    $data_arr = array(1, 2, 3);
    test_container(array());
    test_container($data_arr);
    test_container(new \HH\ImmVector(array()));
    test_container(new \HH\ImmVector($data_arr));
    test_container(new \HH\Vector(array()));
    test_container(new \HH\Vector($data_arr));
    test_container(\HH\Pair::hacklib_new(1, 2));
    test_container(new \HH\ImmSet(array()));
    test_container(new \HH\ImmSet($data_arr));
    test_container(new \HH\Set(array()));
    test_container(new \HH\Set($data_arr));
    test_container(\HH\ImmMap::hacklib_new(array(), array()));
    test_container(new \HH\ImmMap($data_arr));
    test_container(\HH\Map::hacklib_new(array(), array()));
    test_container(new \HH\Map($data_arr));
    test_container(new Foo());
}
示例#2
0
    }
    try {
        $p[10];
        echo "should not see this";
    } catch (OutOfBoundsException $e) {
        echo $e->getMessage() . "\n";
    }
    echo var_export($p->get(10), true) . "\n";
    echo \hacklib_cast_as_boolean(isset($p[3])) ? "is set\n" : "not set\n";
    echo \hacklib_cast_as_boolean($p->containsKey(2)) ? "contains Key\n" : "does not contain Key\n";
    echo \hacklib_cast_as_boolean($p->containsKey(20)) ? "contains Key\n" : "does not contain Key\n";
    foreach ($p as $i => $val) {
        $out = var_export($val, true);
        echo "{$i} : {$out}\n";
    }
    $i = $p->getIterator();
    $i->next();
    $i->next();
    $i->next();
    $i->next();
    try {
        $i->current();
        echo "should not see this";
    } catch (InvalidOperationException $e) {
        echo $e->getMessage() . "\n";
    }
}
verify_pair(\HH\Pair::hacklib_new(1, "hello"));
verify_pair(\HH\Pair::hacklib_new(1, "hello"));
verify_pair(\HH\Pair::hacklib_new(1, "hello"));
示例#3
0
 public function current()
 {
     return \HH\Pair::hacklib_new($this->it->key(), $this->it->current());
 }
 private function readJSONString($peek = false, $start = 0)
 {
     if (!\hacklib_cast_as_boolean($peek)) {
         $start = 0;
     }
     $this->expectChar("\"", $peek, $start);
     $count = \hacklib_cast_as_boolean($peek) ? 1 : 0;
     $sb = new StringBuffer();
     $reading = true;
     while (\hacklib_cast_as_boolean($reading)) {
         $c = $this->bufTrans->peek(1, $start + $count);
         switch ($c) {
             case "\"":
                 $reading = false;
                 break;
             case "\\":
                 $count++;
                 $c = $this->bufTrans->peek(1, $start + $count);
                 switch ($c) {
                     case "\\":
                         $count++;
                         $sb->append("\\");
                         break;
                     case "\"":
                         $count++;
                         $sb->append("\"");
                         break;
                     case "b":
                         $count++;
                         $sb->append(chr(0x8));
                         break;
                     case "/":
                         $count++;
                         $sb->append("/");
                         break;
                     case "f":
                         $count++;
                         $sb->append("\f");
                         break;
                     case "n":
                         $count++;
                         $sb->append("\n");
                         break;
                     case "r":
                         $count++;
                         $sb->append("\r");
                         break;
                     case "t":
                         $count++;
                         $sb->append("\t");
                         break;
                     case "u":
                         $count++;
                         $this->expectChar("0", true, $start + $count);
                         $this->expectChar("0", true, $start + $count + 1);
                         $count += 2;
                         $sb->append(hex2bin($this->bufTrans->peek(2, $start + $count)));
                         $count += 2;
                         break;
                     default:
                         throw new TProtocolException("TSimpleJSONProtocol: Expected Control Character, found 0x" . bin2hex($c));
                 }
                 break;
             default:
                 $count++;
                 $sb->append($c);
                 break;
         }
     }
     if (!\hacklib_cast_as_boolean($peek)) {
         $this->trans_->readAll($count);
     }
     $this->expectChar("\"", $peek, $start + $count);
     return \HH\Pair::hacklib_new($sb->detach(), $count + 1);
 }
示例#5
0
文件: maps.php 项目: barnardm/hhvm
    $i->next();
    $i->next();
    $i->next();
    try {
        $i->current();
        echo "should not see this";
    } catch (InvalidOperationException $e) {
        echo $e->getMessage() . "\n";
    }
}
$immMap = \HH\ImmMap::hacklib_new(array("25", 9, "9"), array("Galadriel", true, new Foo()));
$map = \HH\Map::hacklib_new(array("25", 9, "keyai"), array("zinc", 99, array(2 => 2)));
verify_map($immMap);
verify_map($map);
$i = $map->getIterator();
$map[\hacklib_id("25")] = "copper";
echo "key is " . $i->key() . "\n";
$map[\hacklib_id("logo")] = "basic";
try {
    $i->key();
    echo "should not see this";
} catch (InvalidOperationException $e) {
    echo $e->getMessage() . "\n";
}
$map = $map->add(\HH\Pair::hacklib_new("tweedledee", "tweedledum"));
foreach ($map as $i => $mal) {
    $out = var_export($mal, true);
    $t = gettype($i);
    echo "({$t}) {$i} : {$out} -- ";
}
echo "\n";
示例#6
0
{
    echo $name . " : " . (\hacklib_cast_as_boolean($c) ? " TRUE " : " FALSE ") . "\n";
}
$o1 = 10;
$o2 = "10";
print_res("straightforward equality", 10 == "10");
print_res("simple equality", \hacklib_equals($o1, $o2));
print_res("simple inequality", \hacklib_not_equals($o1, $o2));
print_res("vec and immvec", \hacklib_equals(new \HH\Vector(array()), new \HH\ImmVector(array())));
$m1 = \HH\Map::hacklib_new(array("t", 1), array("tt", 2));
$m2 = \HH\Map::hacklib_new(array(1, "t"), array(2, "tt"));
print_res("map key order", \hacklib_equals($m1, $m2));
$p1 = \HH\Pair::hacklib_new(1, 2);
$p2 = \HH\Pair::hacklib_new(1, 2);
$p1->getIterator();
print_res("collections with additional state", \hacklib_equals($p1, $p2));
print_res("Pairs can be unequal", \hacklib_not_equals(\HH\Pair::hacklib_new("high", "tea"), \HH\Pair::hacklib_new("high", "tee")));
print_res("Vector uses ==", \hacklib_equals(new \HH\Vector(array(1)), new \HH\ImmVector(array("1"))));
print_res("Even if Empty", \hacklib_equals(new \HH\Vector(array()), new \HH\ImmVector(array())));
print_res("Number of Items", \hacklib_equals(new \HH\Set(array(1)), new \HH\Set(array(1, 2))));
print_res("Sets use === on keys", \hacklib_equals(new \HH\Set(array(1)), new \HH\Set(array("1"))));
print_res("Sets can equal ImmSets", \hacklib_equals(new \HH\Set(array("a", 1)), new \HH\ImmSet(array(1, "a"))));
print_res("Maps do both", \hacklib_equals(\HH\Map::hacklib_new(array("1", 1), array("zork", "mindy")), \HH\Map::hacklib_new(array(1, "1"), array("mindy", "zork"))));
print_res("Maps can equal ImmMaps", \hacklib_equals(\HH\ImmMap::hacklib_new(array("o", 1), array("mork", 1)), \HH\Map::hacklib_new(array(1, "o"), array(1, "mork"))));
print_res("Check for false", \hacklib_equals(new \HH\Vector(array()), false));
print_res("Check for true", \hacklib_equals(true, new \HH\Vector(array())));
print_res("Using not equals", \hacklib_not_equals(\HH\Map::hacklib_new(array(), array()), true));
print_res("Nested Comparison True", \hacklib_equals(new \HH\Vector(array(\HH\Map::hacklib_new(array(1), array("zoom")), new \HH\Vector(array("33")))), new \HH\Vector(array(\HH\Map::hacklib_new(array(1), array("zoom")), new \HH\ImmVector(array(33))))));
print_res("Nested Comparison False", \hacklib_equals(new \HH\Vector(array(\HH\Map::hacklib_new(array(1), array("zoom")), new \HH\Set(array("33")))), new \HH\Vector(array(\HH\Map::hacklib_new(array(1), array("zoom")), new \HH\Set(array(33))))));
print_res("Compare with null", \hacklib_equals(null, new \HH\Vector(array())));
print_res("Compare values that are null", \hacklib_equals(new \HH\Vector(array(false)), new \HH\Vector(array(null))));