concordia-publishing-house-syck 1.0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.rdoc +6 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +25 -0
  5. data/Manifest.txt +52 -0
  6. data/README.rdoc +51 -0
  7. data/Rakefile +32 -0
  8. data/ext/syck/bytecode.c +1165 -0
  9. data/ext/syck/emitter.c +1247 -0
  10. data/ext/syck/extconf.h +3 -0
  11. data/ext/syck/extconf.rb +5 -0
  12. data/ext/syck/gram.c +1894 -0
  13. data/ext/syck/gram.h +79 -0
  14. data/ext/syck/handler.c +173 -0
  15. data/ext/syck/implicit.c +2990 -0
  16. data/ext/syck/node.c +407 -0
  17. data/ext/syck/rubyext.c +2328 -0
  18. data/ext/syck/syck.c +524 -0
  19. data/ext/syck/syck.h +453 -0
  20. data/ext/syck/token.c +2724 -0
  21. data/ext/syck/yaml2byte.c +259 -0
  22. data/ext/syck/yamlbyte.h +171 -0
  23. data/lib/syck.rb +448 -0
  24. data/lib/syck/baseemitter.rb +242 -0
  25. data/lib/syck/basenode.rb +222 -0
  26. data/lib/syck/constants.rb +45 -0
  27. data/lib/syck/encoding.rb +35 -0
  28. data/lib/syck/error.rb +34 -0
  29. data/lib/syck/loader.rb +14 -0
  30. data/lib/syck/rubytypes.rb +450 -0
  31. data/lib/syck/stream.rb +41 -0
  32. data/lib/syck/stringio.rb +85 -0
  33. data/lib/syck/syck.rb +16 -0
  34. data/lib/syck/tag.rb +95 -0
  35. data/lib/syck/types.rb +192 -0
  36. data/lib/syck/yamlnode.rb +54 -0
  37. data/lib/syck/ypath.rb +54 -0
  38. data/lib/yaml/engine_manager.rb +71 -0
  39. data/lib/yaml/syck.rb +14 -0
  40. data/test/helper.rb +2 -0
  41. data/test/test_array.rb +13 -0
  42. data/test/test_boolean.rb +36 -0
  43. data/test/test_class.rb +11 -0
  44. data/test/test_exception.rb +45 -0
  45. data/test/test_hash.rb +24 -0
  46. data/test/test_null.rb +19 -0
  47. data/test/test_omap.rb +55 -0
  48. data/test/test_set.rb +30 -0
  49. data/test/test_string.rb +44 -0
  50. data/test/test_struct.rb +32 -0
  51. data/test/test_symbol.rb +21 -0
  52. data/test/test_time.rb +23 -0
  53. data/test/test_yaml.rb +1403 -0
  54. data/test/test_yaml_properties.rb +63 -0
  55. metadata +163 -0
