public function testParseMultiLineArrayTrailingComma() { $p = Toml::parse('test = [ "lorem", "ipsum", ]'); $this->assertEquals(array("lorem", "ipsum"), $p['test']); }
/** * Helper function for parsing Toml strings * or files. * * @param string $toml Specifies the Toml * formatted String or * the path to a Toml file * to be parsed. */ function parse($toml) { if (!is_string($toml)) { throw new \InvalidArgumentException('Please specify a Toml formatted String or a file path to a Toml document'); } $path = pathinfo($toml); if (isset($path['extension']) && strtolower($path['extension']) == 'toml') { return Toml::parseFile($toml); } return Toml::parse($toml); }
public function testCommentAtMultilineArray() { $p = Toml::parse("test = [\n1,\n2 # test\n]"); $this->assertEquals(array('test' => array(1, 2)), $p); }
<?php require '../src/Toml.php'; $toml = '[a] [a.b] '; $result = Toml::parse($toml); print_r($result); echo json_encode($result); echo "\n"; // Format response values into test suite object function walk(&$a) { foreach ($a as $i => $v) { if (is_array($v) && array_values($v) !== $v) { walk($a[$i]); } else { // Get type $t = gettype($v); // Parse type name $t = str_replace(array('boolean', 'double'), array('bool', 'float'), $t); // Check date type if (Toml::isISODate($v)) { $t = 'datetime'; } // Fix double vs integer type if ($t == 'float' && $v == intval($v)) { $t = 'integer'; } // Parse array type if ($t == 'array') {
public function testLiteralString() { $p = Toml::parse('title = \'C:\\Users\\nodejs\\templates\''); $this->assertEquals(array('title' => 'C:\\Users\\nodejs\\templates'), $p); }
public function testZeroInt() { $p = Toml::parse('test = 0'); $this->assertEquals(0, $p['test']); }
#!/usr/bin/php <?php require '../src/Toml.php'; try { $result = Toml::parse(file_get_contents("php://stdin")); } catch (Exception $e) { exit(1); } // Format response values into test suite object function walk(&$a) { foreach ($a as $i => $v) { if (is_array($v) && array_values($v) !== $v) { walk($a[$i]); } else { // Get type $t = gettype($v); // Parse type name $t = str_replace(array('boolean', 'double'), array('bool', 'float'), $t); // Check date type if (Toml::isISODate($v)) { $t = 'datetime'; } // Fix double vs integer type if ($t == 'float' && $v == intval($v)) { $t = 'integer'; } // Parse array type if ($t == 'array') { walk($v); } else {
public function testEmptyNestedTable() { $p = Toml::parse("[test.alpha]"); $this->assertEquals(array('test' => array('alpha' => null)), $p); }