[otrs-cvs] otrs/scripts/test/YAML YAML.t,NONE,1.1 Load.t,NONE,1.1
"CVS commits notifications of OTRS.org" <[email protected]>
| Newsgroups | gmane.comp.otrs.cvs |
|---|---|
| Message-ID | <[email protected]> |
Comments:
Update of /home/cvs/otrs/scripts/test/YAML
In directory lancelot:/tmp/cvs-serv18507/scripts/test/YAML
Added Files:
YAML.t Load.t
Log Message:
Group YAML tests together.
Author: mg
--- NEW FILE: YAML.t ---
# --
# YAML.t - tests for the YAML parser
# Copyright (C) 2001-2013 OTRS AG, http://otrs.org/
# --
# $Id: YAML.t,v 1.1 2013/01/17 09:13:18 mg Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
use strict;
use warnings;
use vars (qw($Self));
use utf8;
use Kernel::System::YAML;
# create needed objects
my $ConfigObject = Kernel::Config->new();
my $YAMLObject = Kernel::System::YAML->new(
%{$Self},
ConfigObject => $ConfigObject,
);
my @Tests = (
{
Name => 'Simple string',
Data => 'Teststring <tag> äß@ø " \\" \' \'\'',
},
{
Name => 'Complex data',
Data => {
Key => 'Teststring <tag> äß@ø " \\" \' \'\'',
Value => [
{
Subkey => 'Value',
Subkey2 => undef,
},
1234,
0,
undef,
'Teststring <tag> äß@ø " \\" \' \'\'',
],
},
},
{
Name => 'Special YAML chars',
Data => ' a " a " a \'\' a \'\' a',
},
{
Name => 'UTF8 string',
Data => 'kéy',
},
{
Name => 'UTF8 string, loader',
Data => 'kéy',
YAMLString => '--- kéy' . "\n",
},
{
Name => 'UTF8 string without UTF8-Flag',
Data => 'k\x{e9}y',
},
{
Name => 'UTF8 string without UTF8-Flag, loader',
Data => 'k\x{e9}y',
YAMLString => '--- k\x{e9}y' . "\n",
},
{
Name => 'Very long string', # see https://bugzilla.redhat.com/show_bug.cgi?id=192400
Data => ' äø<>"\'' x 40_000,
SkipEngine => 'YAML', # This test does not run with plain YAML, see the bug above
},
);
ENGINE:
for my $Engine (qw(YAML::XS YAML)) {
# locally override the internal engine of YAML::Any to force testing
local @YAML::Any::_TEST_ORDER = ($Engine);
TEST:
for my $Test (@Tests) {
next TEST if defined $Test->{SkipEngine} && $Engine eq $Test->{SkipEngine};
my $YAMLString = $Test->{YAMLString} || $YAMLObject->Dump( Data => $Test->{Data} );
my $YAMLData = $YAMLObject->Load( Data => $YAMLString );
$Self->IsDeeply(
$YAMLData,
$Test->{Data},
"Engine $Engine - $Test->{Name}",
);
}
}
1;
Author: mg
--- NEW FILE: Load.t ---
# --
# scripts/test/Load.t - YAML module testscript
# Copyright (C) 2001-2013 OTRS AG, http://otrs.org/
# --
# $Id: Load.t,v 1.1 2013/01/17 09:13:18 mg Exp $
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
use strict;
use warnings;
use utf8;
use Kernel::System::YAML;
# declare externally defined variables to avoid errors under 'use strict'
use vars qw( $Self %Param );
my $YAMLObject = Kernel::System::YAML->new( %{$Self} );
my @Tests = (
{
Input => undef,
Result => undef,
Name => 'YAML - undef test',
},
{
Input => '',
Result => "--- ''\n",
Name => 'YAML - empty test',
},
{
Input => 'Some Text',
Result => "--- Some Text\n",
Name => 'YAML - simple',
},
{
Input => 42,
Result => "--- 42\n",
Name => 'YAML - simple',
},
{
Input => [ 1, 2, "3", "Foo", 5 ],
Result => "---\n- 1\n- 2\n- '3'\n- Foo\n- 5\n",
Name => 'YAML - simple',
},
{
Input => {
Key1 => "Value1",
Key2 => 42,
"Key3" => "Another Value"
},
Result => "---\nKey1: Value1\nKey2: 42\nKey3: Another Value\n",
Name => 'YAML - simple',
},
{
Input => [
[ 1, 2, "Foo", "Bar" ],
{
Key1 => 'Something',
Key2 => [ "Foo", "Bar" ],
Key3 => {
Foo => 'Bar',
},
Key4 => {
Bar => [ "f", "o", "o" ]
}
},
],
Result =>
"---\n"
. "- - 1\n"
. " - 2\n"
. " - Foo\n"
. " - Bar\n"
. "- Key1: Something\n"
. " Key2:\n"
. " - Foo\n"
. " - Bar\n"
. " Key3:\n"
. " Foo: Bar\n"
. " Key4:\n"
. " Bar:\n"
. " - f\n"
. " - o\n"
. " - o\n",
Name => 'YAM - complex structure',
},
);
for my $Test (@Tests) {
my $YAML = $YAMLObject->Dump(
Data => $Test->{Input},
);
$Self->IsDeeply(
$YAML,
$Test->{Result},
$Test->{Name},
);
}
# YAML::Load()
@Tests = (
{
Result => undef,
InputLoad => undef,
Name => 'YAML - undef test',
},
{
Result => undef,
InputLoad => "--- Key: malformed\n - 1\n",
Name => 'YAML - malformed data test',
},
{
Result => 'Some Text',
InputLoad => "--- Some Text\n",
Name => 'YAML - simple'
},
{
Result => 42,
InputLoad => "--- 42\n",
Name => 'YAML - simple'
},
{
Result => [ 1, 2, "3", "Foo", 5 ],
InputLoad => "---\n- 1\n- 2\n- '3'\n- Foo\n- 5\n",
Name => 'YAML - simple'
},
{
Result => {
Key1 => "Value1",
Key2 => 42,
"Key3" => "Another Value"
},
InputLoad => "---\nKey1: Value1\nKey2: 42\nKey3: Another Value\n",
Name => 'YAML - simple'
},
{
Result => [
[ 1, 2, "Foo", "Bar" ],
{
Key1 => 'Something',
Key2 => [ "Foo", "Bar" ],
Key3 => {
Foo => 'Bar',
},
Key4 => {
Bar => [ "f", "o", "o" ]
}
},
],
InputLoad =>
"---\n"
. "- - 1\n"
. " - 2\n"
. " - Foo\n"
. " - Bar\n"
. "- Key1: Something\n"
. " Key2:\n"
. " - Foo\n"
. " - Bar\n"
. " Key3:\n"
. " Foo: Bar\n"
. " Key4:\n"
. " Bar:\n"
. " - f\n"
. " - o\n"
. " - o\n",
Name => 'YAML - complex structure'
},
);
for my $Test (@Tests) {
my $Perl = $YAMLObject->Load(
Data => $Test->{InputLoad},
);
$Self->IsDeeply(
scalar $Perl,
scalar $Test->{Result},
$Test->{Name},
);
}
1;
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log