@@ -0,0 +1,54 @@
1
+ #
2
+ # YAML::YPath
3
+ #
4
+
5
+ warn "#{caller[0]}: YAML::YPath is deprecated" if $VERBOSE
6
+
7
+ module Syck
8
+
9
+ class YPath
10
+ attr_accessor :segments, :predicates, :flags
11
+ def initialize( str )
12
+ @segments = []
13
+ @predicates = []
14
+ @flags = nil
15
+ while str =~ /^\/?(\/|[^\/\[]+)(?:\[([^\]]+)\])?/
16
+ @segments.push $1
17
+ @predicates.push $2
18
+ str = $'
19
+ end
20
+ unless str.to_s.empty?
21
+ @segments += str.split( "/" )
22
+ end
23
+ if @segments.length == 0
24
+ @segments.push "."
25
+ end
26
+ end
27
+ def self.each_path( str )
28
+ #
29
+ # Find choices
30
+ #
31
+ paths = []
32
+ str = "(#{ str })"
33
+ while str.sub!( /\(([^()]+)\)/, "\n#{ paths.length }\n" )
34
+ paths.push $1.split( '|' )
35
+ end
36
+
37
+ #
38
+ # Construct all possible paths
39
+ #
40
+ all = [ str ]
41
+ ( paths.length - 1 ).downto( 0 ) do |i|
42
+ all = all.collect do |a|
43
+ paths[i].collect do |p|
44
+ a.gsub( /\n#{ i }\n/, p )
45
+ end
46
+ end.flatten.uniq
47
+ end
48
+ all.collect do |path|
49
+ yield YPath.new( path )
50
+ end
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,71 @@
1
+ ##
2
+ # The YAML module allows you to use one of the two YAML engines that ship with
3
+ # ruby. By default Psych is used but the old and unmaintained Syck may be
4
+ # chosen.
5
+ #
6
+ # See Psych or Syck for usage and documentation.
7
+ #
8
+ # To set the YAML engine to syck:
9
+ #
10
+ # YAML::ENGINE.yamler = 'syck'
11
+ #
12
+ # To set the YAML engine back to psych:
13
+ #
14
+ # YAML::ENGINE.yamler = 'psych'
15
+
16
+ module YAML
17
+ class EngineManager # :nodoc:
18
+ attr_reader :yamler
19
+
20
+ def initialize
21
+ @yamler = nil
22
+ end
23
+
24
+ def syck?
25
+ 'syck' == @yamler
26
+ end
27
+
28
+ def yamler= engine
29
+ raise(ArgumentError, "bad engine") unless %w{syck psych}.include?(engine)
30
+
31
+ require engine unless (engine == 'syck' ? Syck : Psych).const_defined?(:VERSION)
32
+
33
+ Object.class_eval <<-eorb, __FILE__, __LINE__ + 1
34
+ remove_const 'YAML'
35
+ YAML = #{engine.capitalize}
36
+ remove_method :to_yaml
37
+ alias :to_yaml :#{engine}_to_yaml
38
+ eorb
39
+
40
+ @yamler = engine
41
+ engine
42
+ end
43
+ end
44
+
45
+ ##
46
+ # Allows changing the current YAML engine. See YAML for details.
47
+
48
+ remove_const :ENGINE if const_defined? :ENGINE
49
+ ENGINE = YAML::EngineManager.new
50
+ end
51
+
52
+ if defined?(Psych)
53
+ engine = 'psych'
54
+ elsif defined?(Syck)
55
+ engine = 'syck'
56
+ else
57
+ begin
58
+ require 'psych'
59
+ engine = 'psych'
60
+ rescue LoadError
61
+ warn "#{caller[0]}:"
62
+ warn "It seems your ruby installation is missing psych (for YAML output)."
63
+ warn "To eliminate this warning, please install libyaml and reinstall your ruby."
64
+ require 'syck'
65
+ engine = 'syck'
66
+ end
67
+ end
68
+
69
+ module Syck
70
+ ENGINE = YAML::ENGINE
71
+ end
@@ -0,0 +1,14 @@
1
+ # $Id$
2
+ #
3
+ # = yaml/syck.rb:
4
+ #
5
+
6
+ require 'stringio'
7
+ require 'syck.so'
8
+ require 'syck/error'
9
+ require 'syck/syck'
10
+ require 'syck/tag'
11
+ require 'syck/stream'
12
+ require 'syck/constants'
13
+ require 'syck/rubytypes'
14
+ require 'syck/types'
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require 'syck'
@@ -0,0 +1,13 @@
1
+ require 'helper'
2
+
3
+ module Syck
4
+ class TestArray < Test::Unit::TestCase
5
+ def setup
6
+ @list = [{ :a => 'b' }, 'foo']
7
+ end
8
+
9
+ def test_dump
10
+ assert_equal @list, Syck.load(Syck.dump(@list))
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ module Syck
4
+ ###
5
+ # Test booleans from YAML spec:
6
+ # http://yaml.org/type/bool.html
7
+ class TestBoolean < Test::Unit::TestCase
8
+ %w{ yes Yes YES true True TRUE on On ON }.each do |truth|
9
+ define_method(:"test_#{truth}") do
10
+ assert_equal true, Syck.load("--- #{truth}")
11
+ end
12
+ end
13
+
14
+ %w{ no No NO false False FALSE off Off OFF }.each do |truth|
15
+ define_method(:"test_#{truth}") do
16
+ assert_equal false, Syck.load("--- #{truth}")
17
+ end
18
+ end
19
+
20
+ ###
21
+ # YAML spec says "y" and "Y" may be used as true, but Syck treats them
22
+ # as literal strings
23
+ def test_y
24
+ assert_equal "y", Syck.load("--- y")
25
+ assert_equal "Y", Syck.load("--- Y")
26
+ end
27
+
28
+ ###
29
+ # YAML spec says "n" and "N" may be used as false, but Syck treats them
30
+ # as literal strings
31
+ def test_n
32
+ assert_equal "n", Syck.load("--- n")
33
+ assert_equal "N", Syck.load("--- N")
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ require 'helper'
2
+
3
+ module Syck
4
+ class TestClass < Test::Unit::TestCase
5
+ def test_dump
6
+ assert_raises(::TypeError) do
7
+ Syck.dump TestClass
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,45 @@
1
+ require 'helper'
2
+
3
+ module Syck
4
+ class TestException < Test::Unit::TestCase
5
+ class Wups < Exception
6
+ attr_reader :foo, :bar
7
+ def initialize *args
8
+ super
9
+ @foo = 1
10
+ @bar = 2
11
+ end
12
+ end
13
+
14
+ def setup
15
+ @wups = Wups.new('test_message')
16
+ end
17
+
18
+ def test_to_yaml
19
+ w = Syck.load(Syck.dump(@wups))
20
+ assert_equal @wups, w
21
+ assert_equal 1, w.foo
22
+ assert_equal 2, w.bar
23
+ end
24
+
25
+ def test_dump
26
+ w = Syck.load(Syck.dump(@wups))
27
+ assert_equal @wups, w
28
+ assert_equal 1, w.foo
29
+ assert_equal 2, w.bar
30
+ end
31
+
32
+ def test_to_yaml_properties
33
+ class << @wups
34
+ def to_yaml_properties
35
+ [:@foo]
36
+ end
37
+ end
38
+
39
+ w = Syck.load(Syck.dump(@wups))
40
+ assert_equal @wups, w
41
+ assert_equal 1, w.foo
42
+ assert_nil w.bar
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,24 @@
1
+ require 'helper'
2
+
3
+ module Syck
4
+ class TestHash < Test::Unit::TestCase
5
+ def setup
6
+ @hash = { :a => 'b' }
7
+ end
8
+
9
+ def test_dump
10
+ assert_equal @hash, Syck.load(Syck.dump(@hash))
11
+ end
12
+
13
+ def test_ref_append
14
+ hash = Syck.load(<<-eoyml)
15
+ ---
16
+ foo: &foo
17
+ hello: world
18
+ bar:
19
+ <<: *foo
20
+ eoyml
21
+ assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ module Syck
4
+ ###
5
+ # Test null from YAML spec:
6
+ # http://yaml.org/type/null.html
7
+ class TestNull < Test::Unit::TestCase
8
+ def test_null_list
9
+ assert_equal [nil] * 5, Syck.load(<<-eoyml)
10
+ ---
11
+ - ~
12
+ - null
13
+ -
14
+ - Null
15
+ - NULL
16
+ eoyml
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,55 @@
1
+ require 'helper'
2
+
3
+ module Syck
4
+ class TestOmap < Test::Unit::TestCase
5
+ def test_keys
6
+ map = Syck::Omap.new
7
+ map['foo'] = 'bar'
8
+ assert_equal 'bar', map['foo']
9
+ end
10
+
11
+ def test_order
12
+ map = Syck::Omap.new
13
+ map['a'] = 'b'
14
+ map['b'] = 'c'
15
+ assert_equal [%w{a b}, %w{b c}], map.to_a
16
+ end
17
+
18
+ def test_square
19
+ list = [["a", "b"], ["b", "c"]]
20
+ map = Syck::Omap[*list.flatten]
21
+ assert_equal list, map.to_a
22
+ assert_equal 'b', map['a']
23
+ assert_equal 'c', map['b']
24
+ end
25
+
26
+ def test_to_yaml
27
+ map = Syck::Omap['a', 'b', 'c', 'd']
28
+ yaml = map.to_yaml
29
+ assert_match('!omap', yaml)
30
+ assert_match('- a: b', yaml)
31
+ assert_match('- c: d', yaml)
32
+ end
33
+
34
+ def test_round_trip
35
+ list = [["a", "b"], ["b", "c"]]
36
+ map = Syck::Omap[*list.flatten]
37
+ loaded = Syck.load(Syck.dump(map))
38
+
39
+ assert_equal map, loaded
40
+ assert_equal list, loaded.to_a
41
+ end
42
+
43
+ ###
44
+ # FIXME: Syck should also support !!omap as shorthand
45
+ def test_load
46
+ list = [["a", "b"], ["c", "d"]]
47
+ map = Syck.load(<<-eoyml)
48
+ --- !omap
49
+ - a: b
50
+ - c: d
51
+ eoyml
52
+ assert_equal list, map.to_a
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+
3
+ module Syck
4
+ class TestSet < Test::Unit::TestCase
5
+ def setup
6
+ @set = Syck::Set.new
7
+ @set['foo'] = 'bar'
8
+ @set['bar'] = 'baz'
9
+ end
10
+
11
+ def test_to_yaml
12
+ assert_match(/!set/, @set.to_yaml)
13
+ end
14
+
15
+ def test_roundtrip
16
+ assert_equal(@set, Syck.load(Syck.dump(@set)))
17
+ end
18
+
19
+ ###
20
+ # FIXME: Syck should also support !!set as shorthand
21
+ def test_load_from_yaml
22
+ loaded = Syck.load(<<-eoyml)
23
+ --- !set
24
+ foo: bar
25
+ bar: baz
26
+ eoyml
27
+ assert_equal(@set, loaded)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ require 'helper'
2
+
3
+ module Syck
4
+ class TestString < Test::Unit::TestCase
5
+ def test_binary_string_null
6
+ string = "\x00"
7
+ yml = Syck.dump string
8
+ assert_match(/binary/, yml)
9
+ assert_equal string, Syck.load(yml)
10
+ end
11
+
12
+ def test_binary_string
13
+ string = binary_string
14
+ yml = Syck.dump string
15
+ assert_match(/binary/, yml)
16
+ assert_equal string, Syck.load(yml)
17
+ end
18
+
19
+ def test_non_binary_string
20
+ string = binary_string(0.29)
21
+ yml = Syck.dump string
22
+ assert_not_match(/binary/, yml)
23
+ assert_equal string, Syck.load(yml)
24
+ end
25
+
26
+ def test_string_with_ivars
27
+ food = "is delicious"
28
+ ivar = "on rock and roll"
29
+ food.instance_variable_set(:@we_built_this_city, ivar)
30
+
31
+ str = Syck.load Syck.dump food
32
+ assert_equal ivar, food.instance_variable_get(:@we_built_this_city)
33
+ end
34
+
35
+ def binary_string percentage = 0.31, length = 100
36
+ string = ''
37
+ (percentage * length).to_i.times do |i|
38
+ string << "\b"
39
+ end
40
+ string << 'a' * (length - string.length)
41
+ string
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ class StructWithIvar < Struct.new(:foo)
4
+ attr_reader :bar
5
+ def initialize *args
6
+ super
7
+ @bar = 'hello'
8
+ end
9
+ end
10
+
11
+ module Syck
12
+ class TestStruct < MiniTest::Unit::TestCase
13
+ def test_roundtrip
14
+ thing = StructWithIvar.new('bar')
15
+ struct = Syck.load(Syck.dump(thing))
16
+
17
+ assert_equal 'hello', struct.bar
18
+ assert_equal 'bar', struct.foo
19
+ end
20
+
21
+ def test_load
22
+ obj = Syck.load(<<-eoyml)
23
+ --- !ruby/struct:StructWithIvar
24
+ foo: bar
25
+ @bar: hello
26
+ eoyml
27
+
28
+ assert_equal 'hello', obj.bar
29
+ assert_equal 'bar', obj.foo
30
+ end
31
+ end
32
+ end