psych 1.2.2.rc1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -0
- data/CHANGELOG.rdoc +29 -0
- data/Gemfile +11 -0
- data/Manifest.txt +5 -0
- data/Rakefile +1 -1
- data/lib/psych.rb +4 -4
- data/lib/psych/nodes/node.rb +2 -1
- data/lib/psych/scalar_scanner.rb +11 -1
- data/lib/psych/visitors/to_ruby.rb +3 -3
- data/lib/psych/visitors/yaml_tree.rb +2 -2
- data/test/psych/helper.rb +2 -9
- data/test/psych/test_document.rb +4 -4
- data/test/psych/test_numeric.rb +14 -0
- data/test/psych/test_yamldbm.rb +190 -0
- data/test/psych/test_yamlstore.rb +87 -0
- data/test/psych/visitors/test_emitter.rb +8 -8
- metadata +15 -11
data/.travis.yml
ADDED
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
Tue Oct 4 06:29:55 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
2
|
+
|
3
|
+
* ext/psych/lib/psych.rb: calling `yaml` rather than `to_yaml`.
|
4
|
+
* ext/psych/lib/psych/nodes/node.rb: Rename `to_yaml` to just `yaml`
|
5
|
+
in order to avoid YAML::ENGINE switching from replacing this method.
|
6
|
+
* test/psych/helper.rb: fix tests for method name change.
|
7
|
+
* test/psych/test_document.rb: ditto
|
8
|
+
* test/psych/visitors/test_emitter.rb: ditto
|
9
|
+
|
10
|
+
Tue Oct 4 06:20:19 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
11
|
+
|
12
|
+
* ext/psych/lib/psych/scalar_scanner.rb: Match values against the
|
13
|
+
floating point spec defined in YAML to avoid erronious parses.
|
14
|
+
* test/psych/test_numeric.rb: corresponding test.
|
15
|
+
|
16
|
+
Tue Oct 4 05:59:24 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
17
|
+
|
18
|
+
* ext/psych/lib/psych/visitors/to_ruby.rb: ToRuby visitor can be
|
19
|
+
constructed with a ScalarScanner.
|
20
|
+
* ext/psych/lib/psych/visitors/yaml_tree.rb: ScalarScanner can be
|
21
|
+
passed to the YAMLTree visitor.
|
22
|
+
|
23
|
+
Tue Oct 4 05:47:23 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
24
|
+
|
25
|
+
* ext/psych/lib/psych/visitors/to_ruby.rb: Define Regexp::NOENCODING
|
26
|
+
for 1.9.2 backwards compatibility.
|
27
|
+
* ext/psych/lib/psych/visitors/yaml_tree.rb: Fix Date string
|
28
|
+
generation for 1.9.2 backwards compatibility.
|
29
|
+
|
1
30
|
Fri Sep 2 04:05:25 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
2
31
|
|
3
32
|
* ext/psych/lib/psych/visitors/yaml_tree.rb: emit strings tagged as
|
data/Gemfile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
# DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
|
4
|
+
|
5
|
+
source :gemcutter
|
6
|
+
|
7
|
+
|
8
|
+
gem "rake-compiler", ">=0.4.1", :group => [:development, :test]
|
9
|
+
gem "hoe", "~>2.10", :group => [:development, :test]
|
10
|
+
|
11
|
+
# vim: syntax=ruby
|
data/Manifest.txt
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
.autotest
|
2
|
+
.travis.yml
|
2
3
|
CHANGELOG.rdoc
|
4
|
+
Gemfile
|
3
5
|
Manifest.txt
|
4
6
|
README.rdoc
|
5
7
|
Rakefile
|
@@ -66,6 +68,7 @@ test/psych/test_json_tree.rb
|
|
66
68
|
test/psych/test_merge_keys.rb
|
67
69
|
test/psych/test_nil.rb
|
68
70
|
test/psych/test_null.rb
|
71
|
+
test/psych/test_numeric.rb
|
69
72
|
test/psych/test_object.rb
|
70
73
|
test/psych/test_omap.rb
|
71
74
|
test/psych/test_parser.rb
|
@@ -82,6 +85,8 @@ test/psych/test_tainted.rb
|
|
82
85
|
test/psych/test_to_yaml_properties.rb
|
83
86
|
test/psych/test_tree_builder.rb
|
84
87
|
test/psych/test_yaml.rb
|
88
|
+
test/psych/test_yamldbm.rb
|
89
|
+
test/psych/test_yamlstore.rb
|
85
90
|
test/psych/visitors/test_depth_first.rb
|
86
91
|
test/psych/visitors/test_emitter.rb
|
87
92
|
test/psych/visitors/test_to_ruby.rb
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ end
|
|
11
11
|
gem 'rake-compiler', '>= 0.4.1'
|
12
12
|
require "rake/extensiontask"
|
13
13
|
|
14
|
-
Hoe.plugin :debugging, :doofus, :git, :gemspec
|
14
|
+
Hoe.plugin :debugging, :doofus, :git, :gemspec, :bundler
|
15
15
|
|
16
16
|
$hoe = Hoe.spec 'psych' do
|
17
17
|
developer 'Aaron Patterson', 'aaron@tenderlovemaking.com'
|
data/lib/psych.rb
CHANGED
@@ -90,7 +90,7 @@ require 'psych/json'
|
|
90
90
|
|
91
91
|
module Psych
|
92
92
|
# The version is Psych you're using
|
93
|
-
VERSION = '1.2.2
|
93
|
+
VERSION = '1.2.2'
|
94
94
|
|
95
95
|
# The version of libyaml Psych is using
|
96
96
|
LIBYAML_VERSION = Psych.libyaml_version.join '.'
|
@@ -190,7 +190,7 @@ module Psych
|
|
190
190
|
|
191
191
|
visitor = Psych::Visitors::YAMLTree.new options
|
192
192
|
visitor << o
|
193
|
-
visitor.tree.
|
193
|
+
visitor.tree.yaml io, options
|
194
194
|
end
|
195
195
|
|
196
196
|
###
|
@@ -204,7 +204,7 @@ module Psych
|
|
204
204
|
objects.each do |o|
|
205
205
|
visitor << o
|
206
206
|
end
|
207
|
-
visitor.tree.
|
207
|
+
visitor.tree.yaml
|
208
208
|
end
|
209
209
|
|
210
210
|
###
|
@@ -212,7 +212,7 @@ module Psych
|
|
212
212
|
def self.to_json o
|
213
213
|
visitor = Psych::Visitors::JSONTree.new
|
214
214
|
visitor << o
|
215
|
-
visitor.tree.
|
215
|
+
visitor.tree.yaml
|
216
216
|
end
|
217
217
|
|
218
218
|
###
|
data/lib/psych/nodes/node.rb
CHANGED
@@ -40,13 +40,14 @@ module Psych
|
|
40
40
|
# Convert this node to YAML.
|
41
41
|
#
|
42
42
|
# See also Psych::Visitors::Emitter
|
43
|
-
def
|
43
|
+
def yaml io = nil, options = {}
|
44
44
|
real_io = io || StringIO.new(''.encode('utf-8'))
|
45
45
|
|
46
46
|
Visitors::Emitter.new(real_io, options).accept self
|
47
47
|
return real_io.string unless io
|
48
48
|
io
|
49
49
|
end
|
50
|
+
alias :to_yaml :yaml
|
50
51
|
end
|
51
52
|
end
|
52
53
|
end
|
data/lib/psych/scalar_scanner.rb
CHANGED
@@ -7,6 +7,12 @@ module Psych
|
|
7
7
|
# Taken from http://yaml.org/type/timestamp.html
|
8
8
|
TIME = /^\d{4}-\d{1,2}-\d{1,2}([Tt]|\s+)\d{1,2}:\d\d:\d\d(\.\d*)?(\s*Z|[-+]\d{1,2}(:\d\d)?)?/
|
9
9
|
|
10
|
+
# Taken from http://yaml.org/type/float.html
|
11
|
+
FLOAT = /^(?:[-+]?([0-9][0-9_,]*)?\.[0-9.]*([eE][-+][0-9]+)?(?# base 10)
|
12
|
+
|[-+]?[0-9][0-9_,]*(:[0-5]?[0-9])+\.[0-9_]*(?# base 60)
|
13
|
+
|[-+]?\.(inf|Inf|INF)(?# infinity)
|
14
|
+
|\.(nan|NaN|NAN)(?# not a number))$/x
|
15
|
+
|
10
16
|
# Create a new scanner
|
11
17
|
def initialize
|
12
18
|
@string_cache = {}
|
@@ -67,10 +73,14 @@ module Psych
|
|
67
73
|
i += (n.to_f * 60 ** (e - 2).abs)
|
68
74
|
end
|
69
75
|
i
|
76
|
+
when FLOAT
|
77
|
+
return Float(string.gsub(/[,_]/, '')) rescue ArgumentError
|
78
|
+
|
79
|
+
@string_cache[string] = true
|
80
|
+
string
|
70
81
|
else
|
71
82
|
if string.count('.') < 2
|
72
83
|
return Integer(string.gsub(/[,_]/, '')) rescue ArgumentError
|
73
|
-
return Float(string.gsub(/[,_]/, '')) rescue ArgumentError
|
74
84
|
end
|
75
85
|
|
76
86
|
@string_cache[string] = true
|
@@ -9,10 +9,10 @@ module Psych
|
|
9
9
|
###
|
10
10
|
# This class walks a YAML AST, converting each node to ruby
|
11
11
|
class ToRuby < Psych::Visitors::Visitor
|
12
|
-
def initialize
|
13
|
-
super
|
12
|
+
def initialize ss = ScalarScanner.new
|
13
|
+
super()
|
14
14
|
@st = {}
|
15
|
-
@ss =
|
15
|
+
@ss = ss
|
16
16
|
@domain_types = Psych.domain_types
|
17
17
|
end
|
18
18
|
|
@@ -12,13 +12,13 @@ module Psych
|
|
12
12
|
alias :finished? :finished
|
13
13
|
alias :started? :started
|
14
14
|
|
15
|
-
def initialize options = {}, emitter =
|
15
|
+
def initialize options = {}, emitter = TreeBuilder.new, ss = ScalarScanner.new
|
16
16
|
super()
|
17
17
|
@started = false
|
18
18
|
@finished = false
|
19
19
|
@emitter = emitter
|
20
20
|
@st = {}
|
21
|
-
@ss =
|
21
|
+
@ss = ss
|
22
22
|
@options = options
|
23
23
|
|
24
24
|
@dispatch_cache = Hash.new do |h,klass|
|
data/test/psych/helper.rb
CHANGED
@@ -2,6 +2,7 @@ require 'minitest/autorun'
|
|
2
2
|
require 'stringio'
|
3
3
|
require 'tempfile'
|
4
4
|
require 'date'
|
5
|
+
require 'psych'
|
5
6
|
|
6
7
|
module Psych
|
7
8
|
class TestCase < MiniTest::Unit::TestCase
|
@@ -32,7 +33,7 @@ module Psych
|
|
32
33
|
def assert_cycle( obj )
|
33
34
|
v = Visitors::YAMLTree.new
|
34
35
|
v << obj
|
35
|
-
assert_equal(obj, Psych.load(v.tree.
|
36
|
+
assert_equal(obj, Psych.load(v.tree.yaml))
|
36
37
|
assert_equal( obj, Psych::load(Psych.dump(obj)))
|
37
38
|
assert_equal( obj, Psych::load( obj.psych_to_yaml ) )
|
38
39
|
end
|
@@ -53,11 +54,3 @@ module Psych
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
end
|
56
|
-
|
57
|
-
require 'psych'
|
58
|
-
|
59
|
-
# FIXME: remove this when syck is removed
|
60
|
-
o = Object.new
|
61
|
-
a = o.method(:psych_to_yaml)
|
62
|
-
b = o.method(:to_yaml)
|
63
|
-
raise "psych should define to_yaml" unless a == b
|
data/test/psych/test_document.rb
CHANGED
@@ -18,12 +18,12 @@ module Psych
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_emit_tag
|
21
|
-
assert_match('%TAG ! tag:tenderlovemaking.com,2009:', @stream.
|
21
|
+
assert_match('%TAG ! tag:tenderlovemaking.com,2009:', @stream.yaml)
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_emit_multitag
|
25
25
|
@doc.tag_directives << ['!!', 'foo.com,2009:']
|
26
|
-
yaml = @stream.
|
26
|
+
yaml = @stream.yaml
|
27
27
|
assert_match('%TAG ! tag:tenderlovemaking.com,2009:', yaml)
|
28
28
|
assert_match('%TAG !! foo.com,2009:', yaml)
|
29
29
|
end
|
@@ -31,7 +31,7 @@ module Psych
|
|
31
31
|
def test_emit_bad_tag
|
32
32
|
assert_raises(RuntimeError) do
|
33
33
|
@doc.tag_directives = [['!']]
|
34
|
-
@stream.
|
34
|
+
@stream.yaml
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -40,7 +40,7 @@ module Psych
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_emit_version
|
43
|
-
assert_match('%YAML 1.1', @stream.
|
43
|
+
assert_match('%YAML 1.1', @stream.yaml)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'psych/helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
###
|
5
|
+
# Test numerics from YAML spec:
|
6
|
+
# http://yaml.org/type/float.html
|
7
|
+
# http://yaml.org/type/int.html
|
8
|
+
class TestNumeric < TestCase
|
9
|
+
def test_non_float_with_0
|
10
|
+
str = Psych.load('--- 090')
|
11
|
+
assert_equal '090', str
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require 'yaml/dbm'
|
4
|
+
require 'tmpdir'
|
5
|
+
Psych::DBM = YAML::DBM unless defined?(Psych::DBM)
|
6
|
+
|
7
|
+
module Psych
|
8
|
+
class YAMLDBMTest < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@engine, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
|
11
|
+
@dir = Dir.mktmpdir("rubytest-file")
|
12
|
+
File.chown(-1, Process.gid, @dir)
|
13
|
+
@yamldbm_file = make_tmp_filename("yamldbm")
|
14
|
+
@yamldbm = YAML::DBM.new(@yamldbm_file)
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
YAML::ENGINE.yamler = @engine
|
19
|
+
@yamldbm.clear
|
20
|
+
@yamldbm.close
|
21
|
+
FileUtils.remove_entry_secure @dir
|
22
|
+
end
|
23
|
+
|
24
|
+
def make_tmp_filename(prefix)
|
25
|
+
@dir + "/" + prefix + File.basename(__FILE__) + ".#{$$}.test"
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_store
|
29
|
+
@yamldbm.store('a','b')
|
30
|
+
@yamldbm.store('c','d')
|
31
|
+
assert_equal 'b', @yamldbm['a']
|
32
|
+
assert_equal 'd', @yamldbm['c']
|
33
|
+
assert_nil @yamldbm['e']
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_store_using_carret
|
37
|
+
@yamldbm['a'] = 'b'
|
38
|
+
@yamldbm['c'] = 'd'
|
39
|
+
assert_equal 'b', @yamldbm['a']
|
40
|
+
assert_equal 'd', @yamldbm['c']
|
41
|
+
assert_nil @yamldbm['e']
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_to_a
|
45
|
+
@yamldbm['a'] = 'b'
|
46
|
+
@yamldbm['c'] = 'd'
|
47
|
+
assert_equal([['a','b'],['c','d']], @yamldbm.to_a)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_to_hash
|
51
|
+
@yamldbm['a'] = 'b'
|
52
|
+
@yamldbm['c'] = 'd'
|
53
|
+
assert_equal({'a'=>'b','c'=>'d'}, @yamldbm.to_hash)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_has_value?
|
57
|
+
@yamldbm['a'] = 'b'
|
58
|
+
@yamldbm['c'] = 'd'
|
59
|
+
assert_equal true, @yamldbm.has_value?('b')
|
60
|
+
assert_equal true, @yamldbm.has_value?('d')
|
61
|
+
assert_equal false, @yamldbm.has_value?('f')
|
62
|
+
end
|
63
|
+
|
64
|
+
# Note:
|
65
|
+
# YAML::DBM#index makes warning from internal of ::DBM#index.
|
66
|
+
# It says 'DBM#index is deprecated; use DBM#key', but DBM#key
|
67
|
+
# behaves not same as DBM#index.
|
68
|
+
#
|
69
|
+
# def test_index
|
70
|
+
# @yamldbm['a'] = 'b'
|
71
|
+
# @yamldbm['c'] = 'd'
|
72
|
+
# assert_equal 'a', @yamldbm.index('b')
|
73
|
+
# assert_equal 'c', @yamldbm.index('d')
|
74
|
+
# assert_nil @yamldbm.index('f')
|
75
|
+
# end
|
76
|
+
|
77
|
+
def test_key
|
78
|
+
@yamldbm['a'] = 'b'
|
79
|
+
@yamldbm['c'] = 'd'
|
80
|
+
assert_equal 'a', @yamldbm.key('b')
|
81
|
+
assert_equal 'c', @yamldbm.key('d')
|
82
|
+
assert_nil @yamldbm.key('f')
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_fetch
|
86
|
+
assert_equal('bar', @yamldbm['foo']='bar')
|
87
|
+
assert_equal('bar', @yamldbm.fetch('foo'))
|
88
|
+
assert_nil @yamldbm.fetch('bar')
|
89
|
+
assert_equal('baz', @yamldbm.fetch('bar', 'baz'))
|
90
|
+
assert_equal('foobar', @yamldbm.fetch('bar') {|key| 'foo' + key })
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_shift
|
94
|
+
@yamldbm['a'] = 'b'
|
95
|
+
@yamldbm['c'] = 'd'
|
96
|
+
assert_equal(['a','b'], @yamldbm.shift)
|
97
|
+
assert_equal(['c','d'], @yamldbm.shift)
|
98
|
+
assert_nil @yamldbm.shift
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_invert
|
102
|
+
@yamldbm['a'] = 'b'
|
103
|
+
@yamldbm['c'] = 'd'
|
104
|
+
assert_equal({'b'=>'a','d'=>'c'}, @yamldbm.invert)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_update
|
108
|
+
@yamldbm['a'] = 'b'
|
109
|
+
@yamldbm['c'] = 'd'
|
110
|
+
@yamldbm.update({'c'=>'d','e'=>'f'})
|
111
|
+
assert_equal 'b', @yamldbm['a']
|
112
|
+
assert_equal 'd', @yamldbm['c']
|
113
|
+
assert_equal 'f', @yamldbm['e']
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_replace
|
117
|
+
@yamldbm['a'] = 'b'
|
118
|
+
@yamldbm['c'] = 'd'
|
119
|
+
@yamldbm.replace({'c'=>'d','e'=>'f'})
|
120
|
+
assert_nil @yamldbm['a']
|
121
|
+
assert_equal 'd', @yamldbm['c']
|
122
|
+
assert_equal 'f', @yamldbm['e']
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_delete
|
126
|
+
@yamldbm['a'] = 'b'
|
127
|
+
@yamldbm['c'] = 'd'
|
128
|
+
assert_equal 'b', @yamldbm.delete('a')
|
129
|
+
assert_nil @yamldbm['a']
|
130
|
+
assert_equal 'd', @yamldbm['c']
|
131
|
+
assert_nil @yamldbm.delete('e')
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_delete_if
|
135
|
+
@yamldbm['a'] = 'b'
|
136
|
+
@yamldbm['c'] = 'd'
|
137
|
+
@yamldbm['e'] = 'f'
|
138
|
+
|
139
|
+
@yamldbm.delete_if {|k,v| k == 'a'}
|
140
|
+
assert_nil @yamldbm['a']
|
141
|
+
assert_equal 'd', @yamldbm['c']
|
142
|
+
assert_equal 'f', @yamldbm['e']
|
143
|
+
|
144
|
+
@yamldbm.delete_if {|k,v| v == 'd'}
|
145
|
+
assert_nil @yamldbm['c']
|
146
|
+
assert_equal 'f', @yamldbm['e']
|
147
|
+
|
148
|
+
@yamldbm.delete_if {|k,v| false }
|
149
|
+
assert_equal 'f', @yamldbm['e']
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_reject
|
153
|
+
@yamldbm['a'] = 'b'
|
154
|
+
@yamldbm['c'] = 'd'
|
155
|
+
@yamldbm['e'] = 'f'
|
156
|
+
assert_equal({'c'=>'d','e'=>'f'}, @yamldbm.reject {|k,v| k == 'a'})
|
157
|
+
assert_equal({'a'=>'b','e'=>'f'}, @yamldbm.reject {|k,v| v == 'd'})
|
158
|
+
assert_equal({'a'=>'b','c'=>'d','e'=>'f'}, @yamldbm.reject {false})
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_values
|
162
|
+
assert_equal [], @yamldbm.values
|
163
|
+
@yamldbm['a'] = 'b'
|
164
|
+
@yamldbm['c'] = 'd'
|
165
|
+
assert_equal ['b','d'], @yamldbm.values
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_values_at
|
169
|
+
@yamldbm['a'] = 'b'
|
170
|
+
@yamldbm['c'] = 'd'
|
171
|
+
assert_equal ['b','d'], @yamldbm.values_at('a','c')
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_selsct
|
175
|
+
@yamldbm['a'] = 'b'
|
176
|
+
@yamldbm['c'] = 'd'
|
177
|
+
@yamldbm['e'] = 'f'
|
178
|
+
assert_equal(['b','d'], @yamldbm.select('a','c'))
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_selsct_with_block
|
182
|
+
@yamldbm['a'] = 'b'
|
183
|
+
@yamldbm['c'] = 'd'
|
184
|
+
@yamldbm['e'] = 'f'
|
185
|
+
assert_equal([['a','b']], @yamldbm.select {|k,v| k == 'a'})
|
186
|
+
assert_equal([['c','d']], @yamldbm.select {|k,v| v == 'd'})
|
187
|
+
assert_equal([], @yamldbm.select {false})
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'yaml/store'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
Psych::Store = YAML::Store unless defined?(Psych::Store)
|
6
|
+
|
7
|
+
module Psych
|
8
|
+
class YAMLStoreTest < Test::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@engine, YAML::ENGINE.yamler = YAML::ENGINE.yamler, 'psych'
|
11
|
+
@dir = Dir.mktmpdir("rubytest-file")
|
12
|
+
File.chown(-1, Process.gid, @dir)
|
13
|
+
@yamlstore_file = make_tmp_filename("yamlstore")
|
14
|
+
@yamlstore = YAML::Store.new(@yamlstore_file)
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
YAML::ENGINE.yamler = @engine
|
19
|
+
FileUtils.remove_entry_secure @dir
|
20
|
+
end
|
21
|
+
|
22
|
+
def make_tmp_filename(prefix)
|
23
|
+
@dir + "/" + prefix + File.basename(__FILE__) + ".#{$$}.test"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_opening_new_file_in_readonly_mode_should_result_in_empty_values
|
27
|
+
@yamlstore.transaction(true) do
|
28
|
+
assert_nil @yamlstore[:foo]
|
29
|
+
assert_nil @yamlstore[:bar]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_opening_new_file_in_readwrite_mode_should_result_in_empty_values
|
34
|
+
@yamlstore.transaction do
|
35
|
+
assert_nil @yamlstore[:foo]
|
36
|
+
assert_nil @yamlstore[:bar]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_data_should_be_loaded_correctly_when_in_readonly_mode
|
41
|
+
@yamlstore.transaction do
|
42
|
+
@yamlstore[:foo] = "bar"
|
43
|
+
end
|
44
|
+
@yamlstore.transaction(true) do
|
45
|
+
assert_equal "bar", @yamlstore[:foo]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_data_should_be_loaded_correctly_when_in_readwrite_mode
|
50
|
+
@yamlstore.transaction do
|
51
|
+
@yamlstore[:foo] = "bar"
|
52
|
+
end
|
53
|
+
@yamlstore.transaction do
|
54
|
+
assert_equal "bar", @yamlstore[:foo]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_changes_after_commit_are_discarded
|
59
|
+
@yamlstore.transaction do
|
60
|
+
@yamlstore[:foo] = "bar"
|
61
|
+
@yamlstore.commit
|
62
|
+
@yamlstore[:foo] = "baz"
|
63
|
+
end
|
64
|
+
@yamlstore.transaction(true) do
|
65
|
+
assert_equal "bar", @yamlstore[:foo]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_changes_are_not_written_on_abort
|
70
|
+
@yamlstore.transaction do
|
71
|
+
@yamlstore[:foo] = "bar"
|
72
|
+
@yamlstore.abort
|
73
|
+
end
|
74
|
+
@yamlstore.transaction(true) do
|
75
|
+
assert_nil @yamlstore[:foo]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_writing_inside_readonly_transaction_raises_error
|
80
|
+
assert_raise(PStore::Error) do
|
81
|
+
@yamlstore.transaction(true) do
|
82
|
+
@yamlstore[:foo] = "bar"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -46,7 +46,7 @@ module Psych
|
|
46
46
|
@visitor.accept s
|
47
47
|
|
48
48
|
assert_match(/1.1/, @io.string)
|
49
|
-
assert_equal @io.string, s.
|
49
|
+
assert_equal @io.string, s.yaml
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_document_implicit_end
|
@@ -61,8 +61,8 @@ module Psych
|
|
61
61
|
@visitor.accept s
|
62
62
|
|
63
63
|
assert_match(/key: value/, @io.string)
|
64
|
-
assert_equal @io.string, s.
|
65
|
-
assert(/\.\.\./ !~ s.
|
64
|
+
assert_equal @io.string, s.yaml
|
65
|
+
assert(/\.\.\./ !~ s.yaml)
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_scalar
|
@@ -76,7 +76,7 @@ module Psych
|
|
76
76
|
@visitor.accept s
|
77
77
|
|
78
78
|
assert_match(/hello/, @io.string)
|
79
|
-
assert_equal @io.string, s.
|
79
|
+
assert_equal @io.string, s.yaml
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_scalar_with_tag
|
@@ -91,7 +91,7 @@ module Psych
|
|
91
91
|
|
92
92
|
assert_match(/str/, @io.string)
|
93
93
|
assert_match(/hello/, @io.string)
|
94
|
-
assert_equal @io.string, s.
|
94
|
+
assert_equal @io.string, s.yaml
|
95
95
|
end
|
96
96
|
|
97
97
|
def test_sequence
|
@@ -107,7 +107,7 @@ module Psych
|
|
107
107
|
@visitor.accept s
|
108
108
|
|
109
109
|
assert_match(/- hello/, @io.string)
|
110
|
-
assert_equal @io.string, s.
|
110
|
+
assert_equal @io.string, s.yaml
|
111
111
|
end
|
112
112
|
|
113
113
|
def test_mapping
|
@@ -122,7 +122,7 @@ module Psych
|
|
122
122
|
@visitor.accept s
|
123
123
|
|
124
124
|
assert_match(/key: value/, @io.string)
|
125
|
-
assert_equal @io.string, s.
|
125
|
+
assert_equal @io.string, s.yaml
|
126
126
|
end
|
127
127
|
|
128
128
|
def test_alias
|
@@ -137,7 +137,7 @@ module Psych
|
|
137
137
|
@visitor.accept s
|
138
138
|
|
139
139
|
assert_match(/&A key: \*A/, @io.string)
|
140
|
-
assert_equal @io.string, s.
|
140
|
+
assert_equal @io.string, s.yaml
|
141
141
|
end
|
142
142
|
end
|
143
143
|
end
|
metadata
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: psych
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
9
|
- 2
|
10
|
-
|
11
|
-
- 1
|
12
|
-
version: 1.2.2.rc1
|
10
|
+
version: 1.2.2
|
13
11
|
platform: ruby
|
14
12
|
authors:
|
15
13
|
- Aaron Patterson
|
@@ -67,7 +65,9 @@ extra_rdoc_files:
|
|
67
65
|
- README.rdoc
|
68
66
|
files:
|
69
67
|
- .autotest
|
68
|
+
- .travis.yml
|
70
69
|
- CHANGELOG.rdoc
|
70
|
+
- Gemfile
|
71
71
|
- Manifest.txt
|
72
72
|
- README.rdoc
|
73
73
|
- Rakefile
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- test/psych/test_merge_keys.rb
|
135
135
|
- test/psych/test_nil.rb
|
136
136
|
- test/psych/test_null.rb
|
137
|
+
- test/psych/test_numeric.rb
|
137
138
|
- test/psych/test_object.rb
|
138
139
|
- test/psych/test_omap.rb
|
139
140
|
- test/psych/test_parser.rb
|
@@ -150,6 +151,8 @@ files:
|
|
150
151
|
- test/psych/test_to_yaml_properties.rb
|
151
152
|
- test/psych/test_tree_builder.rb
|
152
153
|
- test/psych/test_yaml.rb
|
154
|
+
- test/psych/test_yamldbm.rb
|
155
|
+
- test/psych/test_yamlstore.rb
|
153
156
|
- test/psych/visitors/test_depth_first.rb
|
154
157
|
- test/psych/visitors/test_emitter.rb
|
155
158
|
- test/psych/visitors/test_to_ruby.rb
|
@@ -178,14 +181,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
181
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
182
|
none: false
|
180
183
|
requirements:
|
181
|
-
- - "
|
184
|
+
- - ">="
|
182
185
|
- !ruby/object:Gem::Version
|
183
|
-
hash:
|
186
|
+
hash: 3
|
184
187
|
segments:
|
185
|
-
-
|
186
|
-
|
187
|
-
- 1
|
188
|
-
version: 1.3.1
|
188
|
+
- 0
|
189
|
+
version: "0"
|
189
190
|
requirements: []
|
190
191
|
|
191
192
|
rubyforge_project: psych
|
@@ -213,6 +214,7 @@ test_files:
|
|
213
214
|
- test/psych/test_merge_keys.rb
|
214
215
|
- test/psych/test_nil.rb
|
215
216
|
- test/psych/test_null.rb
|
217
|
+
- test/psych/test_numeric.rb
|
216
218
|
- test/psych/test_object.rb
|
217
219
|
- test/psych/test_omap.rb
|
218
220
|
- test/psych/test_parser.rb
|
@@ -229,6 +231,8 @@ test_files:
|
|
229
231
|
- test/psych/test_to_yaml_properties.rb
|
230
232
|
- test/psych/test_tree_builder.rb
|
231
233
|
- test/psych/test_yaml.rb
|
234
|
+
- test/psych/test_yamldbm.rb
|
235
|
+
- test/psych/test_yamlstore.rb
|
232
236
|
- test/psych/visitors/test_depth_first.rb
|
233
237
|
- test/psych/visitors/test_emitter.rb
|
234
238
|
- test/psych/visitors/test_to_ruby.rb
|