示例#1
0
 public function testParseMultiLineArrayTrailingComma()
 {
     $p = Toml::parse('test = [
             "lorem", "ipsum",
         ]');
     $this->assertEquals(array("lorem", "ipsum"), $p['test']);
 }
示例#2
0
/**
 * 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);
}
示例#3
0
 public function testCommentAtMultilineArray()
 {
     $p = Toml::parse("test = [\n1,\n2 # test\n]");
     $this->assertEquals(array('test' => array(1, 2)), $p);
 }
示例#4
0
<?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') {
示例#5
0
 public function testLiteralString()
 {
     $p = Toml::parse('title = \'C:\\Users\\nodejs\\templates\'');
     $this->assertEquals(array('title' => 'C:\\Users\\nodejs\\templates'), $p);
 }
示例#6
0
 public function testZeroInt()
 {
     $p = Toml::parse('test = 0');
     $this->assertEquals(0, $p['test']);
 }
示例#7
0
#!/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 {
示例#8
0
 public function testEmptyNestedTable()
 {
     $p = Toml::parse("[test.alpha]");
     $this->assertEquals(array('test' => array('alpha' => null)), $p);
 }