wabur 0.2.0d1 → 0.4.0d1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -14
- data/bin/wabur +103 -0
- data/lib/wab/controller.rb +133 -90
- data/lib/wab/data.rb +14 -27
- data/lib/wab/errors.rb +14 -8
- data/lib/wab/impl/bool_expr.rb +25 -0
- data/lib/wab/impl/configuration.rb +166 -0
- data/lib/wab/impl/data.rb +155 -232
- data/lib/wab/impl/expr.rb +26 -0
- data/lib/wab/impl/expr_parser.rb +55 -0
- data/lib/wab/impl/exprs/and.rb +29 -0
- data/lib/wab/impl/exprs/between.rb +41 -0
- data/lib/wab/impl/exprs/eq.rb +28 -0
- data/lib/wab/impl/exprs/gt.rb +30 -0
- data/lib/wab/impl/exprs/gte.rb +30 -0
- data/lib/wab/impl/exprs/has.rb +26 -0
- data/lib/wab/impl/exprs/in.rb +28 -0
- data/lib/wab/impl/exprs/lt.rb +30 -0
- data/lib/wab/impl/exprs/lte.rb +30 -0
- data/lib/wab/impl/exprs/not.rb +27 -0
- data/lib/wab/impl/exprs/or.rb +29 -0
- data/lib/wab/impl/exprs/regex.rb +28 -0
- data/lib/wab/impl/handler.rb +95 -0
- data/lib/wab/impl/model.rb +197 -0
- data/lib/wab/impl/path_expr.rb +14 -0
- data/lib/wab/impl/shell.rb +92 -7
- data/lib/wab/impl/utils.rb +110 -0
- data/lib/wab/impl.rb +24 -0
- data/lib/wab/io/call.rb +4 -7
- data/lib/wab/io/engine.rb +128 -51
- data/lib/wab/io/shell.rb +61 -64
- data/lib/wab/io.rb +0 -2
- data/lib/wab/open_controller.rb +43 -0
- data/lib/wab/shell.rb +46 -61
- data/lib/wab/shell_logger.rb +13 -0
- data/lib/wab/utils.rb +36 -0
- data/lib/wab/uuid.rb +3 -6
- data/lib/wab/version.rb +2 -2
- data/lib/wab.rb +3 -0
- data/pages/Plan.md +20 -14
- data/test/bench_io_shell.rb +49 -0
- data/test/{impl_test.rb → helper.rb} +2 -4
- data/test/mirror_controller.rb +16 -0
- data/test/test_configuration.rb +38 -0
- data/test/test_data.rb +207 -0
- data/test/test_expr.rb +35 -0
- data/test/test_expr_and.rb +24 -0
- data/test/test_expr_between.rb +43 -0
- data/test/test_expr_eq.rb +24 -0
- data/test/test_expr_gt.rb +24 -0
- data/test/test_expr_gte.rb +24 -0
- data/test/test_expr_has.rb +19 -0
- data/test/test_expr_in.rb +24 -0
- data/test/test_expr_lt.rb +24 -0
- data/test/test_expr_lte.rb +24 -0
- data/test/test_expr_not.rb +22 -0
- data/test/test_expr_or.rb +24 -0
- data/test/test_expr_regex.rb +30 -0
- data/test/test_impl.rb +38 -0
- data/test/test_io_shell.rb +189 -0
- data/test/test_model.rb +31 -0
- data/test/test_runner.rb +177 -0
- data/test/tests.rb +3 -8
- metadata +91 -18
- data/lib/wab/model.rb +0 -136
- data/lib/wab/view.rb +0 -21
- data/test/data_test.rb +0 -253
- data/test/ioshell_test.rb +0 -461
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wabur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0d1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 3.3
|
19
|
+
version: '3.3'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 3.3
|
26
|
+
version: '3.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -31,6 +31,9 @@ dependencies:
|
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '13.0'
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,20 +41,29 @@ dependencies:
|
|
38
41
|
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: '0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '13.0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: rake-compiler
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- - "
|
51
|
+
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0.9'
|
54
|
+
- - "<"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '2.0'
|
48
57
|
type: :development
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
51
60
|
requirements:
|
52
|
-
- - "
|
61
|
+
- - ">="
|
53
62
|
- !ruby/object:Gem::Version
|
54
63
|
version: '0.9'
|
64
|
+
- - "<"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '2.0'
|
55
67
|
- !ruby/object:Gem::Dependency
|
56
68
|
name: minitest
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,7 +80,8 @@ dependencies:
|
|
68
80
|
version: '5'
|
69
81
|
description: 'Web Application Builder '
|
70
82
|
email: peter@ohler.com
|
71
|
-
executables:
|
83
|
+
executables:
|
84
|
+
- wabur
|
72
85
|
extensions: []
|
73
86
|
extra_rdoc_files:
|
74
87
|
- README.md
|
@@ -78,28 +91,69 @@ extra_rdoc_files:
|
|
78
91
|
files:
|
79
92
|
- LICENSE
|
80
93
|
- README.md
|
94
|
+
- bin/wabur
|
81
95
|
- lib/wab.rb
|
82
96
|
- lib/wab/controller.rb
|
83
97
|
- lib/wab/data.rb
|
84
98
|
- lib/wab/errors.rb
|
85
99
|
- lib/wab/impl.rb
|
100
|
+
- lib/wab/impl/bool_expr.rb
|
101
|
+
- lib/wab/impl/configuration.rb
|
86
102
|
- lib/wab/impl/data.rb
|
103
|
+
- lib/wab/impl/expr.rb
|
104
|
+
- lib/wab/impl/expr_parser.rb
|
105
|
+
- lib/wab/impl/exprs/and.rb
|
106
|
+
- lib/wab/impl/exprs/between.rb
|
107
|
+
- lib/wab/impl/exprs/eq.rb
|
108
|
+
- lib/wab/impl/exprs/gt.rb
|
109
|
+
- lib/wab/impl/exprs/gte.rb
|
110
|
+
- lib/wab/impl/exprs/has.rb
|
111
|
+
- lib/wab/impl/exprs/in.rb
|
112
|
+
- lib/wab/impl/exprs/lt.rb
|
113
|
+
- lib/wab/impl/exprs/lte.rb
|
114
|
+
- lib/wab/impl/exprs/not.rb
|
115
|
+
- lib/wab/impl/exprs/or.rb
|
116
|
+
- lib/wab/impl/exprs/regex.rb
|
117
|
+
- lib/wab/impl/handler.rb
|
118
|
+
- lib/wab/impl/model.rb
|
119
|
+
- lib/wab/impl/path_expr.rb
|
87
120
|
- lib/wab/impl/shell.rb
|
121
|
+
- lib/wab/impl/utils.rb
|
88
122
|
- lib/wab/io.rb
|
89
123
|
- lib/wab/io/call.rb
|
90
124
|
- lib/wab/io/engine.rb
|
91
125
|
- lib/wab/io/shell.rb
|
92
|
-
- lib/wab/
|
126
|
+
- lib/wab/open_controller.rb
|
93
127
|
- lib/wab/shell.rb
|
128
|
+
- lib/wab/shell_logger.rb
|
129
|
+
- lib/wab/utils.rb
|
94
130
|
- lib/wab/uuid.rb
|
95
131
|
- lib/wab/version.rb
|
96
|
-
- lib/wab/view.rb
|
97
132
|
- pages/Architecture.md
|
98
133
|
- pages/Goals.md
|
99
134
|
- pages/Plan.md
|
100
|
-
- test/
|
101
|
-
- test/
|
102
|
-
- test/
|
135
|
+
- test/bench_io_shell.rb
|
136
|
+
- test/helper.rb
|
137
|
+
- test/mirror_controller.rb
|
138
|
+
- test/test_configuration.rb
|
139
|
+
- test/test_data.rb
|
140
|
+
- test/test_expr.rb
|
141
|
+
- test/test_expr_and.rb
|
142
|
+
- test/test_expr_between.rb
|
143
|
+
- test/test_expr_eq.rb
|
144
|
+
- test/test_expr_gt.rb
|
145
|
+
- test/test_expr_gte.rb
|
146
|
+
- test/test_expr_has.rb
|
147
|
+
- test/test_expr_in.rb
|
148
|
+
- test/test_expr_lt.rb
|
149
|
+
- test/test_expr_lte.rb
|
150
|
+
- test/test_expr_not.rb
|
151
|
+
- test/test_expr_or.rb
|
152
|
+
- test/test_expr_regex.rb
|
153
|
+
- test/test_impl.rb
|
154
|
+
- test/test_io_shell.rb
|
155
|
+
- test/test_model.rb
|
156
|
+
- test/test_runner.rb
|
103
157
|
- test/tests.rb
|
104
158
|
homepage: http://github.com/ohler55/wabur
|
105
159
|
licenses:
|
@@ -126,12 +180,31 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
180
|
version: 1.3.1
|
127
181
|
requirements: []
|
128
182
|
rubyforge_project: wabur
|
129
|
-
rubygems_version: 2.6.
|
183
|
+
rubygems_version: 2.6.13
|
130
184
|
signing_key:
|
131
185
|
specification_version: 4
|
132
186
|
summary: Web Application Builder
|
133
187
|
test_files:
|
134
|
-
- test/
|
135
|
-
- test/
|
136
|
-
- test/
|
188
|
+
- test/bench_io_shell.rb
|
189
|
+
- test/helper.rb
|
190
|
+
- test/mirror_controller.rb
|
191
|
+
- test/test_configuration.rb
|
192
|
+
- test/test_data.rb
|
193
|
+
- test/test_expr.rb
|
194
|
+
- test/test_expr_and.rb
|
195
|
+
- test/test_expr_between.rb
|
196
|
+
- test/test_expr_eq.rb
|
197
|
+
- test/test_expr_gt.rb
|
198
|
+
- test/test_expr_gte.rb
|
199
|
+
- test/test_expr_has.rb
|
200
|
+
- test/test_expr_in.rb
|
201
|
+
- test/test_expr_lt.rb
|
202
|
+
- test/test_expr_lte.rb
|
203
|
+
- test/test_expr_not.rb
|
204
|
+
- test/test_expr_or.rb
|
205
|
+
- test/test_expr_regex.rb
|
206
|
+
- test/test_impl.rb
|
207
|
+
- test/test_io_shell.rb
|
208
|
+
- test/test_model.rb
|
209
|
+
- test/test_runner.rb
|
137
210
|
- test/tests.rb
|
data/lib/wab/model.rb
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
|
2
|
-
module WAB
|
3
|
-
|
4
|
-
# Represents the model portion of a MVC design pattern. It must respond to
|
5
|
-
# request to update the store using either the CRUD type operations that
|
6
|
-
# match the controller.
|
7
|
-
class Model
|
8
|
-
|
9
|
-
# Should create a new data object.
|
10
|
-
#
|
11
|
-
# The return should be the identifier for the object created or if
|
12
|
-
# +with_data+ is true a Data object with an +id+ attribute and a +data+
|
13
|
-
# attribute that contains the full object details.
|
14
|
-
#
|
15
|
-
# On error an Exception should be raised.
|
16
|
-
#
|
17
|
-
# data:: the data to use as a new object.
|
18
|
-
# with_data:: flag indicating the response should include the new object
|
19
|
-
def create(data, with_data=false) # :doc:
|
20
|
-
# TBD implement the default behavior as an example or starting point
|
21
|
-
end
|
22
|
-
|
23
|
-
# Should return the object with the +id+ provided.
|
24
|
-
#
|
25
|
-
# The function should return the result of a fetch on the model with the
|
26
|
-
# provided +id+. The result should be a Data instance which is either the
|
27
|
-
# object data or a wrapper that include the object id in an +id+ attribute
|
28
|
-
# and the object data itself in a +data+ attribute depending on the value
|
29
|
-
# of the +with_id+ argument.
|
30
|
-
#
|
31
|
-
# id:: identifier of the object
|
32
|
-
# with_id:: if true wrap the object data with an envelope that includes
|
33
|
-
# the id as well as the object data.
|
34
|
-
def read(id, with_id=false) # :doc:
|
35
|
-
# TBD implement the default behavior as an example or starting point
|
36
|
-
end
|
37
|
-
|
38
|
-
# Should return the objects with attributes matching the +attrs+ argument.
|
39
|
-
#
|
40
|
-
# The return should be a Hash where the keys are the matching object
|
41
|
-
# identifiers and the value are the object data. An empty Hash or nil
|
42
|
-
# indicates there were no matches.
|
43
|
-
#
|
44
|
-
# attrs:: a Hash with keys matching paths into the target objects and value
|
45
|
-
# equal to the target attribute values. A path can be an array of
|
46
|
-
# keys used to walk a path to the target or a +.+ delimited set of
|
47
|
-
# keys.
|
48
|
-
def read_by_attrs(attrs) # :doc:
|
49
|
-
# TBD implement the default behavior as an example or starting point
|
50
|
-
end
|
51
|
-
|
52
|
-
# Replaces the object data for the identified object.
|
53
|
-
#
|
54
|
-
# The return should be the identifier for the object updated or if
|
55
|
-
# +with_data+ is true a Data object with an +id+ attribute and a +data+
|
56
|
-
# attribute that contains the full object details. Note that depending on
|
57
|
-
# the implemenation the identifier may change as a result of an update.
|
58
|
-
#
|
59
|
-
# On error an Exception should be raised.
|
60
|
-
#
|
61
|
-
# id:: identifier of the object to be replaced
|
62
|
-
# data:: the data to use as a new object.
|
63
|
-
# with_data:: flag indicating the response should include the new object
|
64
|
-
def update(id, data, with_data=false) # :doc:
|
65
|
-
# TBD implement the default behavior as an example or starting point
|
66
|
-
end
|
67
|
-
|
68
|
-
# Delete the identified object.
|
69
|
-
#
|
70
|
-
# On success the deleted object identifier is returned. If the object is
|
71
|
-
# not found then nil is returned. On error an Exception should be raised.
|
72
|
-
#
|
73
|
-
# id:: identifier of the object to be deleted
|
74
|
-
def delete(id) # :doc:
|
75
|
-
# TBD implement the default behavior as an example or starting point
|
76
|
-
end
|
77
|
-
|
78
|
-
# Delete all object that match the set of provided attribute values.
|
79
|
-
#
|
80
|
-
# An array of deleted object identifiers should be returned.
|
81
|
-
#
|
82
|
-
# attrs:: a Hash with keys matching paths into the target objects and value
|
83
|
-
# equal to the target attribute values. A path can be an array of
|
84
|
-
# keys used to walk a path to the target or a +.+ delimited set of
|
85
|
-
# keys.
|
86
|
-
def delete_by_attrs(attrs) # :doc:
|
87
|
-
# TBD implement the default behavior as an example or starting point
|
88
|
-
end
|
89
|
-
|
90
|
-
# Return a Hash of all the objects of the type associated with the
|
91
|
-
# controller.
|
92
|
-
#
|
93
|
-
# The return hash keys should be the identifiers of the objects and the
|
94
|
-
# the values should be either nil or the object data if the +with_data+
|
95
|
-
# flag is true. If the response will be larger than supported one of the
|
96
|
-
# keys should be the empty string which indicated additional instance
|
97
|
-
# exists and were not provided.
|
98
|
-
#
|
99
|
-
# Note that this could return a very large set of data. If the number of
|
100
|
-
# instances in the type is large the +search()+ might be more appropriate
|
101
|
-
# as it allows for paging of results and sorting.
|
102
|
-
#
|
103
|
-
# with_data:: flag indicating the return should include object data
|
104
|
-
def list(with_data=false) # :doc:
|
105
|
-
# TBD implement the default behavior as an example or starting point
|
106
|
-
end
|
107
|
-
|
108
|
-
# Search using a TQL SELECT.
|
109
|
-
#
|
110
|
-
# The provided TQL[http://opo.technology/pages/doc/tql/index.html] can be
|
111
|
-
# either the JSON syntax or the friendly syntax. The call exists on the
|
112
|
-
# controller to allow filtering and permission checking before
|
113
|
-
# execution. Only the default controller is expected to provide a public
|
114
|
-
# version of this method.
|
115
|
-
#
|
116
|
-
# query:: query
|
117
|
-
# format:: can be one of :TQL or :TQL_JSON. The :GraphQL option is
|
118
|
-
# reserved for the future.
|
119
|
-
def search(query, format=:TQL) # :doc:
|
120
|
-
# TBD implement the default behavior as an example or starting point
|
121
|
-
end
|
122
|
-
|
123
|
-
# Subscribe to changes in stored data and push changes to the controller
|
124
|
-
# if it passes the supplied filter.
|
125
|
-
#
|
126
|
-
# The +controller+ +changed+ method is called when changes in data cause
|
127
|
-
# the associated object to pass the provided filter.
|
128
|
-
#
|
129
|
-
# controller:: the controller to notify of changed
|
130
|
-
# filter:: the filter to apply to the data. Syntax is that TQL uses for the FILTER clause.
|
131
|
-
def subscribe(controller, filter)
|
132
|
-
# TBD
|
133
|
-
end
|
134
|
-
|
135
|
-
end # Model
|
136
|
-
end # WAB
|
data/lib/wab/view.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module WAB
|
2
|
-
|
3
|
-
# Represents the view in the MVC design pattern. It is primarily used to
|
4
|
-
# call the controller with requests but can be used to push data out to a
|
5
|
-
# display if push is supported.
|
6
|
-
#
|
7
|
-
# This class is the default implementation.
|
8
|
-
class View
|
9
|
-
|
10
|
-
def initialize()
|
11
|
-
# TBD as the default implementation this should be an HTTP server that
|
12
|
-
# serves files as well as JSON to a Javascript enabled browser.
|
13
|
-
end
|
14
|
-
|
15
|
-
# Push changed data to a display.
|
16
|
-
def changed(data)
|
17
|
-
# TBD
|
18
|
-
end
|
19
|
-
|
20
|
-
end # View
|
21
|
-
end # WAB
|
data/test/data_test.rb
DELETED
@@ -1,253 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
$: << __dir__
|
5
|
-
$: << File.join(File.dirname(File.expand_path(__dir__)), 'lib')
|
6
|
-
|
7
|
-
require 'minitest'
|
8
|
-
require 'minitest/autorun'
|
9
|
-
|
10
|
-
require 'wab'
|
11
|
-
require 'wab/impl'
|
12
|
-
|
13
|
-
$shell = ::WAB::Impl::Shell.new() if $shell.nil?
|
14
|
-
|
15
|
-
class DataTest < Minitest::Test
|
16
|
-
|
17
|
-
class ToHash
|
18
|
-
def initialize(x, y)
|
19
|
-
@h = {x: x, y: y }
|
20
|
-
end
|
21
|
-
def to_h
|
22
|
-
@h
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_json
|
27
|
-
d = $shell.data({
|
28
|
-
boo: true,
|
29
|
-
n: nil,
|
30
|
-
num: 7,
|
31
|
-
float: 7.654,
|
32
|
-
str: 'a string',
|
33
|
-
t: Time.gm(2017, 1, 5, 15, 4, 33.123456789),
|
34
|
-
big: BigDecimal('63.21'),
|
35
|
-
uri: URI('http://opo.technology/sample'),
|
36
|
-
uuid: ::WAB::UUID.new('b0ca922d-372e-41f4-8fea-47d880188ba3'),
|
37
|
-
a: [],
|
38
|
-
h: {},
|
39
|
-
})
|
40
|
-
# downcase to match Ruby 2.3 and 2.4 which encode BigDecimal differently.
|
41
|
-
assert_equal(%|{
|
42
|
-
"boo":true,
|
43
|
-
"n":null,
|
44
|
-
"num":7,
|
45
|
-
"float":7.654,
|
46
|
-
"str":"a string",
|
47
|
-
"t":"2017-01-05t15:04:33.123456789z",
|
48
|
-
"big":0.6321e2,
|
49
|
-
"uri":"http://opo.technology/sample",
|
50
|
-
"uuid":"b0ca922d-372e-41f4-8fea-47d880188ba3",
|
51
|
-
"a":[],
|
52
|
-
"h":{}
|
53
|
-
}
|
54
|
-
|, d.json(2).downcase)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_validate_keys
|
58
|
-
assert_raises() { d = $shell.data({ 'a' => 1}) }
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_repair_keys
|
62
|
-
d = $shell.data({ 'a' => 1}, true)
|
63
|
-
assert_equal({a:1}, d.native, "data not repaired")
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_validate_non_hash_array
|
67
|
-
assert_raises() { d = $shell.data(123) }
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_fix_non_hash_array
|
71
|
-
# can not fix this one
|
72
|
-
assert_raises() { d = $shell.data(123, true) }
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_validate_object
|
76
|
-
assert_raises() { d = $shell.data({a: 1..3}) }
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_repair_to_s_object
|
80
|
-
d = $shell.data({a: 1..3}, true)
|
81
|
-
assert_equal({a:'1..3'}, d.native, "data not repaired")
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_repair_to_h_object
|
85
|
-
d = $shell.data(ToHash.new(1, 2), true)
|
86
|
-
assert_equal({x:1,y:2}, d.native, "data not repaired")
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_hash_get
|
90
|
-
d = $shell.data({a: 1, b: 2})
|
91
|
-
assert_equal(2, d.get('b'), "failed to get 'b'")
|
92
|
-
assert_equal(2, d.get([:b]), "failed to get [:b]")
|
93
|
-
assert_equal(1, d.get(['a']), "failed to get ['a']")
|
94
|
-
assert_nil(d.get(['d']), "failed to get ['d']")
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_array_get
|
98
|
-
d = $shell.data(['a', 'b', 'c'])
|
99
|
-
assert_equal('b', d.get('1'), "failed to get '1'")
|
100
|
-
assert_equal('c', d.get(['2']), "failed to get ['2']")
|
101
|
-
assert_equal('b', d.get([1]), "failed to get [1]")
|
102
|
-
assert_equal('a', d.get([0]), "failed to get [0]")
|
103
|
-
assert_equal('c', d.get([-1]), "failed to get [-1]")
|
104
|
-
assert_nil(d.get([4]), "failed to get [4]")
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_get_mixed
|
108
|
-
d = $shell.data({a: 1, b: ['a', 'b', { c: 3}]})
|
109
|
-
assert_equal(3, d.get('b.2.c'), "failed to get 'b.2.c'")
|
110
|
-
assert_equal(3, d.get([:b, 2, 'c']), "failed to get [b, 2, c]")
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_hash_set
|
114
|
-
d = $shell.data({a: 1})
|
115
|
-
d.set('b', 2)
|
116
|
-
d.set([:c], 3)
|
117
|
-
d.set([:d], 1..4, true)
|
118
|
-
assert_raises() { d.set([:e], 1..5) }
|
119
|
-
assert_equal(%|{
|
120
|
-
"a":1,
|
121
|
-
"b":2,
|
122
|
-
"c":3,
|
123
|
-
"d":"1..4"
|
124
|
-
}
|
125
|
-
|, d.json(2))
|
126
|
-
# replace existing
|
127
|
-
d.set([:c], -3)
|
128
|
-
assert_equal(%|{
|
129
|
-
"a":1,
|
130
|
-
"b":2,
|
131
|
-
"c":-3,
|
132
|
-
"d":"1..4"
|
133
|
-
}
|
134
|
-
|, d.json(2))
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_array_set
|
138
|
-
d = $shell.data(['x'])
|
139
|
-
d.set([2], 'd')
|
140
|
-
assert_equal(%|["x",null,"d"]|, d.json(), "after d")
|
141
|
-
d.set([1], 'c')
|
142
|
-
assert_equal(%|["x","c","d"]|, d.json(), "after c")
|
143
|
-
d.set([0], 'y')
|
144
|
-
assert_equal(%|["y","c","d"]|, d.json(), "after y")
|
145
|
-
d.set([-3], 'b')
|
146
|
-
assert_equal(%|["b","c","d"]|, d.json(), "after b")
|
147
|
-
d.set([-4], 'a')
|
148
|
-
assert_equal(%|["a","b","c","d"]|, d.json(), "after a")
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_set_mixed
|
152
|
-
d = $shell.data({a: 1, b: ['a', 'b', { c: 3}]})
|
153
|
-
d.set('b.2', 'c')
|
154
|
-
assert_equal(%|{"a":1,"b":["a","b","c"]}|, d.json())
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_hash_length
|
158
|
-
d = $shell.data({a: 1, b: 2})
|
159
|
-
assert_equal(2, d.length())
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_array_length
|
163
|
-
d = $shell.data(['a', 'b', 'c'])
|
164
|
-
assert_equal(3, d.length())
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_mixed_length
|
168
|
-
d = $shell.data({a: 1, b: ['a', 'b', { c: 3}]})
|
169
|
-
assert_equal(2, d.length())
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_empty_leaf_count
|
173
|
-
d = $shell.data()
|
174
|
-
assert_equal(0, d.leaf_count())
|
175
|
-
end
|
176
|
-
|
177
|
-
def test_hash_leaf_count
|
178
|
-
d = $shell.data({a: 1, b: 2, c:{}})
|
179
|
-
assert_equal(2, d.leaf_count())
|
180
|
-
end
|
181
|
-
|
182
|
-
def test_array_leaf_count
|
183
|
-
d = $shell.data(['a', 'b', 'c', []])
|
184
|
-
assert_equal(3, d.leaf_count())
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_mixed_leaf_count
|
188
|
-
d = $shell.data({a: 1, b: ['a', 'b', { c: 3}]})
|
189
|
-
assert_equal(4, d.leaf_count())
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_empty_size
|
193
|
-
d = $shell.data()
|
194
|
-
assert_equal(1, d.size())
|
195
|
-
end
|
196
|
-
|
197
|
-
def test_hash_size
|
198
|
-
d = $shell.data({a: 1, b: 2, c:{}})
|
199
|
-
assert_equal(4, d.size())
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_array_size
|
203
|
-
d = $shell.data(['a', 'b', 'c', []])
|
204
|
-
assert_equal(5, d.size())
|
205
|
-
end
|
206
|
-
|
207
|
-
def test_mixed_size
|
208
|
-
d = $shell.data({a: 1, b: ['a', 'b', { c: 3}]})
|
209
|
-
assert_equal(7, d.size())
|
210
|
-
end
|
211
|
-
|
212
|
-
def test_each
|
213
|
-
d = $shell.data({a: 1, b: ['a', 'b', { c: 3}]})
|
214
|
-
paths = []
|
215
|
-
values = []
|
216
|
-
d.each { |p, v|
|
217
|
-
paths << p
|
218
|
-
values << v
|
219
|
-
}
|
220
|
-
assert_equal([[], [:a], [:b], [:b, 0], [:b, 1], [:b, 2], [:b, 2, :c]], paths, "paths mismatch")
|
221
|
-
assert_equal([{:a=>1, :b=>["a", "b", {:c=>3}]}, 1, ["a", "b", {:c=>3}], "a", "b", {:c=>3}, 3], values, "values mismatch")
|
222
|
-
end
|
223
|
-
|
224
|
-
def test_each_leaf
|
225
|
-
d = $shell.data({a: 1, b: ['a', 'b', { c: 3}]})
|
226
|
-
paths = []
|
227
|
-
values = []
|
228
|
-
d.each_leaf { |p, v|
|
229
|
-
paths << p
|
230
|
-
values << v
|
231
|
-
}
|
232
|
-
assert_equal([[:a], [:b, 0], [:b, 1], [:b, 2, :c]], paths, "paths mismatch")
|
233
|
-
assert_equal([1, "a", "b", 3], values, "values mismatch")
|
234
|
-
end
|
235
|
-
|
236
|
-
def test_eql
|
237
|
-
d = $shell.data({a: 1, b: ['a', 'b', { c: 3}]})
|
238
|
-
d2 = $shell.data({a: 1, b: ['a', 'b', { c: 3}]})
|
239
|
-
d3 = $shell.data({a: 1, b: ['a', 'b', { d: 3}]})
|
240
|
-
d4 = $shell.data({a: 1, b: ['a', 'b', { c: 4}]})
|
241
|
-
|
242
|
-
assert(d == d2, "same keys and values should be eql")
|
243
|
-
assert(!(d == d3), "same values different keys should not be eql")
|
244
|
-
assert(!(d == d4), "same keys different values should not be eql")
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_clone
|
248
|
-
d = $shell.data({a: 1, b: ['a', 'b', { c: 3}]})
|
249
|
-
c = d.clone
|
250
|
-
assert(d == c)
|
251
|
-
end
|
252
|
-
|
253
|
-
end # DataTest
|