2010-05-02 19:15:08 -04:00
# -*- mode: ruby; ruby-indent-level: 4; tab-width: 4; indent-tabs-mode: t -*-
2003-10-03 15:51:25 -04:00
# vim:sw=4:ts=4
# $Id$
#
* gc.c (Init_stack): stack region is far smaller than usual if
pthread is used.
* marshal.c (w_extended): singleton methods should not be checked
when dumping via marshal_dump() or _dump(). [ruby-talk:85909]
* file.c (getcwdofdrv): avoid using getcwd() directly, use
my_getcwd() instead.
* merged NeXT, OpenStep, Rhapsody ports patch from Eric Sunshine
<sunshine@sunshineco.com>. [ruby-core:01596]
* marshal.c (w_object): LINK check earlier than anything else,
i.e. do not dump TYPE_IVAR for already dumped objects.
(ruby-bugs PR#1220)
* eval.c (rb_eval): call "inherited" only when a new class is
generated; not on reopening.
* eval.c (eval): prepend error position in evaluating string to
* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
had become unbuildable; enhanced --enable-fat-binary option so that
it accepts a list of desired architectures (rather than assuming a
fixed list), or defaults to a platform-appropriate list if user does
not provide an explicit list; made the default list of architectures
for MAB (fat binary) more comprehensive; now uses -fno-common even
when building the interpreter (in addition to using it for
extensions), thus allowing the interpreter to be embedded into a
plugin module of an external project (in addition to allowing
embedding directly into an application); added checks for
<netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
ensures that -I/usr/local/include is employed when extensions'
extconf.rb scripts invoke have_header() since extension checks on
NextStep and OpenStep will fail without it if the desired resource
resides in the /usr/local tree; fixed formatting of --help message.
* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
(see configure's --enable-fat-binary option); added rule for new
missing/getcwd.c.
* defines.h: fixed endian handling during MAB build (see configure's
--enable-fat-binary option) to ensure that all portions of the
project see the correct WORDS_BIGENDIAN value (some extension modules
were getting the wrong endian setting); added missing constants
GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
define in NeXT section.
* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
NextStep since, on some installations, this value always resolves
uselessly to zero.
* dln.c: added error reporting to NextStep extension loader since the
previous behavior of failing silently was not useful; now ensures
that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
on Rhapsody since this header lacks multiple-include protection,
which resulted in "redefinition" compilation errors.
* main.c: also create hard reference to objc_msgSend() on NeXT
platforms (in addition to Apple platforms).
* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
makefiles so that extensions can be built MAB (see configure's
--enable-fat-binary option); also utilize XCFLAGS in cc_command()
(but not cpp_command() because MAB flags are incompatible with
direct invocation of `cpp').
* ext/curses/extconf.rb: now additionally checks for presence of these
curses functions which are not present on NextStep or Openstep:
bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
wscrl(), wsetscrreg()
* ext/curses/curses.c: added appropriate #ifdef's for additional set of
curses functions now checked by extconf.rb; fixed curses_bkgd() and
window_bkgd() to correctly return boolean result rather than numeric
result; fixed window_getbkgd() to correctly signal an error by
returning nil rather than -1.
* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
pointers before invoking rb_tainted_str_new2() upon fields extracted
from `struct passwd' and `struct group' since null pointers in some
fields are common on NextStep/OpenStep (especially so for the
`pw_comment' field) and rb_tainted_str_new2() throws an exception
when it receives a null pointer.
* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
gethostbyaddr(), and gethostbyname() from (const char*) to non-const
(char*) for older platforms such as NextStep and OpenStep.
* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup(); include
<netinet/in_systm.h> if present for NextStep and OpenStep; cast first
argument of gethostbyaddr() and getservbyname() from (const char*) to
non-const (char*) for older platforms.
* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
platforms such as NextStep and OpenStep which lack strdup().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-21 23:00:03 -05:00
require 'test/unit'
2011-09-07 04:28:42 -04:00
require 'syck'
2003-10-03 15:51:25 -04:00
require 'yaml'
2010-04-03 17:50:47 -04:00
require 'syck/ypath'
2003-10-03 15:51:25 -04:00
2003-12-12 13:08:58 -05:00
# [ruby-core:01946]
module YAML_Tests
StructTest = Struct :: new ( :c )
end
2010-04-10 20:37:42 -04:00
module Syck
2003-10-03 15:51:25 -04:00
class YAML_Unit_Tests < Test :: Unit :: TestCase
2010-04-10 21:45:15 -04:00
def setup
@current_engine = YAML :: ENGINE . yamler
YAML :: ENGINE . yamler = 'syck'
end
def teardown
YAML :: ENGINE . yamler = @current_engine
end
2011-02-02 17:05:15 -05:00
# [ruby-core:34969]
def test_regexp_with_n
assert_cycle ( Regexp . new ( '' , 0 , 'n' ) )
end
2003-10-03 15:51:25 -04:00
#
# Convert between YAML and the object to verify correct parsing and
# emitting
#
2010-05-02 19:15:08 -04:00
def assert_to_yaml ( obj , yaml , msg = nil )
assert_equal ( obj , YAML :: load ( yaml ) , msg )
assert_equal ( obj , YAML :: parse ( yaml ) . transform , msg )
assert_equal ( obj , YAML :: load ( obj . to_yaml ) , msg )
assert_equal ( obj , YAML :: parse ( obj . to_yaml ) . transform , msg )
2003-10-03 15:51:25 -04:00
assert_equal ( obj , YAML :: load (
2009-03-05 22:56:38 -05:00
obj . to_yaml ( :UseVersion = > true , :UseHeader = > true , :SortKeys = > true )
2010-05-02 19:15:08 -04:00
) , msg )
2003-10-03 15:51:25 -04:00
end
#
# Test parser only
#
2010-05-02 19:15:08 -04:00
def assert_parse_only ( obj , yaml , msg = nil )
assert_equal ( obj , YAML :: load ( yaml ) , msg )
assert_equal ( obj , YAML :: parse ( yaml ) . transform , msg )
2003-10-03 15:51:25 -04:00
end
2010-05-02 19:15:08 -04:00
def assert_cycle ( obj , msg = nil )
assert_equal ( obj , YAML :: load ( obj . to_yaml ) , msg )
2004-05-15 00:38:39 -04:00
end
2010-05-02 19:15:08 -04:00
def assert_path_segments ( path , segments , msg = nil )
2003-10-03 15:51:25 -04:00
YAML :: YPath . each_path ( path ) { | choice |
2010-05-02 19:15:08 -04:00
assert_equal ( choice . segments , segments . shift , msg )
2003-10-03 15:51:25 -04:00
}
assert_equal ( segments . length , 0 , " Some segments leftover: #{ segments . inspect } " )
end
#
# Make a time with the time zone
#
def mktime ( year , mon , day , hour , min , sec , usec , zone = " Z " )
2009-04-21 10:56:59 -04:00
usec = Rational ( usec . to_s ) * 1000000
2003-10-03 15:51:25 -04:00
val = Time :: utc ( year . to_i , mon . to_i , day . to_i , hour . to_i , min . to_i , sec . to_i , usec )
if zone != " Z "
hour = zone [ 0 , 3 ] . to_i * 3600
min = zone [ 3 , 2 ] . to_i * 60
ofs = ( hour + min )
* configure.in: check struct timespec, clock_gettime, utimensat,
struct stat.st_atim,
struct stat.st_atimespec,
struct stat.st_atimensec,
struct stat.st_mtim,
struct stat.st_mtimespec,
struct stat.st_mtimensec,
struct stat.st_ctim,
struct stat.st_ctimespec,
struct stat.st_ctimensec.
* include/ruby/missing.h: provide struct timespec if not available.
* time.c: support nanosecond-resolution using struct timespec.
* include/ruby/intern.h: provide rb_time_nano_new.
* file.c (utime_internal): use utimensat if available.
(rb_file_s_utime): refactored.
(rb_f_test): use stat_atime, stat_mtime, stat_ctime.
(rb_stat_cmp): check tv_nsec.
(stat_atimespec): new function.
(stat_atime): ditto.
(stat_mtimespec): ditto.
(stat_mtime): ditto.
(stat_ctimespec): ditto.
(stat_ctime): ditto.
(rb_stat_atime): use stat_atime.
(rb_file_s_atime): ditto.
(rb_file_atime): ditto.
(rb_stat_mtime): use stat_mtime.
(rb_file_s_mtime): ditto.
(rb_file_mtime): ditto.
(rb_file_ctime): use stat_ctime.
(rb_file_s_ctime): ditto.
(rb_stat_ctime): ditto.
* variable.c (rb_copy_generic_ivar): clear clone's instance variables
if obj has no instance variable.
* marshal.c (w_object): dump instance variables of generated string
for TYPE_USERDEF, even if original object has instance variables.
* lib/time.rb (Time#xmlschema): use nsec instead of usec.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-11-19 04:09:38 -05:00
val = Time . at ( val . tv_sec - ofs , val . tv_nsec / 1000 . 0 )
2003-10-03 15:51:25 -04:00
end
return val
end
#
# Tests modified from 00basic.t in YAML.pm
#
def test_basic_map
# Simple map
assert_parse_only (
{ 'one' = > 'foo' , 'three' = > 'baz' , 'two' = > 'bar' } , <<EOY
one : foo
two : bar
three : baz
EOY
)
end
def test_basic_strings
# Common string types
2004-05-15 00:38:39 -04:00
assert_cycle ( " x " )
assert_cycle ( " :x " )
assert_cycle ( " : " )
2003-10-03 15:51:25 -04:00
assert_parse_only (
{ 1 = > 'simple string' , 2 = > 42 , 3 = > '1 Single Quoted String' ,
4 = > 'YAML\'s Double "Quoted" String' , 5 = > " A block \n with several \n lines. \n " ,
2004-05-15 00:38:39 -04:00
6 = > " A \" chomped \" block " , 7 = > " A folded \n string \n " , 8 = > " : started string " } ,
<<EOY
2003-10-03 15:51:25 -04:00
1 : simple string
2 : 42
3 : '1 Single Quoted String'
4 : " YAML's Double \\ \" Quoted \\ \" String "
5 : |
A block
with several
lines .
6 : | -
A " chomped " block
7 : >
A
folded
string
2004-05-15 00:38:39 -04:00
8 : " : started string "
2003-10-03 15:51:25 -04:00
EOY
)
end
#
# Test the specification examples
# - Many examples have been changes because of whitespace problems that
# caused the two to be inequivalent, or keys to be sorted wrong
#
def test_spec_simple_implicit_sequence
# Simple implicit sequence
assert_to_yaml (
[ 'Mark McGwire' , 'Sammy Sosa' , 'Ken Griffey' ] , <<EOY
- Mark McGwire
- Sammy Sosa
- Ken Griffey
EOY
)
end
def test_spec_simple_implicit_map
# Simple implicit map
assert_to_yaml (
{ 'hr' = > 65 , 'avg' = > 0 . 278 , 'rbi' = > 147 } , <<EOY
avg : 0 . 278
hr : 65
rbi : 147
EOY
)
end
def test_spec_simple_map_with_nested_sequences
# Simple mapping with nested sequences
assert_to_yaml (
2009-03-05 22:56:38 -05:00
{ 'american' = >
2003-10-03 15:51:25 -04:00
[ 'Boston Red Sox' , 'Detroit Tigers' , 'New York Yankees' ] ,
'national' = >
[ 'New York Mets' , 'Chicago Cubs' , 'Atlanta Braves' ] } , <<EOY
american :
- Boston Red Sox
- Detroit Tigers
- New York Yankees
national :
- New York Mets
- Chicago Cubs
- Atlanta Braves
EOY
)
end
def test_spec_simple_sequence_with_nested_map
# Simple sequence with nested map
assert_to_yaml (
[
{ 'name' = > 'Mark McGwire' , 'hr' = > 65 , 'avg' = > 0 . 278 } ,
{ 'name' = > 'Sammy Sosa' , 'hr' = > 63 , 'avg' = > 0 . 288 }
] , <<EOY
-
avg : 0 . 278
hr : 65
name : Mark McGwire
-
avg : 0 . 288
hr : 63
name : Sammy Sosa
EOY
)
end
def test_spec_sequence_of_sequences
# Simple sequence with inline sequences
assert_parse_only (
2009-03-05 22:56:38 -05:00
[
2003-10-03 15:51:25 -04:00
[ 'name' , 'hr' , 'avg' ] ,
[ 'Mark McGwire' , 65 , 0 . 278 ] ,
[ 'Sammy Sosa' , 63 , 0 . 288 ]
] , <<EOY
- [ name , hr , avg ]
- [ Mark McGwire , 65 , 0 . 278 ]
- [ Sammy Sosa , 63 , 0 . 288 ]
EOY
)
end
def test_spec_mapping_of_mappings
# Simple map with inline maps
assert_parse_only (
{ 'Mark McGwire' = >
{ 'hr' = > 65 , 'avg' = > 0 . 278 } ,
'Sammy Sosa' = >
{ 'hr' = > 63 , 'avg' = > 0 . 288 }
} , <<EOY
Mark McGwire : { hr : 65 , avg : 0 . 278 }
Sammy Sosa : { hr : 63 ,
avg : 0 . 288 }
EOY
)
end
2003-12-15 13:17:43 -05:00
def test_ambiguous_comments
# [ruby-talk:88012]
assert_to_yaml ( " Call the method # dave " , <<EOY )
- - - " Call the method # dave "
EOY
end
2003-10-03 15:51:25 -04:00
def test_spec_nested_comments
# Map and sequences with comments
assert_parse_only (
{ 'hr' = > [ 'Mark McGwire' , 'Sammy Sosa' ] ,
'rbi' = > [ 'Sammy Sosa' , 'Ken Griffey' ] } , <<EOY
hr : # 1998 hr ranking
- Mark McGwire
- Sammy Sosa
rbi :
# 1998 rbi ranking
- Sammy Sosa
- Ken Griffey
EOY
)
end
def test_spec_anchors_and_aliases
# Anchors and aliases
assert_parse_only (
{ 'hr' = >
[ 'Mark McGwire' , 'Sammy Sosa' ] ,
'rbi' = >
[ 'Sammy Sosa' , 'Ken Griffey' ] } , <<EOY
hr :
- Mark McGwire
# Name "Sammy Sosa" scalar SS
- & SS Sammy Sosa
rbi :
# So it can be referenced later.
- * SS
- Ken Griffey
EOY
)
assert_to_yaml (
[ { " arrival " = > " EDI " , " departure " = > " LAX " , " fareref " = > " DOGMA " , " currency " = > " GBP " } , { " arrival " = > " MEL " , " departure " = > " SYD " , " fareref " = > " MADF " , " currency " = > " AUD " } , { " arrival " = > " MCO " , " departure " = > " JFK " , " fareref " = > " DFSF " , " currency " = > " USD " } ] , <<EOY
2009-03-05 22:56:38 -05:00
-
2003-10-03 15:51:25 -04:00
& F fareref : DOGMA
& C currency : GBP
& D departure : LAX
2009-03-05 22:56:38 -05:00
& A arrival : EDI
2003-10-03 15:51:25 -04:00
- { * F : MADF , * C : AUD , * D : SYD , * A : MEL }
- { * F : DFSF , * C : USD , * D : JFK , * A : MCO }
EOY
)
assert_to_yaml (
{ " ALIASES " = > [ " fareref " , " currency " , " departure " , " arrival " ] , " FARES " = > [ { " arrival " = > " EDI " , " departure " = > " LAX " , " fareref " = > " DOGMA " , " currency " = > " GBP " } , { " arrival " = > " MEL " , " departure " = > " SYD " , " fareref " = > " MADF " , " currency " = > " AUD " } , { " arrival " = > " MCO " , " departure " = > " JFK " , " fareref " = > " DFSF " , " currency " = > " USD " } ] } , <<EOY
- - -
ALIASES : [ & f fareref , & c currency , & d departure , & a arrival ]
FARES :
- * f : DOGMA
* c : GBP
* d : LAX
* a : EDI
- * f : MADF
* c : AUD
* d : SYD
* a : MEL
- * f : DFSF
* c : USD
* d : JFK
* a : MCO
EOY
)
end
def test_spec_mapping_between_sequences
# Complex key #1
dj = Date . new ( 2001 , 7 , 23 )
assert_parse_only (
{ [ 'Detroit Tigers' , 'Chicago Cubs' ] = > [ Date . new ( 2001 , 7 , 23 ) ] ,
[ 'New York Yankees' , 'Atlanta Braves' ] = > [ Date . new ( 2001 , 7 , 2 ) , Date . new ( 2001 , 8 , 12 ) , Date . new ( 2001 , 8 , 14 ) ] } , <<EOY
? # PLAY SCHEDULE
- Detroit Tigers
- Chicago Cubs
2009-03-05 22:56:38 -05:00
:
2003-10-03 15:51:25 -04:00
- 2001 - 07 - 23
? [ New York Yankees ,
Atlanta Braves ]
2009-03-05 22:56:38 -05:00
: [ 2001 - 07 - 02 , 2001 - 08 - 12 ,
2003-10-03 15:51:25 -04:00
2001 - 08 - 14 ]
EOY
)
# Complex key #2
assert_parse_only (
{ [ 'New York Yankees' , 'Atlanta Braves' ] = >
[ Date . new ( 2001 , 7 , 2 ) , Date . new ( 2001 , 8 , 12 ) ,
Date . new ( 2001 , 8 , 14 ) ] ,
[ 'Detroit Tigers' , 'Chicago Cubs' ] = >
[ Date . new ( 2001 , 7 , 23 ) ]
} , <<EOY
?
- New York Yankees
- Atlanta Braves
:
- 2001 - 07 - 02
- 2001 - 08 - 12
- 2001 - 08 - 14
?
- Detroit Tigers
- Chicago Cubs
:
- 2001 - 07 - 23
EOY
)
end
def test_spec_sequence_key_shortcut
# Shortcut sequence map
assert_parse_only (
{ 'invoice' = > 34843 , 'date' = > Date . new ( 2001 , 1 , 23 ) ,
'bill-to' = > 'Chris Dumars' , 'product' = >
[ { 'item' = > 'Super Hoop' , 'quantity' = > 1 } ,
{ 'item' = > 'Basketball' , 'quantity' = > 4 } ,
{ 'item' = > 'Big Shoes' , 'quantity' = > 1 } ] } , <<EOY
invoice : 34843
date : 2001 - 01 - 23
bill - to : Chris Dumars
product :
- item : Super Hoop
quantity : 1
- item : Basketball
quantity : 4
- item : Big Shoes
quantity : 1
EOY
)
end
def test_spec_sequence_in_sequence_shortcut
# Seq-in-seq
assert_parse_only ( [ [ [ 'one' , 'two' , 'three' ] ] ] , <<EOY )
- - - one
- two
- three
EOY
end
def test_spec_sequence_shortcuts
# Sequence shortcuts combined
2009-03-05 22:56:38 -05:00
assert_parse_only (
2003-10-03 15:51:25 -04:00
[
2009-03-05 22:56:38 -05:00
[
2003-10-03 15:51:25 -04:00
[ [ 'one' ] ] ,
[ 'two' , 'three' ] ,
{ 'four' = > nil } ,
[ { 'five' = > [ 'six' ] } ] ,
[ 'seven' ]
] ,
[ 'eight' , 'nine' ]
] , <<EOY )
- - - - one
- - two
- three
- four :
- - five :
- six
- - seven
- - eight
- nine
EOY
end
def test_spec_single_literal
# Literal scalar block
assert_parse_only ( [ " \\ /| \\ /| \n / | |_ \n " ] , <<EOY )
- |
\ \ / | \ \ / |
/ | |_
EOY
end
def test_spec_single_folded
# Folded scalar block
assert_parse_only (
[ " Mark McGwire's year was crippled by a knee injury. \n " ] , <<EOY
- >
2004-05-15 00:38:39 -04:00
Mark McGwire \ ' s
2003-10-03 15:51:25 -04:00
year was crippled
by a knee injury .
EOY
)
end
def test_spec_preserve_indent
# Preserve indented spaces
assert_parse_only (
" Sammy Sosa completed another fine season with great stats. \n \n 63 Home Runs \n 0.288 Batting Average \n \n What a year! \n " , <<EOY
- - - >
Sammy Sosa completed another
fine season with great stats .
63 Home Runs
0 . 288 Batting Average
What a year!
EOY
)
end
def test_spec_indentation_determines_scope
assert_parse_only (
{ 'name' = > 'Mark McGwire' , 'accomplishment' = > " Mark set a major league home run record in 1998. \n " ,
'stats' = > " 65 Home Runs \n 0.278 Batting Average \n " } , <<EOY
name : Mark McGwire
accomplishment : >
Mark set a major league
home run record in 1998 .
stats : |
65 Home Runs
0 . 278 Batting Average
EOY
)
end
2010-05-02 19:15:08 -04:00
#
# Reports from N.Easterly & J.Trupiano : Tests with patch from daz
2011-12-20 11:09:17 -05:00
# [ruby-core:23006] [Bug #1311] http://bugs.ruby-lang.org/issues/show/1311
2010-05-02 19:15:08 -04:00
#
def test_scan_scalar_nl
bug1311 = '[ruby-core:23006]'
assert_cycle ( <<EoY, bug1311)
a
b
EoY
assert_cycle ( <<EoY, bug1311)
a
b
c
EoY
assert_cycle ( <<EoY, bug1311)
a
b
EoY
assert_cycle ( " Do I work? \n No indent " , bug1311 )
assert_cycle ( " \n Do I work? \n No indent " , bug1311 )
assert_cycle ( " \n Do I work? \n No indent " , bug1311 )
assert_cycle ( " \n " , bug1311 )
assert_cycle ( " \n \n " , bug1311 )
assert_cycle ( " \r \n " , bug1311 )
assert_cycle <<EoY, '[ruby-core:28777]'
Domain name :
ckgteam . co . uk
Registrant :
James Gregory
Registrant type :
UK Individual
Registrant ' s address :
The registrant is a non - trading individual who has opted to have their
address omitted from the WHOIS service .
Registrar :
Webfusion Ltd t / a 123 - Reg . co . uk [ Tag = 123 - REG ]
URL : http : / / www . 123 - reg . co . uk
Relevant dates :
Registered on : 16 - Nov - 2009
Renewal date : 16 - Nov - 2011
Last updated : 25 - Nov - 2009
Registration status :
Registered until renewal date .
Name servers :
ns1 . slicehost . net
ns2 . slicehost . net
ns3 . slicehost . net
WHOIS lookup made at 11 : 56 : 46 19 - Mar - 2010
2011-05-15 07:55:52 -04:00
- -
2010-05-02 19:15:08 -04:00
This WHOIS information is provided for free by Nominet UK the central registry
for . uk domain names . This information and the . uk WHOIS are :
Copyright Nominet UK 1996 - 2010 .
You may not access the . uk WHOIS or use any data from it except as permitted
by the terms of use available in full at http : / / www . nominet . org . uk / whois , which
includes restrictions on : ( A ) use of the data for advertising , or its
repackaging , recompilation , redistribution or reuse ( B ) obscuring , removing
or hiding any or all of this notice and ( C ) exceeding query rate or volume
limits . The data is provided on an 'as-is' basis and may lag behind the
2011-05-15 07:55:52 -04:00
register . Access may be withdrawn or restricted at any time .
2010-05-02 19:15:08 -04:00
EoY
end
2003-10-03 15:51:25 -04:00
def test_spec_multiline_scalars
# Multiline flow scalars
assert_parse_only (
{ 'plain' = > 'This unquoted scalar spans many lines.' ,
'quoted' = > " So does this quoted scalar. \n " } , <<EOY
plain : This unquoted
scalar spans
many lines .
quoted : " \\
So does this quoted
scalar . \ \ n "
EOY
)
2009-03-05 22:56:38 -05:00
end
2003-10-03 15:51:25 -04:00
def test_spec_type_int
assert_parse_only (
{ 'canonical' = > 12345 , 'decimal' = > 12345 , 'octal' = > '014' . oct , 'hexadecimal' = > '0xC' . hex } , <<EOY
canonical : 12345
decimal : + 12 , 345
octal : 014
hexadecimal : 0xC
EOY
)
2004-01-12 17:55:09 -05:00
assert_parse_only (
2004-01-12 21:39:03 -05:00
{ 'canonical' = > 685230 , 'decimal' = > 685230 , 'octal' = > 02472256 , 'hexadecimal' = > 0x0A74AE , 'sexagesimal' = > 685230 } , <<EOY)
2004-01-12 17:55:09 -05:00
canonical : 685230
decimal : + 685 , 230
octal : 02472256
hexadecimal : 0x0A , 74 , AE
sexagesimal : 190 : 20 : 30
EOY
2003-10-03 15:51:25 -04:00
end
def test_spec_type_float
assert_parse_only (
{ 'canonical' = > 1230 . 15 , 'exponential' = > 1230 . 15 , 'fixed' = > 1230 . 15 ,
2004-01-12 21:39:03 -05:00
'negative infinity' = > - 1 . 0 / 0 . 0 } , <<EOY)
2003-10-03 15:51:25 -04:00
canonical : 1 . 23015 e + 3
exponential : 12 . 3015 e + 02
fixed : 1 , 230 . 15
negative infinity : - . inf
EOY
2004-01-12 21:39:03 -05:00
nan = YAML :: load ( <<EOY )
2003-10-03 15:51:25 -04:00
not a number : . NaN
EOY
assert ( nan [ 'not a number' ] . nan? )
end
def test_spec_type_misc
assert_parse_only (
{ nil = > nil , true = > true , false = > false , 'string' = > '12345' } , <<EOY
null : ~
true : yes
false : no
string : '12345'
EOY
)
end
def test_spec_complex_invoice
# Complex invoice type
id001 = { 'given' = > 'Chris' , 'family' = > 'Dumars' , 'address' = >
{ 'lines' = > " 458 Walkman Dr. \n Suite # 292 \n " , 'city' = > 'Royal Oak' ,
'state' = > 'MI' , 'postal' = > 48046 } }
assert_parse_only (
{ 'invoice' = > 34843 , 'date' = > Date . new ( 2001 , 1 , 23 ) ,
'bill-to' = > id001 , 'ship-to' = > id001 , 'product' = >
[ { 'sku' = > 'BL394D' , 'quantity' = > 4 ,
'description' = > 'Basketball' , 'price' = > 450 . 00 } ,
{ 'sku' = > 'BL4438H' , 'quantity' = > 1 ,
'description' = > 'Super Hoop' , 'price' = > 2392 . 00 } ] ,
'tax' = > 251 . 42 , 'total' = > 4443 . 52 ,
'comments' = > " Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. \n " } , <<EOY
invoice : 34843
date : 2001 - 01 - 23
bill - to : & id001
given : Chris
family : ! str Dumars
address :
lines : |
458 Walkman Dr .
Suite #292
city : Royal Oak
state : MI
postal : 48046
ship - to : * id001
product :
- ! map
sku : BL394D
quantity : 4
description : Basketball
price : 450 . 00
- sku : BL4438H
quantity : 1
description : Super Hoop
price : 2392 . 00
tax : 251 . 42
total : 4443 . 52
comments : >
Late afternoon is best .
Backup contact is Nancy
Billsmer @ 338 - 4338 .
EOY
)
end
def test_spec_log_file
doc_ct = 0
YAML :: load_documents ( <<EOY
- - -
Time : 2001 - 11 - 23 15 : 01 : 42 - 05 : 00
User : ed
Warning : >
This is an error message
for the log file
- - -
Time : 2001 - 11 - 23 15 : 02 : 31 - 05 : 00
User : ed
Warning : >
A slightly different error
message .
- - -
Date : 2001 - 11 - 23 15 : 03 : 17 - 05 : 00
User : ed
Fatal : >
Unknown variable " bar "
Stack :
- file : TopClass . py
line : 23
code : |
x = MoreObject ( " 345 \\ n " )
- file : MoreClass . py
line : 58
code : | -
foo = bar
EOY
) { | doc |
case doc_ct
when 0
assert_equal ( doc , { 'Time' = > mktime ( 2001 , 11 , 23 , 15 , 01 , 42 , 00 , " -05:00 " ) ,
'User' = > 'ed' , 'Warning' = > " This is an error message for the log file \n " } )
when 1
assert_equal ( doc , { 'Time' = > mktime ( 2001 , 11 , 23 , 15 , 02 , 31 , 00 , " -05:00 " ) ,
'User' = > 'ed' , 'Warning' = > " A slightly different error message. \n " } )
when 2
assert_equal ( doc , { 'Date' = > mktime ( 2001 , 11 , 23 , 15 , 03 , 17 , 00 , " -05:00 " ) ,
'User' = > 'ed' , 'Fatal' = > " Unknown variable \" bar \" \n " ,
'Stack' = > [
{ 'file' = > 'TopClass.py' , 'line' = > 23 , 'code' = > " x = MoreObject( \" 345 \\ n \" ) \n " } ,
{ 'file' = > 'MoreClass.py' , 'line' = > 58 , 'code' = > " foo = bar " } ] } )
end
doc_ct += 1
}
assert_equal ( doc_ct , 3 )
end
def test_spec_root_fold
y = YAML :: load ( <<EOY
- - - >
This YAML stream contains a single text value .
The next stream is a log file - a sequence of
log entries . Adding an entry to the log is a
simple matter of appending it at the end .
EOY
)
assert_equal ( y , " This YAML stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end. \n " )
end
def test_spec_root_mapping
y = YAML :: load ( <<EOY
# This stream is an example of a top-level mapping.
invoice : 34843
date : 2001 - 01 - 23
total : 4443 . 52
EOY
)
assert_equal ( y , { 'invoice' = > 34843 , 'date' = > Date . new ( 2001 , 1 , 23 ) , 'total' = > 4443 . 52 } )
end
def test_spec_oneline_docs
doc_ct = 0
YAML :: load_documents ( <<EOY
# The following is a sequence of three documents.
# The first contains an empty mapping, the second
# an empty sequence, and the last an empty string.
- - - { }
- - - [ ]
- - - ''
EOY
) { | doc |
case doc_ct
when 0
assert_equal ( doc , { } )
when 1
assert_equal ( doc , [ ] )
when 2
assert_equal ( doc , '' )
end
doc_ct += 1
}
assert_equal ( doc_ct , 3 )
end
def test_spec_domain_prefix
2005-09-17 13:22:49 -04:00
customer_proc = proc { | type , val |
if Hash === val
2003-10-03 15:51:25 -04:00
scheme , domain , type = type . split ( ':' , 3 )
2005-09-17 13:22:49 -04:00
val [ 'type' ] = " domain #{ type } "
val
else
raise ArgumentError , " Not a Hash in domain.tld,2002/invoice: " + val . inspect
end
}
YAML . add_domain_type ( " domain.tld,2002 " , 'invoice' , & customer_proc )
YAML . add_domain_type ( " domain.tld,2002 " , 'customer' , & customer_proc )
2003-10-03 15:51:25 -04:00
assert_parse_only ( { " invoice " = > { " customers " = > [ { " given " = > " Chris " , " type " = > " domain customer " , " family " = > " Dumars " } ] , " type " = > " domain invoice " } } , <<EOY
# 'http://domain.tld,2002/invoice' is some type family.
invoice : ! domain . tld , 2002 / ^ invoice
# 'seq' is shorthand for 'http://yaml.org/seq'.
# This does not effect '^customer' below
# because it is does not specify a prefix.
customers : ! seq
# '^customer' is shorthand for the full
# notation 'http://domain.tld,2002/customer'.
- ! ^ customer
given : Chris
family : Dumars
EOY
)
end
def test_spec_throwaway
assert_parse_only (
{ " this " = > " contains three lines of text. \n The third one starts with a \n # character. This isn't a comment. \n " } , <<EOY
### These are four throwaway comment ###
### lines (the second line is empty). ###
this : | # Comments may trail lines.
contains three lines of text .
The third one starts with a
# character. This isn't a comment.
# These are three throwaway comment
# lines (the first line is empty).
EOY
)
end
def test_spec_force_implicit
# Force implicit
2009-03-05 22:56:38 -05:00
assert_parse_only (
2003-10-03 15:51:25 -04:00
{ 'integer' = > 12 , 'also int' = > 12 , 'string' = > '12' } , <<EOY
integer : 12
also int : ! " 12 "
string : ! str 12
EOY
)
end
def test_spec_private_types
doc_ct = 0
YAML :: parse_documents ( <<EOY
# Private types are per-document.
- - -
pool : ! ! ball
number : 8
color : black
- - -
bearing : ! ! ball
material : steel
EOY
) { | doc |
case doc_ct
when 0
assert_equal ( doc [ 'pool' ] . type_id , 'x-private:ball' )
assert_equal ( doc [ 'pool' ] . transform . value , { 'number' = > 8 , 'color' = > 'black' } )
when 1
2009-03-05 22:56:38 -05:00
assert_equal ( doc [ 'bearing' ] . type_id , 'x-private:ball' )
2003-10-03 15:51:25 -04:00
assert_equal ( doc [ 'bearing' ] . transform . value , { 'material' = > 'steel' } )
end
doc_ct += 1
}
assert_equal ( doc_ct , 2 )
end
def test_spec_url_escaping
YAML . add_domain_type ( " domain.tld,2002 " , " type0 " ) { | type , val |
" ONE: #{ val } "
}
YAML . add_domain_type ( " domain.tld,2002 " , " type%30 " ) { | type , val |
" TWO: #{ val } "
}
assert_parse_only (
{ 'same' = > [ 'ONE: value' , 'ONE: value' ] , 'different' = > [ 'TWO: value' ] } , <<EOY
same :
- ! domain . tld , 2002 / type \ \ x30 value
- ! domain . tld , 2002 / type0 value
different : # As far as the YAML parser is concerned
- ! domain . tld , 2002 / type % 30 value
EOY
)
end
def test_spec_override_anchor
# Override anchor
a001 = " The alias node below is a repeated use of this value. \n "
2009-03-05 22:56:38 -05:00
assert_parse_only (
2003-10-03 15:51:25 -04:00
{ 'anchor' = > 'This scalar has an anchor.' , 'override' = > a001 , 'alias' = > a001 } , <<EOY
anchor : & A001 This scalar has an anchor .
override : & A001 >
The alias node below is a
repeated use of this value .
alias : * A001
EOY
)
end
def test_spec_explicit_families
2005-09-17 13:22:49 -04:00
YAML . add_domain_type ( " somewhere.com,2002 " , 'type' ) { | type , val |
" SOMEWHERE: #{ val } "
}
2003-10-03 15:51:25 -04:00
assert_parse_only (
{ 'not-date' = > '2002-04-28' , 'picture' = > " GIF89a \f \000 \f \000 \204 \000 \000 \377 \377 \367 \365 \365 \356 \351 \351 \345 fff \000 \000 \000 \347 \347 \347 ^^^ \363 \363 \355 \216 \216 \216 \340 \340 \340 \237 \237 \237 \223 \223 \223 \247 \247 \247 \236 \236 \236 i^ \020 ' \202 \n \001 \000 ; " , 'hmm' = > " SOMEWHERE: family above is short for \n http://somewhere.com/type \n " } , <<EOY
not - date : ! str 2002 - 04 - 28
picture : ! binary |
R0lGODlhDAAMAIQAAP / / 9 / X
17 unp5WZmZgAAAOfn515eXv
Pz7Y6OjuDg4J + fn5OTk6enp
56 enmleECcgggoBADs =
2009-03-05 22:56:38 -05:00
hmm : ! somewhere . com , 2002 / type |
2003-10-03 15:51:25 -04:00
family above is short for
http : / /some where . com / type
EOY
)
end
def test_spec_application_family
# Testing the clarkevans.com graphs
YAML . add_domain_type ( " clarkevans.com,2002 " , 'graph/shape' ) { | type , val |
if Array === val
val << " Shape Container "
val
else
raise ArgumentError , " Invalid graph of type #{ val . class } : " + val . inspect
end
}
one_shape_proc = Proc . new { | type , val |
if Hash === val
type = type . split ( / : / )
val [ 'TYPE' ] = " Shape: #{ type [ 2 ] } "
val
else
raise ArgumentError , " Invalid graph of type #{ val . class } : " + val . inspect
end
}
YAML . add_domain_type ( " clarkevans.com,2002 " , 'graph/circle' , & one_shape_proc )
YAML . add_domain_type ( " clarkevans.com,2002 " , 'graph/line' , & one_shape_proc )
YAML . add_domain_type ( " clarkevans.com,2002 " , 'graph/text' , & one_shape_proc )
assert_parse_only (
[ [ { " radius " = > 7 , " center " = > { " x " = > 73 , " y " = > 129 } , " TYPE " = > " Shape: graph/circle " } , { " finish " = > { " x " = > 89 , " y " = > 102 } , " TYPE " = > " Shape: graph/line " , " start " = > { " x " = > 73 , " y " = > 129 } } , { " TYPE " = > " Shape: graph/text " , " value " = > " Pretty vector drawing. " , " start " = > { " x " = > 73 , " y " = > 129 } , " color " = > 16772795 } , " Shape Container " ] ] , <<EOY
- ! clarkevans . com , 2002 / graph / ^ shape
- ! ^ circle
center : & ORIGIN { x : 73 , y : 129 }
radius : 7
- ! ^ line # !clarkevans.com,2002/graph/line
start : * ORIGIN
finish : { x : 89 , y : 102 }
- ! ^ text
start : * ORIGIN
color : 0xFFEEBB
value : Pretty vector drawing .
EOY
)
end
def test_spec_float_explicit
assert_parse_only (
[ 10 . 0 , 10 . 0 , 10 . 0 , 10 . 0 ] , <<EOY
# All entries in the sequence
# have the same type and value.
- 10 . 0
- ! float 10
- ! yaml . org , 2002 / ^ float '10'
- ! yaml . org , 2002 / float " \\
1 \ \
0 "
EOY
)
end
def test_spec_builtin_seq
# Assortment of sequences
assert_parse_only (
{ 'empty' = > [ ] , 'in-line' = > [ 'one' , 'two' , 'three' , 'four' , 'five' ] ,
'nested' = > [ 'First item in top sequence' , [ 'Subordinate sequence entry' ] ,
" A multi-line sequence entry \n " , 'Sixth item in top sequence' ] } , <<EOY
empty : [ ]
in - line : [ one , two , three # May span lines,
, four , # indentation is
five ] # mostly ignored.
nested :
- First item in top sequence
-
- Subordinate sequence entry
- >
A multi - line
sequence entry
- Sixth item in top sequence
EOY
)
end
def test_spec_builtin_map
# Assortment of mappings
2009-03-05 22:56:38 -05:00
assert_parse_only (
2003-10-03 15:51:25 -04:00
{ 'empty' = > { } , 'in-line' = > { 'one' = > 1 , 'two' = > 2 } ,
'spanning' = > { 'one' = > 1 , 'two' = > 2 } ,
'nested' = > { 'first' = > 'First entry' , 'second' = >
{ 'key' = > 'Subordinate mapping' } , 'third' = >
[ 'Subordinate sequence' , { } , 'Previous mapping is empty.' ,
{ 'A key' = > 'value pair in a sequence.' , 'A second' = > 'key:value pair.' } ,
'The previous entry is equal to the following one.' ,
{ 'A key' = > 'value pair in a sequence.' , 'A second' = > 'key:value pair.' } ] ,
12 . 0 = > 'This key is a float.' , " ? \n " = > 'This key had to be protected.' ,
" \a " = > 'This key had to be escaped.' ,
" This is a multi-line folded key \n " = > " Whose value is also multi-line. \n " ,
[ 'This key' , 'is a sequence' ] = > [ 'With a sequence value.' ] } } , <<EOY
empty : { }
in - line : { one : 1 , two : 2 }
spanning : { one : 1 ,
two : 2 }
nested :
first : First entry
second :
key : Subordinate mapping
third :
- Subordinate sequence
- { }
- Previous mapping is empty .
- A key : value pair in a sequence .
A second : key : value pair .
- The previous entry is equal to the following one .
-
A key : value pair in a sequence .
A second : key : value pair .
! float 12 : This key is a float .
? >
?
: This key had to be protected .
" \\ a " : This key had to be escaped .
? >
This is a
multi - line
folded key
: >
Whose value is
also multi - line .
?
- This key
- is a sequence
:
- With a sequence value .
# The following parses correctly,
# but Ruby 1.6.* fails the comparison!
# ?
# This: key
# is a: mapping
# :
# with a: mapping value.
EOY
)
end
def test_spec_builtin_literal_blocks
# Assortment of literal scalar blocks
assert_parse_only (
{ " both are equal to " = > " This has no newline. " , " is equal to " = > " The \\ ' \" characters may be \n freely used. Leading white \n space is significant. \n \n Line breaks are significant. \n Thus this value contains one \n empty line and ends with a \n single line break, but does \n not start with one. \n " , " also written as " = > " This has no newline. " , " indented and chomped " = > " This has no newline. " , " empty " = > " " , " literal " = > " The \\ ' \" characters may be \n freely used. Leading white \n space is significant. \n \n Line breaks are significant. \n Thus this value contains one \n empty line and ends with a \n single line break, but does \n not start with one. \n " } , <<EOY
empty : |
literal : |
The \ \ ' " characters may be
freely used . Leading white
space is significant .
Line breaks are significant .
Thus this value contains one
empty line and ends with a
single line break , but does
not start with one .
2004-05-15 00:38:39 -04:00
is equal to : " The \\ ' \\ " characters may \ \
2003-10-03 15:51:25 -04:00
be \ \ nfreely used . Leading white \ \ n space \ \
is significant . \ \ n \ \ nLine breaks are \ \
significant . \ \ nThus this value contains \ \
one \ \ nempty line and ends with a \ \ nsingle \ \
line break , but does \ \ nnot start with one . \ \ n "
# Comments may follow a nested
# scalar value. They must be
# less indented.
# Modifiers may be combined in any order.
indented and chomped : | 2 -
This has no newline .
also written as : | - 2
This has no newline .
both are equal to : " This has no newline. "
EOY
)
str1 = " This has one newline. \n "
str2 = " This has no newline. "
str3 = " This has two newlines. \n \n "
2009-03-05 22:56:38 -05:00
assert_parse_only (
{ 'clipped' = > str1 , 'same as "clipped" above' = > str1 ,
'stripped' = > str2 , 'same as "stripped" above' = > str2 ,
2003-10-03 15:51:25 -04:00
'kept' = > str3 , 'same as "kept" above' = > str3 } , <<EOY
clipped : |
This has one newline .
same as " clipped " above : " This has one newline. \\ n "
stripped : | -
This has no newline .
same as " stripped " above : " This has no newline. "
kept : | +
This has two newlines .
same as " kept " above : " This has two newlines. \\ n \\ n "
EOY
)
end
2009-03-05 22:56:38 -05:00
2003-10-03 15:51:25 -04:00
def test_spec_span_single_quote
assert_parse_only ( { " third " = > " a single quote ' must be escaped. " , " second " = > " ! : \\ etc. can be used freely. " , " is same as " = > " this contains six spaces \n and one line break " , " empty " = > " " , " span " = > " this contains six spaces \n and one line break " } , <<EOY
empty : ''
second : '! : \\ etc. can be used freely.'
third : 'a single quote ' ' must be escaped.'
span : ' this contains
six spaces
2009-03-05 22:56:38 -05:00
2003-10-03 15:51:25 -04:00
and one
line break '
is same as : " this contains six spaces \\ nand one line break "
EOY
)
end
def test_spec_span_double_quote
assert_parse_only ( { " is equal to " = > " this contains four spaces " , " third " = > " a \" or a \\ must be escaped. " , " second " = > " ! : etc. can be used freely. " , " empty " = > " " , " fourth " = > " this value ends with an LF. \n " , " span " = > " this contains four spaces " } , <<EOY
empty : " "
second : " ! : etc. can be used freely. "
third : " a \\ \" or a \\ \\ must be escaped. "
fourth : " this value ends with an LF. \\ n "
span : " this contains
four \ \
spaces "
is equal to : " this contains four spaces "
EOY
)
end
def test_spec_builtin_time
# Time
assert_parse_only (
2009-03-05 22:56:38 -05:00
{ " space separated " = > mktime ( 2001 , 12 , 14 , 21 , 59 , 43 , " .10 " , " -05:00 " ) ,
" canonical " = > mktime ( 2001 , 12 , 15 , 2 , 59 , 43 , " .10 " ) ,
" date (noon UTC) " = > Date . new ( 2002 , 12 , 14 ) ,
2003-10-03 15:51:25 -04:00
" valid iso8601 " = > mktime ( 2001 , 12 , 14 , 21 , 59 , 43 , " .10 " , " -05:00 " ) } , <<EOY
canonical : 2001 - 12 - 15 T02 : 59 : 43 . 1 Z
valid iso8601 : 2001 - 12 - 14 t21 : 59 : 43 . 10 - 05 : 00
space separated : 2001 - 12 - 14 21 : 59 : 43 . 10 - 05 : 00
date ( noon UTC ) : 2002 - 12 - 14
EOY
)
end
def test_spec_builtin_binary
arrow_gif = " GIF89a \f \000 \f \000 \204 \000 \000 \377 \377 \367 \365 \365 \356 \351 \351 \345 fff \000 \000 \000 \347 \347 \347 ^^^ \363 \363 \355 \216 \216 \216 \340 \340 \340 \237 \237 \237 \223 \223 \223 \247 \247 \247 \236 \236 \236 iiiccc \243 \243 \243 \204 \204 \204 \377 \376 \371 \377 \376 \371 \377 \376 \371 \377 \376 \371 \377 \376 \371 \377 \376 \371 \377 \376 \371 \377 \376 \371 \377 \376 \371 \377 \376 \371 \377 \376 \371 \377 \376 \371 \377 \376 \371 \377 \376 \371 ! \376 \016 Made with GIMP \000 , \000 \000 \000 \000 \f \000 \f \000 \000 \005 , \216 \201 0 \236 \343 @ \024 \350 i \020 \304 \321 \212 \010 \034 \317 \200 M$z \357 \377 0 \205 p \270 \260 1f \r \e \316 \001 \303 \001 \036 \020 ' \202 \n \001 \000 ; "
assert_parse_only (
2009-03-05 22:56:38 -05:00
{ 'canonical' = > arrow_gif , 'base64' = > arrow_gif ,
2003-10-03 15:51:25 -04:00
'description' = > " The binary value above is a tiny arrow encoded as a gif image. \n " } , <<EOY
canonical : ! binary " \\
R0lGODlhDAAMAIQAAP / / 9 / X17unp5WZmZgAAAOf \ \
n515eXvPz7Y6OjuDg4J + fn5OTk6enp56enmlpaW \ \
NjY6Ojo4SEhP / + + f / + + f / + + f / + + f / + + f / + + f / + + \ \
f / + + f / + + f / + + f / + + f / + + f / + + f / + + SH + Dk1hZGUg \ \
d2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuN \ \
AFOhpEMTRiggcz4BNJHrv / zCFcLiwMWYNG84Bww \ \
EeECcgggoBADs = "
base64 : ! binary |
R0lGODlhDAAMAIQAAP / / 9 / X17unp5WZmZgAAAOf
n515eXvPz7Y6OjuDg4J + fn5OTk6enp56enmlpaW
NjY6Ojo4SEhP / + + f / + + f / + + f / + + f / + + f / + + f / + +
f / + + f / + + f / + + f / + + f / + + f / + + f / + + SH + Dk1hZGUg
d2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuN
AFOhpEMTRiggcz4BNJHrv / zCFcLiwMWYNG84Bww
EeECcgggoBADs =
description : >
The binary value above is a tiny arrow
encoded as a gif image .
EOY
)
end
def test_ruby_regexp
# Test Ruby regular expressions
2009-03-05 22:56:38 -05:00
assert_to_yaml (
2004-05-15 00:38:39 -04:00
{ 'simple' = > / a.b / , 'complex' = > %r'\A"((?:[^"]|\")+)"' ,
2003-10-03 15:51:25 -04:00
'case-insensitive' = > / George McFly /i } , <<EOY
case - insensitive : ! ruby / regexp " /George McFly/i "
complex : ! ruby / regexp " / \\ \\ A \\ " ( ( ?: [ ^ \ \ " ]| \\ \\ \\ " ) + ) \ \ " / "
simple : ! ruby / regexp " /a.b/ "
EOY
)
end
2004-01-28 11:59:00 -05:00
#
# Test of Ranges
#
def test_ranges
# Simple numeric
assert_to_yaml ( 1 .. 3 , <<EOY )
- - - ! ruby / range 1 .. 3
EOY
# Simple alphabetic
assert_to_yaml ( 'a' .. 'z' , <<EOY )
- - - ! ruby / range a .. z
EOY
# Float
assert_to_yaml ( 10 . 5 ... 30 . 3 , <<EOY )
- - - ! ruby / range 10 . 5 ... 30 . 3
EOY
end
2003-10-03 15:51:25 -04:00
def test_ruby_struct
# Ruby structures
book_struct = Struct :: new ( " BookStruct " , :author , :title , :year , :isbn )
assert_to_yaml (
[ book_struct . new ( " Yukihiro Matsumoto " , " Ruby in a Nutshell " , 2002 , " 0-596-00214-9 " ) ,
2009-03-05 22:56:38 -05:00
book_struct . new ( [ 'Dave Thomas' , 'Andy Hunt' ] , " The Pickaxe " , 2002 ,
book_struct . new ( " This should be the ISBN " , " but I have another struct here " , 2002 , " None " )
2003-10-03 15:51:25 -04:00
) ] , <<EOY
- ! ruby / struct : BookStruct
2010-02-04 12:11:00 -05:00
author : Yukihiro Matsumoto
title : Ruby in a Nutshell
year : 2002
isbn : 0 - 596 - 00214 - 9
2003-10-03 15:51:25 -04:00
- ! ruby / struct : BookStruct
2010-02-04 12:11:00 -05:00
author :
2003-10-03 15:51:25 -04:00
- Dave Thomas
- Andy Hunt
2010-02-04 12:11:00 -05:00
title : The Pickaxe
year : 2002
isbn : ! ruby / struct : BookStruct
author : This should be the ISBN
title : but I have another struct here
year : 2002
isbn : None
2003-10-03 15:51:25 -04:00
EOY
)
2003-12-12 13:08:58 -05:00
assert_to_yaml ( YAML_Tests :: StructTest . new ( 123 ) , <<EOY )
2003-12-12 19:02:30 -05:00
- - - ! ruby / struct : YAML_Tests :: StructTest
2010-02-04 12:11:00 -05:00
c : 123
2003-12-12 13:08:58 -05:00
EOY
2003-10-03 15:51:25 -04:00
end
2008-11-06 17:36:07 -05:00
def test_ruby_rational
assert_to_yaml ( Rational ( 1 , 2 ) , <<EOY )
2009-03-05 22:56:38 -05:00
- - - ! ruby / object : Rational
2008-11-06 17:36:07 -05:00
numerator : 1
denominator : 2
EOY
# Read YAML dumped by the ruby 1.8.3.
assert_to_yaml ( Rational ( 1 , 2 ) , " !ruby/object:Rational 1/2 \n " )
assert_raise ( ArgumentError ) { YAML . load ( " !ruby/object:Rational INVALID/RATIONAL \n " ) }
end
def test_ruby_complex
assert_to_yaml ( Complex ( 3 , 4 ) , <<EOY )
2009-03-05 22:56:38 -05:00
- - - ! ruby / object : Complex
2008-11-06 17:36:07 -05:00
image : 4
real : 3
EOY
# Read YAML dumped by the ruby 1.8.3.
assert_to_yaml ( Complex ( 3 , 4 ) , " !ruby/object:Complex 3+4i \n " )
assert_raise ( ArgumentError ) { YAML . load ( " !ruby/object:Complex INVALID+COMPLEXi \n " ) }
end
2003-10-03 15:51:25 -04:00
def test_emitting_indicators
assert_to_yaml ( " Hi, from Object 1. You passed: please, pretty please " , <<EOY
- - - " Hi, from Object 1. You passed: please, pretty please "
EOY
)
end
#
# Test the YAML::Stream class -- INACTIVE at the moment
#
def test_document
y = YAML :: Stream . new ( :Indent = > 2 , :UseVersion = > 0 )
2009-03-05 22:56:38 -05:00
y . add (
2003-10-03 15:51:25 -04:00
{ 'hi' = > 'hello' , 'map' = >
{ 'good' = > 'two' } ,
'time' = > Time . now ,
'try' = > / ^po(.*)$ / ,
'bye' = > 'goodbye'
}
)
y . add ( { 'po' = > 'nil' , 'oper' = > 90 } )
y . add ( { 'hi' = > 'wow!' , 'bye' = > 'wow!' } )
y . add ( { [ 'Red Socks' , 'Boston' ] = > [ 'One' , 'Two' , 'Three' ] } )
y . add ( [ true , false , false ] )
end
#
# Test YPath choices parsing
#
def test_ypath_parsing
assert_path_segments ( " /*/((one|three)/name|place)|//place " ,
[ [ " * " , " one " , " name " ] ,
[ " * " , " three " , " name " ] ,
[ " * " , " place " ] ,
[ " / " , " place " ] ]
)
end
#
# Tests from Tanaka Akira on [ruby-core]
#
def test_akira
# Commas in plain scalars [ruby-core:1066]
assert_to_yaml (
{ " A " = > " A, " , " B " = > " B " } , <<EOY
A : " A, "
B : B
EOY
)
# Double-quoted keys [ruby-core:1069]
assert_to_yaml (
{ " 1 " = > 2 , " 2 " = > 3 } , <<EOY
'1' : 2
" 2 " : 3
EOY
)
# Anchored mapping [ruby-core:1071]
assert_to_yaml (
[ { " a " = > " b " } ] * 2 , <<EOY
- & id001
a : b
- * id001
EOY
)
# Stress test [ruby-core:1071]
# a = []; 1000.times { a << {"a"=>"b", "c"=>"d"} }
# YAML::load( a.to_yaml )
end
2004-01-28 11:59:00 -05:00
#
# Test Time.now cycle
#
def test_time_now_cycle
#
# From Minero Aoki [ruby-core:2305]
#
require 'yaml'
t = Time . now
2007-12-01 12:24:13 -05:00
t = Time . at ( t . tv_sec , t . tv_usec )
2004-01-28 11:59:00 -05:00
5 . times do
2004-05-15 00:38:39 -04:00
assert_cycle ( t )
2004-01-28 11:59:00 -05:00
end
end
2004-02-08 01:43:53 -05:00
#
# Test Range cycle
#
def test_range_cycle
#
# From Minero Aoki [ruby-core:02306]
#
2004-05-15 00:38:39 -04:00
assert_cycle ( " a " .. " z " )
2004-02-08 01:43:53 -05:00
#
# From Nobu Nakada [ruby-core:02311]
#
2004-05-15 00:38:39 -04:00
assert_cycle ( 0 .. 1 )
assert_cycle ( 1 . 0e20 .. 2 . 0e20 )
assert_cycle ( " 0 " .. " 1 " )
assert_cycle ( " .. " ... " ... " )
assert_cycle ( " .rb " .. " .pl " )
assert_cycle ( " .rb " ... " .pl " )
assert_cycle ( '"' ... " . " )
assert_cycle ( " ' " ... " . " )
2004-02-08 01:43:53 -05:00
end
2003-10-03 15:51:25 -04:00
#
# Circular references
#
def test_circular_references
a = [ ] ; a [ 0 ] = a ; a [ 1 ] = a
inspect_str = " [[...], [...]] "
assert_equal ( inspect_str , YAML :: load ( a . to_yaml ) . inspect )
end
2006-01-09 22:05:40 -05:00
#
# Test Symbol cycle
#
def test_symbol_cycle
#
# From Aaron Schrab [ruby-Bugs:2535]
#
assert_cycle ( :" ^foo " )
end
2006-01-09 22:50:28 -05:00
#
# Test Numeric cycle
#
class NumericTest < Numeric
def initialize ( value )
@value = value
end
def == ( other )
@value == other . instance_eval { @value }
end
end
def test_numeric_cycle
assert_cycle ( 1 ) # Fixnum
assert_cycle ( 111111111111111111111111111111111 ) # Bignum
assert_cycle ( NumericTest . new ( 3 ) ) # Subclass of Numeric
end
2006-01-15 20:29:58 -05:00
#
# Test empty map/seq in map cycle
#
def test_empty_map_key
#
# empty seq as key
#
o = YAML . load ( { [ ] = > " " } . to_yaml )
assert_equal ( Hash , o . class )
assert_equal ( [ [ ] ] , o . keys )
#
# empty map as key
#
o = YAML . load ( { { } = > " " } . to_yaml )
assert_equal ( Hash , o . class )
assert_equal ( [ { } ] , o . keys )
end
2007-11-15 12:54:32 -05:00
#
# contributed by riley lynch [ruby-Bugs-8548]
#
def test_object_id_collision
omap = YAML :: Omap . new
1000 . times { | i | omap [ " key_ #{ i } " ] = { " value " = > i } }
raise " id collision in ordered map " if omap . to_yaml =~ / id \ d+ /
end
2007-12-01 00:43:06 -05:00
2008-11-19 03:49:51 -05:00
def test_date_out_of_range
assert_nothing_raised { YAML :: load ( '1900-01-01T00:00:00+00:00' ) }
end
2007-12-01 00:43:06 -05:00
def test_normal_exit
YAML . load ( " 2000-01-01 00:00:00. #{ " 0 " * 1000 } +00:00 \n " )
# '[ruby-core:13735]'
end
2003-10-03 15:51:25 -04:00
end
2010-04-10 20:37:42 -04:00
end