Esempio n. 1
0
 public function testDump()
 {
     $testsForDump = $this->getTestsForDump();
     foreach ($testsForDump as $yaml => $value) {
         $this->assertEquals(Inline::dump($value), $yaml, sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
     }
     foreach ($this->getTestsForLoad() as $yaml => $value) {
         if ($value == 1230) {
             continue;
         }
         $this->assertEquals(Inline::load(Inline::dump($value)), $value, 'check consistency');
     }
     foreach ($testsForDump as $yaml => $value) {
         if ($value == 1230) {
             continue;
         }
         $this->assertEquals(Inline::load(Inline::dump($value)), $value, 'check consistency');
     }
 }
Esempio n. 2
0
 * file that was distributed with this source code.
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\Yaml\Yaml;
use Symfony\Components\Yaml\Inline;
Yaml::setSpecVersion('1.1');
$t = new LimeTest(124);
// ::load()
$t->diag('::load()');
$testsForLoad = array('' => '', 'null' => null, 'false' => false, 'true' => true, '12' => 12, '"quoted string"' => 'quoted string', "'quoted string'" => 'quoted string', '12.30e+02' => 1230.0, '0x4D2' => 0x4d2, '02333' => 02333, '.Inf' => -log(0), '-.Inf' => log(0), '123456789123456789' => '123456789123456789', '"foo\\r\\nbar"' => "foo\r\nbar", "'foo#bar'" => 'foo#bar', "'foo # bar'" => 'foo # bar', "'#cfcfcf'" => '#cfcfcf', '2007-10-30' => mktime(0, 0, 0, 10, 30, 2007), '2007-10-30T02:59:43Z' => gmmktime(2, 59, 43, 10, 30, 2007), '2007-10-30 02:59:43 Z' => gmmktime(2, 59, 43, 10, 30, 2007), '"a \\"string\\" with \'quoted strings inside\'"' => 'a "string" with \'quoted strings inside\'', "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', '[foo, http://urls.are/no/mappings, false, null, 12]' => array('foo', 'http://urls.are/no/mappings', false, null, 12), '[  foo  ,   bar , false  ,  null     ,  12  ]' => array('foo', 'bar', false, null, 12), '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), '{foo:bar,bar:foo,false:false,null:null,integer:12}' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{ foo  : bar, bar : foo,  false  :   false,  null  :   null,  integer :  12  }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{foo: \'bar\', bar: \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), '{\'foo\': \'bar\', "bar": \'foo: bar\'}' => array('foo' => 'bar', 'bar' => 'foo: bar'), '{\'foo\'\'\': \'bar\', "bar\\"": \'foo: bar\'}' => array('foo\'' => 'bar', "bar\"" => 'foo: bar'), '{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}' => array('foo: ' => 'bar', "bar: " => 'foo: bar'), '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), '[foo, {bar: foo}]' => array('foo', array('bar' => 'foo')), '{ foo: {bar: foo} }' => array('foo' => array('bar' => 'foo')), '{ foo: [bar, foo] }' => array('foo' => array('bar', 'foo')), '[  foo, [  bar, foo  ]  ]' => array('foo', array('bar', 'foo')), '[{ foo: {bar: foo} }]' => array(array('foo' => array('bar' => 'foo'))), '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), '[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))), '[foo, bar: { foo: bar }]' => array('foo', '1' => array('bar' => array('foo' => 'bar'))));
foreach ($testsForLoad as $yaml => $value) {
    $t->is(Inline::load($yaml), $value, sprintf('::load() converts an inline YAML to a PHP structure (%s)', $yaml));
}
$testsForDump = array('null' => null, 'false' => false, 'true' => true, '12' => 12, "'quoted string'" => 'quoted string', '12.30e+02' => 1230.0, '1234' => 0x4d2, '1243' => 02333, '.Inf' => -log(0), '-.Inf' => log(0), '"foo\\r\\nbar"' => "foo\r\nbar", "'foo#bar'" => 'foo#bar', "'foo # bar'" => 'foo # bar', "'#cfcfcf'" => '#cfcfcf', "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', '[foo, bar, false, null, 12]' => array('foo', 'bar', false, null, 12), '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), '{ foo: bar, bar: foo, \'false\': false, \'null\': null, integer: 12 }' => array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), '{ foo: bar, bar: \'foo: bar\' }' => array('foo' => 'bar', 'bar' => 'foo: bar'), '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), '{ foo: { bar: foo } }' => array('foo' => array('bar' => 'foo')), '[foo, { bar: foo }]' => array('foo', array('bar' => 'foo')), '[foo, { bar: foo, foo: [foo, { bar: foo }] }, [foo, { bar: foo }]]' => array('foo', array('bar' => 'foo', 'foo' => array('foo', array('bar' => 'foo'))), array('foo', array('bar' => 'foo'))));
// ::dump()
$t->diag('::dump()');
foreach ($testsForDump as $yaml => $value) {
    $t->is(Inline::dump($value), $yaml, sprintf('::dump() converts a PHP structure to an inline YAML (%s)', $yaml));
}
foreach ($testsForLoad as $yaml => $value) {
    if ($value == 1230) {
        continue;
    }
    $t->is(Inline::load(Inline::dump($value)), $value, 'check consistency');
}
foreach ($testsForDump as $yaml => $value) {
    if ($value == 1230) {
        continue;
    }
    $t->is(Inline::load(Inline::dump($value)), $value, 'check consistency');
}
Esempio n. 3
0
 /**
  * @see Base
  */
 public function asString($indent = 0)
 {
     $options = $this->getOptionsWithoutDefaults();
     $messages = $this->getMessagesWithoutDefaults();
     unset($options['left_field'], $options['operator'], $options['right_field']);
     $arguments = '';
     if ($options || $messages) {
         $arguments = sprintf('(%s%s)', $options ? YamlInline::dump($options) : ($messages ? '{}' : ''), $messages ? ', ' . YamlInline::dump($messages) : '');
     }
     return sprintf('%s%s %s%s %s', str_repeat(' ', $indent), $this->getOption('left_field'), $this->getOption('operator'), $arguments, $this->getOption('right_field'));
 }
Esempio n. 4
0
 /**
  * Parses validator arguments.
  *
  * @param  string  $string  The string to parse
  * @param  integer $i       The indice to start the parsing
  *
  * @return array   An array of parameters
  */
 protected function parseArguments($string, &$i)
 {
     $len = strlen($string);
     if ($i + 1 > $len || '(' != $string[$i]) {
         return array(array(), array());
     }
     ++$i;
     $args = '';
     $opened = 0;
     while ($i < $len) {
         if ('(' == $string[$i]) {
             ++$opened;
         } else {
             if (')' == $string[$i]) {
                 if (!$opened) {
                     break;
                 }
                 --$opened;
             }
         }
         $args .= $string[$i++];
     }
     ++$i;
     $args = \Symfony\Components\Yaml\Inline::load('[' . (!$args ? '{}' : $args) . ']');
     return $args;
 }
Esempio n. 5
0
 /**
  * Returns a string representation of this validator.
  *
  * @param  int $indent  Indentation (number of spaces before each line)
  *
  * @return string The string representation of the validator
  */
 public function asString($indent = 0)
 {
     $options = $this->getOptionsWithoutDefaults();
     $messages = $this->getMessagesWithoutDefaults();
     return sprintf('%s%s(%s%s)', str_repeat(' ', $indent), str_replace('', '', get_class($this)), $options ? YamlInline::dump($options) : ($messages ? '{}' : ''), $messages ? ', ' . YamlInline::dump($messages) : '');
 }
Esempio n. 6
0
 /**
  * @see Base
  */
 public function asString($indent = 0)
 {
     $validators = '';
     for ($i = 0, $max = count($this->validators); $i < $max; $i++) {
         $validators .= "\n" . $this->validators[$i]->asString($indent + 2) . "\n";
         if ($i < $max - 1) {
             $validators .= str_repeat(' ', $indent + 2) . 'and';
         }
         if ($i == $max - 2) {
             $options = $this->getOptionsWithoutDefaults();
             $messages = $this->getMessagesWithoutDefaults();
             if ($options || $messages) {
                 $validators .= sprintf('(%s%s)', $options ? YamlInline::dump($options) : ($messages ? '{}' : ''), $messages ? ', ' . YamlInline::dump($messages) : '');
             }
         }
     }
     return sprintf("%s(%s%s)", str_repeat(' ', $indent), $validators, str_repeat(' ', $indent));
 }