rkwalify 1.4.0.pre.beta → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/workflows/ruby.yml +2 -2
- data/.rubocop.yml +24 -2
- data/.ruby-version +1 -1
- data/Attic/spec/rspec-ex_spec.rb +1 -1
- data/CHANGELOG.md +60 -22
- data/CODE_OF_CONDUCT.md +147 -0
- data/Gemfile.lock +5 -4
- data/README.md +9 -12
- data/ROLL-OUT-STRATEGY.md +5 -4
- data/SECURITY.md +19 -0
- data/bin/kwalify +26 -31
- data/bin/kwalify.rb +26 -31
- data/devbin/README.md +6 -2
- data/{contrib → devbin}/inline-require +1 -1
- data/devbin/mkbig-rkwalify.sh +1 -3
- data/devbin/mktag +2 -2
- data/devbin/rubycheck.sh +39 -0
- data/devbin/run-smoketest.sh +17 -0
- data/devbin/smoke-tests.golden +67 -73
- data/devbin/smoke-tests.sh +23 -20
- data/devbin/update-rel-numbers.sh +3 -3
- data/doc-api/classes/CommandOptionError.html +1 -1
- data/doc-api/classes/Kwalify/Util.html +2 -2
- data/doc-api/classes/Kwalify.html +1 -1
- data/doc-api/files/__/README_txt.html +1 -1
- data/doc-api/files/kwalify/errors_rb.html +1 -1
- data/doc-api/files/kwalify/main_rb.html +1 -1
- data/doc-api/files/kwalify/messages_rb.html +1 -1
- data/doc-api/files/kwalify/meta-validator_rb.html +1 -1
- data/doc-api/files/kwalify/parser/base_rb.html +1 -1
- data/doc-api/files/kwalify/parser/yaml_rb.html +1 -1
- data/doc-api/files/kwalify/rule_rb.html +1 -1
- data/doc-api/files/kwalify/types_rb.html +1 -1
- data/doc-api/files/kwalify/util/assert-text-equal_rb.html +1 -1
- data/doc-api/files/kwalify/util/hash-interface_rb.html +1 -1
- data/doc-api/files/kwalify/util/hashlike_rb.html +1 -1
- data/doc-api/files/kwalify/util/option-parser_rb.html +1 -1
- data/doc-api/files/kwalify/util/ordered-hash_rb.html +1 -1
- data/doc-api/files/kwalify/util/testcase-helper_rb.html +1 -1
- data/doc-api/files/kwalify/util_rb.html +1 -1
- data/doc-api/files/kwalify/validator_rb.html +1 -1
- data/doc-api/files/kwalify/yaml-parser_rb.html +1 -1
- data/doc-api/files/kwalify_rb.html +1 -1
- data/examples/address-book/address-book.schema.yaml +1 -1
- data/examples/invoice/invoice.schema.yaml +1 -1
- data/examples/tapkit/tapkit.schema.yaml +1 -1
- data/lib/kwalify/errors.rb +2 -2
- data/lib/kwalify/main.rb +3 -5
- data/lib/kwalify/messages.rb +1 -1
- data/lib/kwalify/meta-validator.rb +4 -5
- data/lib/kwalify/parser/base.rb +2 -3
- data/lib/kwalify/parser/yaml.rb +5 -5
- data/lib/kwalify/rule.rb +13 -14
- data/lib/kwalify/templates/genclass-java.eruby +1 -1
- data/lib/kwalify/templates/genclass-php.eruby +1 -1
- data/lib/kwalify/templates/genclass-ruby.eruby +1 -1
- data/lib/kwalify/types.rb +1 -1
- data/lib/kwalify/util/assert-text-equal.rb +2 -2
- data/lib/kwalify/util/hash-interface.rb +1 -1
- data/lib/kwalify/util/hashlike.rb +5 -4
- data/lib/kwalify/util/option-parser.rb +1 -1
- data/lib/kwalify/util/ordered-hash.rb +1 -1
- data/lib/kwalify/util/testcase-helper.rb +1 -1
- data/lib/kwalify/util.rb +8 -7
- data/lib/kwalify/validator.rb +38 -13
- data/lib/kwalify/version.rb +1 -1
- data/lib/kwalify/yaml-parser.rb +17 -14
- data/lib/kwalify.rb +26 -1
- data/test/Rookbook.yaml +1 -1
- data/test/data/users-guide/answers-validator.rb +0 -0
- data/test/data/users-guide/validate08.rb +0 -0
- data/test/test-action.rb +1 -1
- data/test/test-action.yaml +1 -1
- data/test/test-databinding.rb +3 -5
- data/test/test-databinding.yaml +1 -1
- data/test/test-hashlike.rb +29 -0
- data/test/test-main.rb +1 -1
- data/test/test-main.yaml +1 -1
- data/test/test-metavalidator.rb +5 -5
- data/test/test-metavalidator.yaml +1 -1
- data/test/test-parser-yaml.rb +5 -5
- data/test/test-parser-yaml.yaml +1 -2
- data/test/test-rule.rb +1 -1
- data/test/test-rule.yaml +1 -2
- data/test/test-users-guide.rb +1 -1
- data/test/test-util.rb +1 -1
- data/test/test-validator.rb +4 -4
- data/test/test-validator.yaml +1 -1
- data/test/test-yaml-parser.rb +3 -3
- data/test/test-yaml-parser.yaml +47 -48
- data/test/test.rb +40 -25
- data/test/test_logger.rb +37 -0
- metadata +11 -6
- data/.rubocop_todo.yml +0 -1369
- data/contrib/kwalify +0 -4167
- /data/{contrib → Attic}/kwalify-0.7.2 +0 -0
- /data/{MIT-LICENSE → MIT-LICENSE.txt} +0 -0
data/lib/kwalify/main.rb
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
|
-
# frozen_string_literal: false
|
|
7
6
|
|
|
8
7
|
require 'yaml'
|
|
9
8
|
require 'erb'
|
|
@@ -81,11 +80,10 @@ module Kwalify
|
|
|
81
80
|
def execute(argv=ARGV)
|
|
82
81
|
## parse command-line options
|
|
83
82
|
filenames = _parse_argv(argv)
|
|
84
|
-
|
|
85
83
|
## help or version
|
|
86
84
|
if @options[:help] || @options[:version]
|
|
87
85
|
action = @options[:action]
|
|
88
|
-
s =
|
|
86
|
+
s = String.new
|
|
89
87
|
s << _version() << "\n" if @options[:version]
|
|
90
88
|
s << _usage() if @options[:help] && !action
|
|
91
89
|
s << _describe_properties(action) if @options[:help] && action
|
|
@@ -129,7 +127,7 @@ module Kwalify
|
|
|
129
127
|
exit 1
|
|
130
128
|
rescue Kwalify::KwalifyError => ex
|
|
131
129
|
raise ex if main.debug?
|
|
132
|
-
$stderr.puts "ERROR: #{ex
|
|
130
|
+
$stderr.puts "ERROR: #{ex}"
|
|
133
131
|
exit 1
|
|
134
132
|
#rescue => ex
|
|
135
133
|
# if main.debug?
|
data/lib/kwalify/messages.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
6
|
|
|
@@ -65,7 +65,7 @@ module Kwalify
|
|
|
65
65
|
pat = (val =~ /\A\/(.*)\/([mi]?[mi]?)\z/ ? $1 : val)
|
|
66
66
|
begin
|
|
67
67
|
Regexp.compile(pat)
|
|
68
|
-
rescue RegexpError =>
|
|
68
|
+
rescue RegexpError => _ex
|
|
69
69
|
errors << validate_error(:pattern_syntaxerr, rule, "#{path}/pattern", val)
|
|
70
70
|
end
|
|
71
71
|
end
|
|
@@ -91,9 +91,8 @@ module Kwalify
|
|
|
91
91
|
val = hash['assert']
|
|
92
92
|
#val =~ /\bval\b/ or errors << validate_error(:assert_noval, rule, "#{path}/assert", val)
|
|
93
93
|
begin
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
rescue ::SyntaxError => ex
|
|
94
|
+
RubyVM::InstructionSequence.compile("proc { |val| #{val} }")
|
|
95
|
+
rescue SyntaxError
|
|
97
96
|
errors << validate_error(:assert_syntaxerr, rule, "#{path}/assert", val)
|
|
98
97
|
end
|
|
99
98
|
end
|
data/lib/kwalify/parser/base.rb
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
|
-
# frozen_string_literal: false
|
|
7
6
|
|
|
8
7
|
require 'strscan'
|
|
9
8
|
require 'kwalify/errors'
|
|
@@ -83,7 +82,7 @@ class Kwalify::BaseParser
|
|
|
83
82
|
ch = _getch()
|
|
84
83
|
ch == '"' || ch == "'" or raise "assertion error"
|
|
85
84
|
endch = ch
|
|
86
|
-
s =
|
|
85
|
+
s = String.new
|
|
87
86
|
while !(ch = _getch()).nil? && ch != endch
|
|
88
87
|
if ch != '\\'
|
|
89
88
|
s << ch
|
data/lib/kwalify/parser/yaml.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
6
|
|
|
@@ -521,7 +521,7 @@ class Kwalify::Yaml::Parser < Kwalify::BaseParser
|
|
|
521
521
|
else # indicator == '>'
|
|
522
522
|
if !text.empty? && spaces.length == indent
|
|
523
523
|
if s.sub!(/\r?\n((\r?\n)+)\z/, '\1')
|
|
524
|
-
nil
|
|
524
|
+
# Ruby will return "nil"
|
|
525
525
|
elsif is_folded
|
|
526
526
|
s.sub!(/\r?\n\z/, ' ')
|
|
527
527
|
end
|
|
@@ -536,7 +536,7 @@ class Kwalify::Yaml::Parser < Kwalify::BaseParser
|
|
|
536
536
|
end
|
|
537
537
|
## chomping
|
|
538
538
|
if chomping == '+'
|
|
539
|
-
nil
|
|
539
|
+
# Ruby will return "nil"
|
|
540
540
|
elsif chomping == '-'
|
|
541
541
|
s.sub!(/(\r?\n)+\z/, '')
|
|
542
542
|
else
|
|
@@ -599,7 +599,7 @@ class Kwalify::Yaml::Parser < Kwalify::BaseParser
|
|
|
599
599
|
scan('[')
|
|
600
600
|
skip_spaces_and_comments()
|
|
601
601
|
if scan(']')
|
|
602
|
-
nil
|
|
602
|
+
# Ruby will return "nil"
|
|
603
603
|
else
|
|
604
604
|
rule = seq_rule ? seq_rule.sequence[0] : nil #*V
|
|
605
605
|
uniq_table = rule ? rule._uniqueness_check_table() : nil #*V
|
|
@@ -638,7 +638,7 @@ class Kwalify::Yaml::Parser < Kwalify::BaseParser
|
|
|
638
638
|
scan('{')
|
|
639
639
|
skip_spaces_and_comments()
|
|
640
640
|
if scan('}')
|
|
641
|
-
nil
|
|
641
|
+
# Ruby will return "nil"
|
|
642
642
|
else
|
|
643
643
|
path.push(nil)
|
|
644
644
|
is_merged = false
|
data/lib/kwalify/rule.rb
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
|
-
# frozen_string_literal: false
|
|
7
6
|
|
|
8
7
|
require 'kwalify/messages'
|
|
9
8
|
require 'kwalify/errors'
|
|
@@ -74,12 +73,13 @@ module Kwalify
|
|
|
74
73
|
end
|
|
75
74
|
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
@@dispatch_table = table
|
|
82
|
-
|
|
76
|
+
# Dispatch table maps schema keys to their initialization methods.
|
|
77
|
+
# This allows dynamic method lookup for _init_<key>_value methods.
|
|
78
|
+
SCHEMA_KEYS = %w[type name desc required pattern enum assert range length
|
|
79
|
+
ident unique default sequence mapping class].freeze
|
|
80
|
+
@@dispatch_table = SCHEMA_KEYS.each_with_object({}) do |key, table|
|
|
81
|
+
table[key.intern] = :"_init_#{key}_value"
|
|
82
|
+
end.freeze
|
|
83
83
|
|
|
84
84
|
protected
|
|
85
85
|
|
|
@@ -163,7 +163,7 @@ module Kwalify
|
|
|
163
163
|
flag += Regexp::MULTILINE if opt.include?("m")
|
|
164
164
|
begin
|
|
165
165
|
@regexp = Regexp.compile(pat, flag)
|
|
166
|
-
rescue RegexpError =>
|
|
166
|
+
rescue RegexpError => _ex
|
|
167
167
|
#* key=:pattern_syntaxerr msg="has regexp error."
|
|
168
168
|
raise schema_error(:pattern_syntaxerr, rule, path, val)
|
|
169
169
|
end
|
|
@@ -206,10 +206,9 @@ module Kwalify
|
|
|
206
206
|
raise schema_error(:assert_noval, rule, path, val)
|
|
207
207
|
end
|
|
208
208
|
begin
|
|
209
|
-
#
|
|
210
|
-
@
|
|
211
|
-
|
|
212
|
-
rescue ::SyntaxError => ex
|
|
209
|
+
# Store expression as string, evaluate at validation time
|
|
210
|
+
@assert_expr = val
|
|
211
|
+
rescue ::SyntaxError => _ex
|
|
213
212
|
#* key=:assert_syntaxerr msg="expression syntax error."
|
|
214
213
|
raise schema_error(:assert_syntaxerr, rule, path, val)
|
|
215
214
|
end
|
|
@@ -473,7 +472,7 @@ module Kwalify
|
|
|
473
472
|
protected
|
|
474
473
|
|
|
475
474
|
|
|
476
|
-
def _inspect(str=
|
|
475
|
+
def _inspect(str = String.new, level = 0, done = {})
|
|
477
476
|
done[self.__id__] = true
|
|
478
477
|
str << (" " * level) << "name: #{@name}\n" unless @name.nil?
|
|
479
478
|
str << (" " * level) << "desc: #{@desc}\n" unless @desc.nil?
|
data/lib/kwalify/types.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
6
|
|
|
@@ -29,7 +29,7 @@ class Test::Unit::TestCase # :nodoc:
|
|
|
29
29
|
expfile.write(expected); expfile.flush()
|
|
30
30
|
actfile = Tempfile.new(".actual.")
|
|
31
31
|
actfile.write(actual); actfile.flush()
|
|
32
|
-
diff =
|
|
32
|
+
diff = system("diff", *diffopt, expfile.path, actfile.path)
|
|
33
33
|
ensure
|
|
34
34
|
expfile.close(true) if expfile
|
|
35
35
|
actfile.close(true) if actfile
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
6
|
|
|
@@ -27,13 +27,14 @@ module Kwalify
|
|
|
27
27
|
#end
|
|
28
28
|
#++
|
|
29
29
|
|
|
30
|
-
def key?(key)
|
|
31
|
-
instance_variables().include?("@#{key}")
|
|
32
|
-
end
|
|
33
30
|
if Object.method_defined?('instance_variable_defined?')
|
|
34
31
|
def key?(key)
|
|
35
32
|
instance_variable_defined?("@#{key}")
|
|
36
33
|
end
|
|
34
|
+
else
|
|
35
|
+
def key?(key)
|
|
36
|
+
instance_variables().include?("@#{key}")
|
|
37
|
+
end
|
|
37
38
|
end
|
|
38
39
|
|
|
39
40
|
def each # not necessary
|
data/lib/kwalify/util.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
|
-
# frozen_string_literal:
|
|
6
|
+
# frozen_string_literal: true
|
|
7
7
|
|
|
8
8
|
module Kwalify
|
|
9
9
|
|
|
@@ -17,18 +17,19 @@ module Kwalify
|
|
|
17
17
|
## ex.
|
|
18
18
|
## untabified_str = YamlHelper.untabify(tabbed_str)
|
|
19
19
|
##
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
def untabify(str, width = 8)
|
|
21
22
|
return str if str.nil?
|
|
22
|
-
list = str.split("\t", -1)
|
|
23
|
+
list = str.split("\t", -1)
|
|
23
24
|
last = list.pop
|
|
24
|
-
sb =
|
|
25
|
+
sb = String.new
|
|
25
26
|
list.each do |s|
|
|
26
27
|
column = (n = s.rindex(?\n)) ? s.length - n - 1 : s.length
|
|
27
28
|
n = width - (column % width)
|
|
28
29
|
sb << s << (' ' * n)
|
|
29
30
|
end
|
|
30
31
|
sb << last if last
|
|
31
|
-
|
|
32
|
+
sb
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
|
|
@@ -121,7 +122,7 @@ module Kwalify
|
|
|
121
122
|
hashlist.each do |hash|
|
|
122
123
|
key = hash[primarykey]
|
|
123
124
|
unless key
|
|
124
|
-
|
|
125
|
+
raise "primary key '#{key}' not found."
|
|
125
126
|
end
|
|
126
127
|
if flag_duplicate_check && hashtable.key?(key)
|
|
127
128
|
raise "primary key '#{key}' duplicated (value '#{hashtable[key]}')"
|
data/lib/kwalify/validator.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
6
|
|
|
@@ -37,16 +37,23 @@ module Kwalify
|
|
|
37
37
|
## end
|
|
38
38
|
## end
|
|
39
39
|
##
|
|
40
|
+
|
|
41
|
+
def self.logger
|
|
42
|
+
@logger ||= Object.new.tap do |obj|
|
|
43
|
+
def obj.method_missing(*); end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
40
47
|
class Validator
|
|
41
48
|
include Kwalify::ErrorHelper
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
def initialize(hash_or_rule, &block)
|
|
50
|
+
def initialize(hash_or_rule, logger: nil, &block)
|
|
45
51
|
obj = hash_or_rule
|
|
46
52
|
@rule = (obj.nil? || obj.is_a?(Rule)) ? obj : Rule.new(obj)
|
|
53
|
+
@logger = logger || Kwalify.logger
|
|
47
54
|
@block = block
|
|
48
55
|
end
|
|
49
|
-
attr_reader :rule
|
|
56
|
+
attr_reader :rule, :logger
|
|
50
57
|
|
|
51
58
|
|
|
52
59
|
def _inspect
|
|
@@ -55,8 +62,10 @@ module Kwalify
|
|
|
55
62
|
|
|
56
63
|
|
|
57
64
|
def validate(value)
|
|
65
|
+
@logger.debug("Starting validation") if @logger
|
|
58
66
|
path = ''; errors = []; done = {}; uniq_table = nil
|
|
59
67
|
_validate(value, @rule, path, errors, done, uniq_table)
|
|
68
|
+
@logger.debug("Validation complete: #{errors.length} errors") if @logger
|
|
60
69
|
return errors
|
|
61
70
|
end
|
|
62
71
|
|
|
@@ -199,15 +208,6 @@ module Kwalify
|
|
|
199
208
|
public :_validate_unique
|
|
200
209
|
|
|
201
210
|
|
|
202
|
-
def _validate_assert(value, rule, path, errors)
|
|
203
|
-
assert_error("rule=#{rule._inspect}") unless rule.assert_proc
|
|
204
|
-
unless rule.assert_proc.call(value)
|
|
205
|
-
#* key=:assert_failed msg="assertion expression failed (%s)."
|
|
206
|
-
errors << validate_error(:assert_failed, rule, path, value, [rule.assert])
|
|
207
|
-
end
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
|
|
211
211
|
def _validate_enum(value, rule, path, errors)
|
|
212
212
|
assert_error("rule=#{rule._inspect}") unless rule.enum
|
|
213
213
|
unless rule.enum.include?(value)
|
|
@@ -277,6 +277,31 @@ module Kwalify
|
|
|
277
277
|
end
|
|
278
278
|
|
|
279
279
|
|
|
280
|
+
# DUP def
|
|
281
|
+
# def _validate_assert(value, rule, path, errors)
|
|
282
|
+
# assert_error("rule=#{rule._inspect}") unless rule.assert_proc
|
|
283
|
+
# unless rule.assert_proc.call(value)
|
|
284
|
+
# #* key=:assert_failed msg="assertion expression failed (%s)."
|
|
285
|
+
# errors << validate_error(:assert_failed, rule, path, value, [rule.assert])
|
|
286
|
+
# end
|
|
287
|
+
# end
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _validate_assert(value, rule, path, errors)
|
|
291
|
+
assert_error("rule=#{rule._inspect}") unless rule.assert
|
|
292
|
+
local_val = value
|
|
293
|
+
begin
|
|
294
|
+
result = eval(rule.assert, binding)
|
|
295
|
+
unless result
|
|
296
|
+
#* key=:assert_failed msg="assertion expression failed (%s)."
|
|
297
|
+
errors << validate_error(:assert_failed, rule, path,
|
|
298
|
+
value, [rule.assert])
|
|
299
|
+
end
|
|
300
|
+
rescue StandardError => ex
|
|
301
|
+
errors << validate_error(:assert_failed, rule, path, value, [rule.assert])
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
|
|
280
305
|
end
|
|
281
306
|
|
|
282
307
|
end
|
data/lib/kwalify/version.rb
CHANGED
data/lib/kwalify/yaml-parser.rb
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
|
-
# frozen_string_literal: false
|
|
7
6
|
|
|
8
7
|
require 'kwalify/messages'
|
|
9
8
|
require 'kwalify/errors'
|
|
@@ -391,7 +390,7 @@ module Kwalify
|
|
|
391
390
|
case ch = current_char()
|
|
392
391
|
when ?", ?' #"
|
|
393
392
|
endch = ch
|
|
394
|
-
s =
|
|
393
|
+
s = String.new
|
|
395
394
|
while (ch = _getchar()) != nil && ch != endch
|
|
396
395
|
if ch == ?\\
|
|
397
396
|
ch = _getchar()
|
|
@@ -479,7 +478,7 @@ module Kwalify
|
|
|
479
478
|
def parse_alias(column, value)
|
|
480
479
|
assert value =~ /^\*([-\w]+)(( *)(.*))?$/
|
|
481
480
|
label = $1
|
|
482
|
-
|
|
481
|
+
_space = $3
|
|
483
482
|
value2 = $4
|
|
484
483
|
if value2 && !value2.empty? && value2[0] != ?\#
|
|
485
484
|
#* key=:alias_extradata msg="alias cannot take any data."
|
|
@@ -545,20 +544,22 @@ module Kwalify
|
|
|
545
544
|
|
|
546
545
|
|
|
547
546
|
def parse_block_text(column, value)
|
|
548
|
-
assert value =~ /^[
|
|
549
|
-
value =~ /^([
|
|
547
|
+
assert value =~ /^[>|]/
|
|
548
|
+
value =~ /^([>|])([-+]?)(\d+)?\s*(.*)$/
|
|
550
549
|
char = $1
|
|
551
550
|
indicator = $2
|
|
552
|
-
|
|
551
|
+
_sep = char == "|" ? "\n" : " "
|
|
553
552
|
margin = $3 && !$3.empty? ? $3.to_i : nil
|
|
554
553
|
#text = $4.empty? ? '' : $4 + sep
|
|
555
554
|
text = $4
|
|
556
|
-
s =
|
|
557
|
-
empty =
|
|
555
|
+
s = String.new
|
|
556
|
+
empty = String.new
|
|
558
557
|
min_indent = -1
|
|
559
|
-
|
|
558
|
+
|
|
559
|
+
while (line = _getline())
|
|
560
560
|
line =~ /^( *)(.*)/
|
|
561
561
|
indent = $1.length
|
|
562
|
+
|
|
562
563
|
if $2.empty?
|
|
563
564
|
empty << "\n"
|
|
564
565
|
elsif indent < column
|
|
@@ -566,7 +567,7 @@ module Kwalify
|
|
|
566
567
|
else
|
|
567
568
|
min_indent = indent if min_indent < 0 || min_indent > indent
|
|
568
569
|
s << empty << line
|
|
569
|
-
empty =
|
|
570
|
+
empty = String.new
|
|
570
571
|
end
|
|
571
572
|
end
|
|
572
573
|
s << empty if indicator == '+' && char != '>'
|
|
@@ -697,7 +698,7 @@ module Kwalify
|
|
|
697
698
|
year, month, day = $1.to_i, $2.to_i, $3.to_i
|
|
698
699
|
return Date.new(year, month, day)
|
|
699
700
|
when /^(\d\d\d\d)-(\d\d)-(\d\d)(?:[Tt]|[ \t]+)(\d\d?):(\d\d):(\d\d)(\.\d*)?(?:Z|[ \t]*([-+]\d\d?)(?::(\d\d))?)?$/
|
|
700
|
-
year, mon,
|
|
701
|
+
year, mon, _mday, hour, min, sec, usec, tzone_h, tzone_m = $1, $2, $3, $4, $5, $6, $7, $8, $9
|
|
701
702
|
#Time.utc(sec, min, hour, mday, mon, year, wday, yday, isdst, zone)
|
|
702
703
|
#t = Time.utc(sec, min, hour, mday, mon, year, nil, nil, nil, nil)
|
|
703
704
|
#Time.utc(year[, mon[, day[, hour[, min[, sec[, usec]]]]]])
|
|
@@ -705,8 +706,10 @@ module Kwalify
|
|
|
705
706
|
if tzone_h
|
|
706
707
|
diff_sec = tzone_h.to_i * 60 * 60
|
|
707
708
|
if tzone_m
|
|
708
|
-
if diff_sec > 0
|
|
709
|
-
|
|
709
|
+
if diff_sec > 0
|
|
710
|
+
diff_sec += tzone_m.to_i * 60
|
|
711
|
+
else
|
|
712
|
+
diff_sec -= tzone_m.to_i * 60
|
|
710
713
|
end
|
|
711
714
|
end
|
|
712
715
|
p diff_sec
|
data/lib/kwalify.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2006 kuwata-lab.com all rights reserved.
|
|
5
5
|
###
|
|
6
6
|
|
|
@@ -15,9 +15,34 @@ require 'kwalify/yaml-parser'
|
|
|
15
15
|
#require 'kwalify/parser/base'
|
|
16
16
|
#require 'kwalify/parser/yaml'
|
|
17
17
|
|
|
18
|
+
# Ruby 4.0 Compatibility Patch: StringScanner#peep was renamed to #peek in Ruby 4.0.
|
|
19
|
+
require 'strscan'
|
|
20
|
+
class StringScanner
|
|
21
|
+
alias_method :peep, :peek unless method_defined?(:peep)
|
|
22
|
+
end
|
|
18
23
|
|
|
19
24
|
module Kwalify
|
|
20
25
|
|
|
26
|
+
require 'logger'
|
|
27
|
+
|
|
28
|
+
# Logger singleton - can be configured per application
|
|
29
|
+
@@logger = Logger.new($stderr, level: Logger::WARN)
|
|
30
|
+
@@logger.formatter = proc do |severity, datetime, progname, msg|
|
|
31
|
+
"#{severity}: #{msg}\n"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.logger
|
|
35
|
+
@@logger
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.logger=(logger)
|
|
39
|
+
@@logger = logger
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.log(level, message)
|
|
43
|
+
@@logger.send(level, message)
|
|
44
|
+
end
|
|
45
|
+
|
|
21
46
|
module Util
|
|
22
47
|
|
|
23
48
|
autoload :HashLike, 'kwalify/util/hashlike'
|
data/test/Rookbook.yaml
CHANGED
|
File without changes
|
|
File without changes
|
data/test/test-action.rb
CHANGED
data/test/test-action.yaml
CHANGED
data/test/test-databinding.rb
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
###
|
|
2
2
|
### $Rev$
|
|
3
|
-
### $Release 1.4.0
|
|
3
|
+
### $Release 1.4.0 $
|
|
4
4
|
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
|
5
5
|
###
|
|
6
|
-
# frozen_string_literal: false
|
|
7
6
|
|
|
8
7
|
require File.dirname(__FILE__) + '/test.rb'
|
|
9
8
|
|
|
@@ -25,7 +24,7 @@ class DataBindingTest < Test::Unit::TestCase
|
|
|
25
24
|
TESTDATA1.key?(name) and raise "name '#{name}' is dupilcated."
|
|
26
25
|
TESTDATA1[name] = hash
|
|
27
26
|
#
|
|
28
|
-
s =
|
|
27
|
+
s = String.new
|
|
29
28
|
s << "def test_#{name}\n"
|
|
30
29
|
s << " @name = '#{name}'\n"
|
|
31
30
|
for key, val in hash
|
|
@@ -36,7 +35,6 @@ class DataBindingTest < Test::Unit::TestCase
|
|
|
36
35
|
eval s
|
|
37
36
|
end
|
|
38
37
|
end
|
|
39
|
-
load_yaml_testdata(filename, :lang=>'ruby')
|
|
40
38
|
|
|
41
39
|
|
|
42
40
|
def _test
|
|
@@ -57,7 +55,7 @@ class DataBindingTest < Test::Unit::TestCase
|
|
|
57
55
|
ydoc = parser.parse(@data)
|
|
58
56
|
assert_equal(parser.errors, [])
|
|
59
57
|
## pp
|
|
60
|
-
result =
|
|
58
|
+
result = String.new
|
|
61
59
|
def result.write(arg); self << arg.to_s; end
|
|
62
60
|
PP.pp(ydoc, result)
|
|
63
61
|
## convert object-id to portable number
|