##\
# YAML handler fixtures for testing accepted syntax and data types.
#
# This file is a part of the "common classes package", utilised by a number of
# packages and projects, including CIDRAM and phpMussel.
# Source: https://github.com/Maikuolan/Common
##/
Deep outermost:
Deep outer:
Deep inner:
Deep innermost: "Thus, from here, within this variable, a value is inserted"
String foo: "Bar"
Integer foo: 1234
Float foo: 123.4
Example implicit numeric array:
- "Bar0"
- "Bar1"
- "Bar2"
- "Bar3"
Example explicit numeric array:
0: "Bar0"
1: "Bar1"
2: "Bar2"
3: "Bar3"
Example associative array:
Foo1: "Bar1"
Foo2: "Bar2"
Foo3: "Bar3"
Foo4: "Bar4"
Example null set:
? "Bar0"
? "Bar1"
? "Bar2"
? "Bar3"
Example mixed multi-dimensional array:
- "Bar0"
- "Bar1"
2: "Bar2"
3: "Bar3"
xFooX: "xBarX"
Some int: 4567
Sub array:
Hello: "World"
Sub-sub array:
Foobar: "Barfoo"
Multi-line example: |
h e l l o - w o r l d
hello-world
Folded multi-line example: >
Hello
world.
This
is
an
example.
Example booleans and null:
This is true: true
This is also true: +
This is false: false
This is also false: -
This is null: null
This is also null: ~
Testing anchors:
Anchored text push: &TestAnchor "Some placeholder text."
Anchored text pull: *TestAnchor
Escaping test:
- "They said, \"Our number is \#123-456-789\"."
- "???????? \xE3\x81\x93\xE3\x82\x93\xE3\x81\xAB\xE3\x81\xA1\xE3\x81\xAF\xE4\xB8\x96\xE7\x95\x8C\xE3\x80\x82 \u3053\u3093\u306B\u3061\u306F\u4E16\u754C\u3002 \U00003053\U00003093\U0000306B\U00003061\U0000306F\U00004E16\U0000754C\U00003002"
- "????? ???????. \xD9\x85\xD8\xB1\xD8\xAD\xD8\xA8\xD8\xA7 \xD8\xA8\xD8\xA7\xD9\x84\xD8\xB9\xD8\xA7\xD9\x84\xD9\x85."
- "????? \xE4\xBD\xA0\xE5\xA5\xBD\xE4\xB8\x96\xE7\x95\x8C\xE3\x80\x82 \u4F60\u597D\u4E16\u754C\u3002 \U00004F60\U0000597D\U00004E16\U0000754C\U00003002"
Inserts test: "Hello world; {{Deep outermost.Deep outer.Deep inner.Deep innermost}}; It should work, hopefully."
Inline array example: [this, is, a, test., "Foo", "Bar", true, false, 123]
Hexadecimal number notation: 0x10000
Binary number notation: 0b10000
Octal number notation: 0o10000
Example explicit tags (type coercion):
Normal string: &NormalString "123 Hello"
Make the string a bool: !!bool "123 Hello"
Make the string a float: !!float "123 Hello"
Make the string a null set: !!set "123 Hello"
Make the string a null: !!null "123 Hello"
Make the string a numeric array: !!seq "123 Hello"
Make the string an integer: !!int "123 Hello"
Make the string an integer from an anchor: !!int *NormalString
Normal integer: &NormalInteger 12345
Make the integer a bool: !!bool 12345
Make the integer a float: !!float 12345
Make the integer a null set: !!set 12345
Make the integer a null: !!null 12345
Make the integer a numeric array: !!seq 12345
Make the integer a string: !!str 12345
Make the integer a string from an anchor: !!str *NormalInteger
Normal float: &NormalFloat 123.456
Make the float a bool: !!bool 123.456
Make the float a null: !!null 123.456
Make the float a string: !!str 123.456
Make the float an integer: !!int 123.456
Make the float an integer from an anchor: !!int *NormalFloat
Normal array: &NormalArray ["Foo", "Bar", 1]
Make the array a bool: !!bool ["Foo", "Bar", 1]
Make the array a float: !!float ["Foo", "Bar", 1]
Make the array a null set: !!set ["Foo", "Bar", 1]
Make the array a null: !!null ["Foo", "Bar", 1]
Make the array a numeric array: !!seq ["Foo", "Bar", 1]
Make the array an integer: !!int ["Foo", "Bar", 1]
Make the array an integer from an anchor: !!int *NormalArray
To bool:
- !!bool "0"
- !!bool "1"
- !!bool "Hello"
- !!bool "fAlSe"
- !!bool "false"
- !!bool "tRuE"
- !!bool "true"
- !!bool 0
- !!bool 1
- !!bool null
To int:
- !!int "0"
- !!int "1"
- !!int "Hello"
- !!int false
- !!int null
- !!int true
To string:
- !!str null
- !!str true
- !!str false
Binary single-line example: !!binary SGVsbG8gd29ybGQhIDotKQ==
Binary multi-line example: !!binary |
TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCw
gc2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYW
duYSBhbGlxdWEu
Make the array into a null set: !!set
Foo: "Bar"
Foz: "Baz"
Far: "Boo"
Make the array sequential (numeric): !!seq
Foo: "Bar"
Foz: "Baz"
Far: "Boo"
Example flow mapping: {Foo: "Bar", Foz: "Baz", Far: "Boo"}
Test ability to merge:
Foo: "Bar1"
Foz: "Baz1"
Far: "Boo1"
<<:
Foo: "Bar2"
Moz: "Baz2"
Mar: "Boo2"
<<:
Lorem: "Ipsum"
2: {Foo: "Bar3", Woo: "Bar3"}
3: "Should not appear"
World: !!merge {Hi there: "How are you", What are you doing: "Reading a YAML file"}
Test ability to merge (block tag): !!merge
Blocky foo: "Bar1"
Blocky foz: "Baz1"
Blocky far: "Boo1"
<<:
Blocky lorem: "Blocky ipsum"
World: !!merge {Blocky hello: "How are you", What is happening: "Reading a YAML file"}
Mixed flow style test 1: ["Foo","Bar",{Hello World: "Hello to the world! :-)",Goodbye world:"Goodbye cruel world. :-(",Oh hi there:"Oh hi there! ;-)"},"What's up buddy"]
Mixed flow style test 2: &MixedFlow {Foo and bar:["Foo","Bar"],Hellos and goodbyes:{Hello World: "Hello to the world! :-)",Goodbye world:"Goodbye cruel world. :-(",Oh hi there:"Oh hi there! ;-)"},Deeper:{And deeper:{And deepest:["What's up buddy","How're you"]}}}
Flattened array test 1: !flatten *MixedFlow
Flattened array test 2: !flatten
Somewhere to start: "Somewhere to go"
<<: *MixedFlow
Multidimensional:
Lorem ipsum: "Dolor sit amet, consectetur adipiscing elit."
Sed do eiusmod tempor: "Incididunt ut labore et dolore magna aliqua."
Test support for PHP functions in YAML:
String functions:
Test addslashes: !addslashes "'"<>&"
Test bin2hex: !bin2hex "Hello world."
Test hex2bin: !hex2bin "48656c6c6f20776f726c642e"
Test html_entity_decode: !html_entity_decode "&\#039;"<>&"
Test htmlentities: !htmlentities "'"<>&"
Test htmlspecialchars: !htmlspecialchars "'"<>&"
Test htmlspecialchars_decode: !htmlspecialchars_decode "&\#039;"<>&"
Test lcfirst: !lcfirst "HELLO WORLD."
Test nl2br: !nl2br "Hello\nworld."
Test ord: !ord "Hello world."
Test quotemeta: !quotemeta ".\+*?[^]($)"
Test str_rot13: !str_rot13 "Hello world."
Test strip_tags: !strip_tags "<p>Hello world.</p>"
Test stripslashes: !stripslashes "\He\l\l\o\ \w\or\l\d\."
Test stripcslashes: !stripcslashes "\He\l\l\o\ \w\or\l\d\."
Test strlen: !strlen "Hello world."
Test strrev: !strrev "Hello world."
Test strtolower: !strtolower "Hello world."
Test strtoupper: !strtoupper "Hello world."
Test ucfirst: !ucfirst "hello world."
Test ucwords: !ucwords "hello world."
Numeric functions:
Default number: &NumericDefault 123456789.87654321
Default number int: &NumericDefaultInt 123456789
Test abs: !abs *NumericDefault
Test acos: !acos *NumericDefault
Test acosh: !acosh *NumericDefault
Test asin: !asin *NumericDefault
Test asinh: !asinh *NumericDefault
Test atan: !atan *NumericDefault
Test atanh: !atanh *NumericDefault
Test ceil: !ceil *NumericDefault
Test chr: !chr *NumericDefaultInt
Test cos: !cos *NumericDefault
Test cosh: !cosh *NumericDefault
Test decbin: !decbin *NumericDefaultInt
Test dechex: !dechex *NumericDefaultInt
Test decoct: !decoct *NumericDefaultInt
Test deg2rad: !deg2rad *NumericDefault
Test exp: !exp *NumericDefault
Test expm1: !expm1 *NumericDefault
Test floor: !floor *NumericDefault
Test log10: !log10 *NumericDefault
Test log1p: !log1p *NumericDefault
Test rad2deg: !rad2deg *NumericDefault
Test round: !round *NumericDefault
Test sin: !sin *NumericDefault
Test sinh: !sinh *NumericDefault
Test tan: !tan *NumericDefault
Test tanh: !tanh *NumericDefault
Test sqrt: !sqrt *NumericDefault
Hashes:
Test MD2: !hash:md2 "Hello world."
Test MD5: !hash:md5 "Hello world."
Test SHA1: !hash:sha1 "Hello world."
Test SHA256: !hash:sha256 "Hello world."
Test SHA512: !hash:sha512 "Hello world."
Test Whirlpool: !hash:whirlpool "Hello world."
Specification examples:
2.1. Collections:
2.1 Sequence of Scalars:
- Mark McGwire
- Sammy Sosa
- Ken Griffey
2.2 Mapping Scalars to Scalars:
hr: 65 # Home runs
avg: 0.278 # Batting average
rbi: 147 # Runs Batted In
2.3 Mapping Scalars to Sequences:
american:
- Boston Red Sox
- Detroit Tigers
- New York Yankees
national:
- New York Mets
- Chicago Cubs
- Atlanta Braves
2.4 Sequence of Mappings:
-
name: Mark McGwire
hr: 65
avg: 0.278
-
name: Sammy Sosa
hr: 63
avg: 0.288
2.5 Sequence of Sequences:
- [name , hr, avg ]
- [Mark McGwire, 65, 0.278]
- [Sammy Sosa , 63, 0.288]
2.6 Mapping of Mappings:
Mark McGwire: {hr: 65, avg: 0.278}
Sammy Sosa: {
hr: 63,
avg: 0.288,
}
2.12 Compact Nested Mapping:
- item : Super Hoop
quantity: 1
- item : Basketball
quantity: 4
- item : Big Shoes
quantity: 1
2.3. Scalars:
2.16 Indentation determines scope:
name: Mark McGwire
accomplishment: >
Mark set a major league
home run record in 1998.
stats: |
65 Home Runs
0.278 Batting Average
List support:
[aa, ab, ac, ad]: "All keys same value." # Assigns 4 elements to the parent array (or "flow map"), using the values of the flow sequence at the left operand as the keys, all with the same value of "All keys same value."
[ba, bb, bc, bd]: ["ww", "xx", "yy", "zz"] # Key-value pairs balanced; Assigns 4 elements to the parent array (or "flow map"), using the values of the flow sequence at the left operand as the keys, and the values of the flow sequence at the right operand as the values.
[ca, cb, cc, cd]: ["vv", "ww", "xx", "yy", "zz"] # Key-value pairs NOT balanced; Assigns 1 element to the parent array: A non-associative array (or "flow sequence") whose key is the literal left operand, and whose elements use the values of the flow sequence at the right operand.
Support for entities(
Hello World: "Hello World"
I am a number: 123
Does it work: "It works"
Recursive entity(
Can it recurse: "Yes it can!"
)
)
Support for inline entities(Hello World: "Hello World", I am a number: 123, Does it work: "It works")
End of file: ":-)"
|