Skip to content

Instantly share code, notes, and snippets.

@castor4bit
Created June 16, 2013 07:44
Show Gist options
  • Select an option

  • Save castor4bit/5791301 to your computer and use it in GitHub Desktop.

Select an option

Save castor4bit/5791301 to your computer and use it in GitHub Desktop.
Spyc tests with syck module.
# http://www.yaml.org/spec/1.2/spec.html
Example 2.1. Sequence of Scalars:
- Mark McGwire
- Sammy Sosa
- Ken Griffey
Example 2.2. Mapping Scalars to Scalars:
hr: 65 # Home runs
avg: 0.278 # Batting average
rbi: 147 # Runs Batted In
Example 2.3. Mapping Scalars to Sequences:
american:
- Boston Red Sox
- Detroit Tigers
- New York Yankees
national:
- New York Mets
- Chicago Cubs
- Atlanta Braves
Example 2.4. Sequence of Mappings:
-
name: Mark McGwire
hr: 65
avg: 0.278
-
name: Sammy Sosa
hr: 63
avg: 0.288
Example 2.5. Sequence of Sequences:
- [name , hr, avg ]
- [Mark McGwire, 65, 0.278]
- [Sammy Sosa , 63, 0.288]
#Example 2.6. Mapping of Mappings:
# Mark McGwire: {hr: 65, avg: 0.278}
# Sammy Sosa: {
# hr: 63,
# avg: 0.288
# }
#Example 2.7. Two Documents in a Stream:
# # Ranking of 1998 home runs
# ---
# - Mark McGwire
# - Sammy Sosa
# - Ken Griffey
#
# # Team ranking
# ---
# - Chicago Cubs
# - St Louis Cardinals
#Example 2.8. Play by Play Feed from a Game:
# ---
# time: 20:03:20
# player: Sammy Sosa
# action: strike (miss)
# ---
# time: 20:03:47
# player: Sammy Sosa
# action: grand slam
#Example 2.9. Single Document with Two Comments:
# ---
# hr: # 1998 hr ranking
# - Mark McGwire
# - Sammy Sosa
# rbi:
# # 1998 rbi ranking
# - Sammy Sosa
# - Ken Griffey
#Example 2.10. Node for "Sammy Sosa" appears twice in this document:
# ---
# hr:
# - Mark McGwire
# # Following node labeled SS
# - &SS Sammy Sosa
# rbi:
# - *SS # Subsequent occurrence
# - Ken Griffey
#Example 2.11. Mapping between Sequences:
# ? - Detroit Tigers
# - Chicago cubs
# :
# - 2001-07-23
#
# ? [ New York Yankees,
# Atlanta Braves ]
# : [ 2001-07-02, 2001-08-12,
# 2001-08-14 ]
#Example 2.12. Compact Nested Mapping:
# ---
# # Products purchased
# - item : Super Hoop
# quantity: 1
# - item : Basketball
# quantity: 4
# - item : Big Shoes
# quantity: 1
#Example 2.13. In literals, newlines are preserved:
# # ASCII Art
# --- |
# \//||\/||
# // || ||__
#Example 2.14. In the folded scalars, newlines become spaces:
#Example 2.15. Folded newlines are preserved for "more indented" and blank lines:
#Example 2.16. Indentation determines scope:
#Example 2.17. Quoted Scalars:
# unicode: "Sosa did fine.\u263A"
# control: "\b1998\t1999\t2000\n"
# hex esc: "\x0d\x0a is \r\n"
#
# single: '"Howdy!" he cried.'
# quoted: ' # Not a ''comment''.'
# tie-fighter: '|\-*-/|'
#Example 2.18. Multi-line Flow Scalars:
# plain:
# This unquoted scalar
# spans many lines.
#
# quoted: "So does this
# quoted scalar.\n"
#Example 2.19. Integers:
# canonical: 12345
# decimal: +12345
# octal: 0o14
# hexadecimal: 0xC
#Example 2.20. Floating Point:
# canonical: 1.23015e+3
# exponential: 12.3015e+02
# fixed: 1230.15
# negative infinity: -.inf
# not a number: .NaN
#Example 2.21. Miscellaneous:
# null:
# booleans: [ true, false ]
# string: '012345'
#Example 2.22. Timestamps:
# canonical: 2001-12-15T02:59:43.1Z
# iso8601: 2001-12-14t21:59:43.10-05:00
# spaced: 2001-12-14 21:59:43.10 -5
# date: 2002-12-14
# Example 2.23. Various Explicit Tags
# ---
# not-date: !!str 2002-04-28
#
# picture: !!binary |
# R0lGODlhDAAMAIQAAP//9/X
# 17unp5WZmZgAAAOfn515eXv
# Pz7Y6OjuDg4J+fn5OTk6enp
# 56enmleECcgggoBADs=
#
# application specific tag: !something |
# The semantics of the tag
# above may be different for
# different documents.
# Example 2.24. Global Tags
#%TAG ! tag:clarkevans.com,2002:
#--- !shape
# # Use the ! handle for presenting
# # tag:clarkevans.com,2002:circle
#- !circle
# center: &ORIGIN {x: 73, y: 129}
# radius: 7
#- !line
# start: *ORIGIN
# finish: { x: 89, y: 102 }
#- !label
# start: *ORIGIN
# color: 0xFFEEBB
# text: Pretty vector drawing.
#Example 2.25. Unordered Sets:
#--- !!set
#? Mark McGwire
#? Sammy Sosa
#? Ken Griff
#Example 2.26. Ordered Mappings:
#--- !!omap
#- Mark McGwire: 65
#- Sammy Sosa: 63
#- Ken Griffy: 58
<?php
require_once ("../Spyc.php");
class SyckModuleTest extends PHPUnit_Framework_TestCase {
public function testLoad() {
$spyc = new Spyc();
$data = file_get_contents('./example.yaml');
$result1 = $spyc->load($data);
$spyc->setting_use_syck_is_possible = true;
$result2 = $spyc->load($data);
$this->assertEquals ($result1, $result2);
}
public function testLoadFile() {
$spyc = new Spyc();
$result1 = $spyc->loadFile('./example.yaml');
$spyc->setting_use_syck_is_possible = true;
$result2 = $spyc->loadFile('./example.yaml');
$this->assertEquals ($result1, $result2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment