judges 0.0.26 → 0.0.28

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a2c905f28928721f9ed99956f7e9eea5e3b4eabf21a7bffdc324651ea2bf213
4
- data.tar.gz: 4e6cb24b4b4aff6b8bab408d5038a8fee454382d293972ddcf78bab0d2c37b51
3
+ metadata.gz: b3d395cb5c5d1116843533c8a8d8576e346c8426ef1da8524d11c2fb00a65430
4
+ data.tar.gz: 648cb80dae16df946aec75075d3458b4fafaf04531e2cf2fe8bfa225353b4e3f
5
5
  SHA512:
6
- metadata.gz: ad604005840c419cc0021cc0d55a64c010ca6ab64c73f5e30cfa72c9e43190382b5bf6783794389eb3f21cc6fd24d3b60c3c3f803f29f71480a0eb73cfa7995f
7
- data.tar.gz: 4888625231190957df7b5c189215b49cb9ed1ec01c40edf795140a4d6896d7a9b6d7d24e4dd02bf931281ee25ec2db87590be3275d97aa2980cfd3eb7b44a1cf
6
+ metadata.gz: 99f24ae2112c3e60ac802a82f7ba0f5b8c2f582fcbdf9fc8d92d89c2c8f52476c4566b67bd4996b06c0c3aa550573fc79ecfec534493a0a7f3c71fe9c247cc4d
7
+ data.tar.gz: 53d1db75b34ae7d2536bd9ef5787d5fa52d5cd16debb199702c15381a8d20de0a8a06359b3482b2ba9d48990cc4ceba4d73d93f8a9b6969b22dc7122b0c18ef3
data/Gemfile.lock CHANGED
@@ -3,7 +3,7 @@ PATH
3
3
  specs:
4
4
  judges (0.0.0)
5
5
  backtrace (~> 0.3)
6
- factbase (~> 0.0.23)
6
+ factbase (~> 0.0.28)
7
7
  gli (~> 2.21)
8
8
  loog (~> 0.2)
9
9
  nokogiri (~> 1.10)
@@ -74,7 +74,7 @@ GEM
74
74
  docile (1.4.0)
75
75
  drb (2.2.1)
76
76
  erubi (1.12.0)
77
- factbase (0.0.23)
77
+ factbase (0.0.28)
78
78
  json (~> 2.7)
79
79
  loog (~> 0.2)
80
80
  nokogiri (~> 1.10)
data/bin/judges CHANGED
@@ -32,7 +32,7 @@ Encoding.default_internal = Encoding::UTF_8
32
32
  class App
33
33
  extend GLI::App
34
34
 
35
- ver = '0.0.26'
35
+ ver = '0.0.28'
36
36
 
37
37
  loog = Loog::REGULAR
38
38
 
@@ -71,8 +71,16 @@ class App
71
71
  end
72
72
  end
73
73
 
74
+ desc 'Evaluate a single Ruby expression on the factbase'
75
+ command :eval do |c|
76
+ c.action do |global, options, args|
77
+ require_relative '../lib/judges/commands/eval'
78
+ Judges::Eval.new(loog).run(options, args)
79
+ end
80
+ end
81
+
74
82
  desc 'Join two factbases'
75
- command :print do |c|
83
+ command :join do |c|
76
84
  c.action do |global, options, args|
77
85
  require_relative '../lib/judges/commands/join'
78
86
  Judges::Join.new(loog).run(options, args)
@@ -81,8 +89,10 @@ class App
81
89
 
82
90
  desc 'Remove the facts that are too old'
83
91
  command :trim do |c|
92
+ c.desc 'Only the facts that match the expression are deleted'
93
+ c.flag([:query])
84
94
  c.desc 'Remove facts that are older than X days'
85
- c.flag([:days], type: Integer, default_value: 90)
95
+ c.flag([:days], type: Integer)
86
96
  c.action do |global, options, args|
87
97
  require_relative '../lib/judges/commands/trim'
88
98
  Judges::Trim.new(loog).run(options, args)
@@ -95,6 +105,8 @@ class App
95
105
  c.flag([:format], default_value: 'yaml')
96
106
  c.desc 'Generate output name of the file automatically'
97
107
  c.switch([:auto], default_value: false)
108
+ c.desc 'Only the facts that match the expression are printed'
109
+ c.flag([:query], default_value: '()')
98
110
  c.action do |global, options, args|
99
111
  require_relative '../lib/judges/commands/print'
100
112
  Judges::Print.new(loog).run(options, args)
@@ -3,14 +3,9 @@ Feature: Inspect
3
3
 
4
4
  Scenario: Simple inspect of a small factbase
5
5
  Given I make a temp directory
6
- Then I have a "simple/simple_judge.rb" file with content:
7
- """
8
- return if $fb.size > 2
9
- n = $fb.insert
10
- n.kind = 'yes!'
11
- """
6
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
12
7
  Then I run bin/judges with "update . simple.fb"
13
8
  Then I run bin/judges with "inspect simple.fb"
14
- Then Stdout contains "Facts: 3"
9
+ Then Stdout contains "Facts: 1"
15
10
  And Exit code is zero
16
11
 
@@ -0,0 +1,12 @@
1
+ Feature: Join
2
+ I want to join two factbases
3
+
4
+ Scenario: Simple join of two small factbases
5
+ Given I make a temp directory
6
+ Then I run bin/judges with "--verbose eval first.fb '$fb.insert.foo = 42'"
7
+ Then I run bin/judges with "--verbose eval second.fb '$fb.insert.foo = 42'"
8
+ Then I run bin/judges with "update . first.fb"
9
+ Then I run bin/judges with "update . second.fb"
10
+ Then I run bin/judges with "join first.fb second.fb"
11
+ Then Stdout contains "joined"
12
+ And Exit code is zero
@@ -3,12 +3,7 @@ Feature: Print
3
3
 
4
4
  Scenario: Simple print of a small factbase, to YAML
5
5
  Given I make a temp directory
6
- Then I have a "simple/simple_judge.rb" file with content:
7
- """
8
- return if $fb.size > 2
9
- n = $fb.insert
10
- n.kind = 'yes!'
11
- """
6
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
12
7
  Then I run bin/judges with "update . simple.fb"
13
8
  Then I run bin/judges with "print --format=yaml simple.fb simple.yml"
14
9
  Then Stdout contains "printed"
@@ -16,12 +11,7 @@ Feature: Print
16
11
 
17
12
  Scenario: Simple print of a small factbase, to JSON
18
13
  Given I make a temp directory
19
- Then I have a "simple/simple_judge.rb" file with content:
20
- """
21
- return if $fb.size > 2
22
- n = $fb.insert
23
- n.kind = 'yes!'
24
- """
14
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
25
15
  Then I run bin/judges with "update . simple.fb"
26
16
  Then I run bin/judges with "print --format=json simple.fb simple.json"
27
17
  Then Stdout contains "printed"
@@ -29,13 +19,17 @@ Feature: Print
29
19
 
30
20
  Scenario: Simple print of a small factbase, to XML
31
21
  Given I make a temp directory
32
- Then I have a "simple/simple_judge.rb" file with content:
33
- """
34
- return if $fb.size > 2
35
- n = $fb.insert
36
- n.kind = 'yes!'
37
- """
22
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
38
23
  Then I run bin/judges with "update . simple.fb"
39
24
  Then I run bin/judges with "print --format=xml --auto simple.fb"
40
25
  Then Stdout contains "printed"
41
26
  And Exit code is zero
27
+
28
+ Scenario: Simple print of a small factbase, to XML, with a query
29
+ Given I make a temp directory
30
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
31
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 43'"
32
+ Then I run bin/judges with "update . simple.fb"
33
+ Then I run bin/judges with "print '--query=(eq foo 43)' --auto simple.fb"
34
+ Then Stdout contains "printed"
35
+ And Exit code is zero
@@ -3,12 +3,15 @@ Feature: Trim
3
3
 
4
4
  Scenario: Simple trimming of a factbase
5
5
  Given I make a temp directory
6
- Then I have a "simple/simple_judge.rb" file with content:
7
- """
8
- return if $fb.size > 2
9
- $fb.insert.time = Time.now - 100 * 60 * 60 * 24
10
- """
6
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.time = Time.now - 100 * 60 * 60 * 24'"
11
7
  Then I run bin/judges with "--verbose update . simple.fb"
12
8
  Given I run bin/judges with "trim --days 5 simple.fb"
13
- Then Stdout contains "3 fact(s) deleted"
9
+ Then Stdout contains "1 fact(s) deleted"
10
+ And Exit code is zero
11
+
12
+ Scenario: Simple trimming of a factbase, with a query
13
+ Given I make a temp directory
14
+ Then I run bin/judges with "--verbose eval simple.fb '$fb.insert.foo = 42'"
15
+ Given I run bin/judges with "trim --query '(eq foo 42)' simple.fb"
16
+ Then Stdout contains "1 fact(s) deleted"
14
17
  And Exit code is zero
@@ -12,7 +12,7 @@ Feature: Update
12
12
  Then Stdout contains "foo → "
13
13
  Then Stdout contains "bar → "
14
14
  Then Stdout contains "1 judge(s) processed"
15
- Then Stdout contains "Update finished in 3 cycles"
15
+ Then Stdout contains "Update finished: 3 cycles"
16
16
  And Exit code is zero
17
17
 
18
18
  Scenario: Simple run of a few judges, with a lib
@@ -28,5 +28,5 @@ Feature: Update
28
28
  """
29
29
  Then I run bin/judges with "update --lib mylib --max-cycles 1 mypacks simple.fb"
30
30
  Then Stdout contains "1 judge(s) processed"
31
- Then Stdout contains "Update finished in 1 cycles"
31
+ Then Stdout contains "Update finished: 1 cycles"
32
32
  And Exit code is zero
data/judges.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
27
27
  s.required_ruby_version = '>=3.2'
28
28
  s.name = 'judges'
29
- s.version = '0.0.26'
29
+ s.version = '0.0.28'
30
30
  s.license = 'MIT'
31
31
  s.summary = 'Command-Line Tool for a Factbase'
32
32
  s.description = '
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
42
42
  s.rdoc_options = ['--charset=UTF-8']
43
43
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
44
44
  s.add_runtime_dependency 'backtrace', '~> 0.3'
45
- s.add_runtime_dependency 'factbase', '~>0.0.23'
45
+ s.add_runtime_dependency 'factbase', '~>0.0.28'
46
46
  s.add_runtime_dependency 'gli', '~>2.21'
47
47
  s.add_runtime_dependency 'loog', '~>0.2'
48
48
  s.add_runtime_dependency 'nokogiri', '~> 1.10'
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'backtrace'
24
+ require 'factbase/looged'
25
+ require_relative '../../judges'
26
+ require_relative '../../judges/to_rel'
27
+ require_relative '../../judges/packs'
28
+ require_relative '../../judges/options'
29
+ require_relative '../../judges/impex'
30
+
31
+ # Eval.
32
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
33
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
34
+ # License:: MIT
35
+ class Judges::Eval
36
+ def initialize(loog)
37
+ @loog = loog
38
+ end
39
+
40
+ def run(_opts, args)
41
+ raise 'Exactly two arguments required' unless args.size == 2
42
+ impex = Judges::Impex.new(@loog, args[0])
43
+ $fb = impex.import(strict: false)
44
+ $fb = Factbase::Looged.new($fb, @loog)
45
+ expr = args[1]
46
+ # rubocop:disable Security/Eval
47
+ eval(expr)
48
+ # rubocop:enable Security/Eval
49
+ impex.export($fb)
50
+ end
51
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'time'
24
+ require_relative '../../judges'
25
+ require_relative '../../judges/impex'
26
+ require_relative '../../judges/to_rel'
27
+
28
+ # Import.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
31
+ # License:: MIT
32
+ class Judges::Import
33
+ def initialize(loog)
34
+ @loog = loog
35
+ end
36
+
37
+ def run(_opts, args)
38
+ raise 'Exactly two arguments required' unless args.size == 2
39
+ raise "File not found #{args[0].to_rel}" unless File.exist?(args[0])
40
+ start = Time.now
41
+ yaml = YAML.load_file(args[0], permitted_classes: [Time])
42
+ impex = Judges::Impex.new(@loog, args[1])
43
+ fb = impex.import(strict: false)
44
+ fb = Factbase::Looged.new(fb, @loog)
45
+ yaml.each do |i|
46
+ f = fb.insert
47
+ i.each do |p, v|
48
+ f.send("#{p}=", v)
49
+ end
50
+ end
51
+ impex.export(fb)
52
+ @loog.info("Import finished in #{format('%.02f', Time.now - start)}s")
53
+ end
54
+ end
@@ -39,5 +39,6 @@ class Judges::Join
39
39
  fb = master.import
40
40
  slave.import_to(fb)
41
41
  master.export(fb)
42
+ @loog.info('Two factbases joined')
42
43
  end
43
44
  end
@@ -39,6 +39,7 @@ class Judges::Print
39
39
  o = args[1]
40
40
  f = args[0]
41
41
  fb = Judges::Impex.new(@loog, f).import
42
+ fb.query("(not #{opts['query']})").delete! unless opts['query'].nil?
42
43
  if o.nil?
43
44
  raise 'Either provide output file name or use --auto' unless opts[:auto]
44
45
  o = File.join(File.dirname(f), File.basename(f).gsub(/\.[^.]*$/, ''))
@@ -48,11 +49,14 @@ class Judges::Print
48
49
  output =
49
50
  case opts[:format].downcase
50
51
  when 'yaml'
51
- fb.to_yaml
52
+ require 'factbase/to_yaml'
53
+ Factbase::ToYAML.new(fb).yaml
52
54
  when 'json'
53
- fb.to_json
55
+ require 'factbase/to_json'
56
+ Factbase::ToJSON.new(fb).json
54
57
  when 'xml'
55
- fb.to_xml
58
+ require 'factbase/to_xml'
59
+ Factbase::ToXML.new(fb).xml
56
60
  end
57
61
  File.binwrite(o, output)
58
62
  @loog.info("Factbase printed to #{o.to_rel} (#{File.size(o)} bytes)")
@@ -24,6 +24,7 @@ require 'nokogiri'
24
24
  require 'factbase'
25
25
  require 'backtrace'
26
26
  require 'factbase/looged'
27
+ require 'factbase/to_xml'
27
28
  require_relative '../../judges'
28
29
  require_relative '../../judges/to_rel'
29
30
  require_relative '../../judges/packs'
@@ -45,6 +46,7 @@ class Judges::Test
45
46
  errors = []
46
47
  done = 0
47
48
  global = {}
49
+ start = Time.now
48
50
  Judges::Packs.new(dir, opts['lib'], @loog).each_with_index do |p, i|
49
51
  local = {}
50
52
  next unless include?(opts, p.name)
@@ -61,13 +63,14 @@ class Judges::Test
61
63
  end
62
64
  done += 1
63
65
  end
66
+ lapse = "in #{format('%.02f', Time.now - start)}s"
64
67
  if done.zero?
65
68
  raise 'No judges tested :(' unless opts['quiet']
66
- @loog.warn("\n👍 No judges tested")
69
+ @loog.warn("\n👍 No judges tested #{lapse}")
67
70
  elsif errors.empty?
68
- @loog.info("\n👍 All #{done} judge(s) tested successfully")
71
+ @loog.info("\n👍 All #{done} judge(s) tested successfully #{lapse}")
69
72
  else
70
- @loog.info("\n❌ #{done} judge(s) tested, #{errors.size} of them failed")
73
+ @loog.info("\n❌ #{done} judge(s) tested, #{errors.size} of them failed #{lapse}")
71
74
  raise "#{errors.size} tests failed" unless opts['quiet']
72
75
  end
73
76
  end
@@ -95,7 +98,7 @@ class Judges::Test
95
98
  end
96
99
  end
97
100
  pack.run(Factbase::Looged.new(fb, @loog), global, local, Judges::Options.new(yaml['options']))
98
- xml = Nokogiri::XML.parse(fb.to_xml)
101
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
99
102
  yaml['expected'].each do |xp|
100
103
  raise "#{pack.script} doesn't match '#{xp}':\n#{xml}" if xml.xpath(xp).empty?
101
104
  end
@@ -37,13 +37,22 @@ class Judges::Trim
37
37
  raise 'Exactly one argument required' unless args.size == 1
38
38
  impex = Judges::Impex.new(@loog, args[0])
39
39
  fb = impex.import
40
- days = opts['days']
41
- day = Time.now - (days * 60 * 60 * 24)
42
- deleted = fb.query("(lt time #{day.utc.iso8601})").delete!
40
+ query = opts['query']
41
+ if query.nil?
42
+ days = opts['days']
43
+ day = Time.now - (days * 60 * 60 * 24)
44
+ query = "(lt time #{day.utc.iso8601})"
45
+ @loog.info("Deleting facts that are older than #{days} days")
46
+ else
47
+ raise 'Specify either --days or --query' unless opts['days'].nil?
48
+ end
49
+ start = Time.now
50
+ deleted = fb.query(query).delete!
51
+ lapse = "in #{format('%.02f', Time.now - start)}s"
43
52
  if deleted.zero?
44
- @loog.info('No facts deleted')
53
+ @loog.info("No facts deleted #{lapse}")
45
54
  else
46
- @loog.info("🗑 #{deleted} fact(s) deleted, because they were older than #{days} days")
55
+ @loog.info("🗑 #{deleted} fact(s) deleted #{lapse}")
47
56
  impex.export(fb)
48
57
  end
49
58
  end
@@ -48,6 +48,7 @@ class Judges::Update
48
48
  @loog.debug("The following options provided:\n\t#{options.to_s.gsub("\n", "\n\t")}")
49
49
  packs = Judges::Packs.new(dir, opts['lib'], @loog)
50
50
  c = 0
51
+ start = Time.now
51
52
  loop do
52
53
  c += 1
53
54
  diff = cycle(opts, packs, fb, options)
@@ -57,11 +58,13 @@ class Judges::Update
57
58
  @loog.info('Too many cycles already, as set by --max-cycles, breaking')
58
59
  break
59
60
  end
60
- @loog.info("By #{diff} facts the factbase \
61
- #{diff.positive? ? 'increased' : 'decreased'} \
62
- its size at the cycle ##{c}")
61
+ @loog.info(
62
+ "By #{diff} facts the factbase " \
63
+ "#{diff.positive? ? 'increased' : 'decreased'} " \
64
+ "its size at the cycle ##{c}"
65
+ )
63
66
  end
64
- @loog.info("Update finished in #{c} cycles")
67
+ @loog.info("Update finished: #{c} cycles in #{format('%.02f', Time.now - start)}s")
65
68
  end
66
69
 
67
70
  private
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'minitest/autorun'
24
+ require 'loog'
25
+ require 'nokogiri'
26
+ require 'factbase/to_xml'
27
+ require_relative '../../lib/judges'
28
+ require_relative '../../lib/judges/commands/eval'
29
+
30
+ # Test.
31
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
33
+ # License:: MIT
34
+ class TestEval < Minitest::Test
35
+ def test_build_factbase_from_scratch
36
+ Dir.mktmpdir do |d|
37
+ file = File.join(d, 'base.fb')
38
+ Judges::Eval.new(Loog::NULL).run({}, [file, '$fb.insert.foo = 42'])
39
+ fb = Factbase.new
40
+ fb.import(File.binread(file))
41
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
42
+ assert(!xml.xpath('/fb/f[foo="42"]').empty?, xml)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2024 Yegor Bugayenko
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the 'Software'), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'minitest/autorun'
24
+ require 'loog'
25
+ require 'nokogiri'
26
+ require 'factbase/to_xml'
27
+ require_relative '../../lib/judges'
28
+ require_relative '../../lib/judges/commands/import'
29
+
30
+ # Test.
31
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
+ # Copyright:: Copyright (c) 2024 Yegor Bugayenko
33
+ # License:: MIT
34
+ class TestImport < Minitest::Test
35
+ def test_import_from_yaml
36
+ Dir.mktmpdir do |d|
37
+ file = File.join(d, 'base.fb')
38
+ yaml = File.join(d, 'input.yml')
39
+ File.write(
40
+ yaml,
41
+ <<-YAML
42
+ -
43
+ foo: 42
44
+ bar: 2024-03-04T22:22:22Z
45
+ t: Hello, world!
46
+ -
47
+ z: 3.14
48
+ YAML
49
+ )
50
+ Judges::Import.new(Loog::NULL).run({}, [yaml, file])
51
+ fb = Factbase.new
52
+ fb.import(File.binread(file))
53
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
54
+ assert(!xml.xpath('/fb[count(f)=2]').empty?, xml)
55
+ end
56
+ end
57
+ end
@@ -23,6 +23,7 @@
23
23
  require 'minitest/autorun'
24
24
  require 'loog'
25
25
  require 'nokogiri'
26
+ require 'factbase/to_xml'
26
27
  require_relative '../../lib/judges'
27
28
  require_relative '../../lib/judges/commands/join'
28
29
 
@@ -41,12 +42,12 @@ class TestJoin < Minitest::Test
41
42
  fb2 = Factbase.new
42
43
  fb2.insert.foo_bar = 42
43
44
  File.binwrite(slave, fb2.export)
44
- Judges::Join.new(Loog::VERBOSE).run({}, [master, slave])
45
+ Judges::Join.new(Loog::NULL).run({}, [master, slave])
45
46
  fb = Factbase.new
46
47
  fb.import(File.binread(master))
47
- xml = Nokogiri::XML.parse(fb.to_xml)
48
- assert(!xml.xpath('/fb/f[zz="5"]').empty?, fb.to_xml)
49
- assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?, fb.to_xml)
48
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
49
+ assert(!xml.xpath('/fb/f[zz="5"]').empty?, xml)
50
+ assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?, xml)
50
51
  end
51
52
  end
52
53
  end
@@ -38,7 +38,7 @@ class TestPrint < Minitest::Test
38
38
  fb = Factbase.new
39
39
  fb.insert
40
40
  File.binwrite(f, fb.export)
41
- Judges::Print.new(Loog::VERBOSE).run({ format: 'yaml', auto: true }, [f])
41
+ Judges::Print.new(Loog::NULL).run({ format: 'yaml', auto: true }, [f])
42
42
  y = File.join(d, 'base.yaml')
43
43
  assert(File.exist?(y))
44
44
  assert_equal(1, YAML.load_file(y)['facts'].size)
@@ -39,7 +39,7 @@ class TestTrim < Minitest::Test
39
39
  before.insert.time = Time.now + 1
40
40
  before.insert.time = Time.now - (100 * 24 * 60 * 60)
41
41
  File.binwrite(file, before.export)
42
- Judges::Trim.new(Loog::VERBOSE).run({ 'days' => 10 }, [file])
42
+ Judges::Trim.new(Loog::NULL).run({ 'days' => 10 }, [file])
43
43
  after = Factbase.new
44
44
  after.import(File.binread(file))
45
45
  assert_equal(1, after.size)
@@ -23,6 +23,7 @@
23
23
  require 'minitest/autorun'
24
24
  require 'loog'
25
25
  require 'nokogiri'
26
+ require 'factbase/to_xml'
26
27
  require_relative '../../lib/judges'
27
28
  require_relative '../../lib/judges/commands/update'
28
29
 
@@ -35,11 +36,11 @@ class TestUpdate < Minitest::Test
35
36
  Dir.mktmpdir do |d|
36
37
  File.write(File.join(d, 'foo.rb'), 'return if $fb.size > 2; $fb.insert.zzz = $options.foo_bar + 1')
37
38
  file = File.join(d, 'base.fb')
38
- Judges::Update.new(Loog::VERBOSE).run({ 'option' => ['foo_bar=42'] }, [d, file])
39
+ Judges::Update.new(Loog::NULL).run({ 'option' => ['foo_bar=42'] }, [d, file])
39
40
  fb = Factbase.new
40
41
  fb.import(File.binread(file))
41
- xml = Nokogiri::XML.parse(fb.to_xml)
42
- assert(!xml.xpath('/fb/f[zzz="43"]').empty?)
42
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
43
+ assert(!xml.xpath('/fb/f[zzz="43"]').empty?, xml)
43
44
  end
44
45
  end
45
46
 
@@ -50,12 +51,12 @@ class TestUpdate < Minitest::Test
50
51
  fb.insert.foo_bar = 42
51
52
  File.binwrite(file, fb.export)
52
53
  File.write(File.join(d, 'foo.rb'), '$fb.insert.tt = 4')
53
- Judges::Update.new(Loog::VERBOSE).run({ 'max-cycles' => 1 }, [d, file])
54
+ Judges::Update.new(Loog::NULL).run({ 'max-cycles' => 1 }, [d, file])
54
55
  fb = Factbase.new
55
56
  fb.import(File.binread(file))
56
- xml = Nokogiri::XML.parse(fb.to_xml)
57
- assert(!xml.xpath('/fb/f[tt="4"]').empty?)
58
- assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?)
57
+ xml = Nokogiri::XML.parse(Factbase::ToXML.new(fb).xml)
58
+ assert(!xml.xpath('/fb/f[tt="4"]').empty?, xml)
59
+ assert(!xml.xpath('/fb/f[foo_bar="42"]').empty?, xml)
59
60
  end
60
61
  end
61
62
 
@@ -63,7 +64,7 @@ class TestUpdate < Minitest::Test
63
64
  Dir.mktmpdir do |d|
64
65
  File.write(File.join(d, 'foo.rb'), 'this is a broken Ruby script')
65
66
  file = File.join(d, 'base.fb')
66
- Judges::Update.new(Loog::VERBOSE).run({ 'quiet' => true }, [d, file])
67
+ Judges::Update.new(Loog::NULL).run({ 'quiet' => true }, [d, file])
67
68
  end
68
69
  end
69
70
  end
@@ -80,13 +80,13 @@ class TestIfAbsent < Minitest::Test
80
80
  def test_complex_injects
81
81
  fb = Factbase.new
82
82
  f1 = fb.insert
83
- f1.foo = 'hello, "dude"!'
83
+ f1.foo = 'hello, dude!'
84
84
  f1.abc = 42
85
85
  t = Time.now
86
86
  f1.z = t
87
87
  f1.bar = 3.14
88
88
  n = if_absent(fb) do |f|
89
- f.foo = 'hello, "dude"!'
89
+ f.foo = "hello, \\\"dude\\\" \\' \\' ( \n\n ) (!"
90
90
  f.abc = 42
91
91
  f.z = t + 1
92
92
  f.bar = 3.15
data/test/test_impex.rb CHANGED
@@ -34,7 +34,7 @@ class TestImpex < Minitest::Test
34
34
  def test_basic
35
35
  Dir.mktmpdir do |d|
36
36
  f = File.join(d, 'foo.rb')
37
- impex = Judges::Impex.new(Loog::VERBOSE, f)
37
+ impex = Judges::Impex.new(Loog::NULL, f)
38
38
  impex.import(strict: false)
39
39
  impex.export(Factbase.new)
40
40
  end
@@ -43,7 +43,7 @@ class TestImpex < Minitest::Test
43
43
  def test_strict_import
44
44
  Dir.mktmpdir do |d|
45
45
  f = File.join(d, 'x.rb')
46
- impex = Judges::Impex.new(Loog::VERBOSE, f)
46
+ impex = Judges::Impex.new(Loog::NULL, f)
47
47
  impex.import(strict: false)
48
48
  impex.export(Factbase.new)
49
49
  impex.import
data/test/test_pack.rb CHANGED
@@ -35,7 +35,7 @@ class TestPack < Minitest::Test
35
35
  def test_basic_run
36
36
  Dir.mktmpdir do |d|
37
37
  File.write(File.join(d, 'foo.rb'), '$fb.insert')
38
- pack = Judges::Pack.new(d, nil, Loog::VERBOSE)
38
+ pack = Judges::Pack.new(d, nil, Loog::NULL)
39
39
  fb = Factbase.new
40
40
  pack.run(fb, {}, {}, {})
41
41
  assert_equal(1, fb.size)
@@ -45,7 +45,7 @@ class TestPack < Minitest::Test
45
45
  def test_run_isolated
46
46
  Dir.mktmpdir do |d|
47
47
  File.write(File.join(d, 'bar.rb'), '$fb.insert')
48
- pack = Judges::Pack.new(d, nil, Loog::VERBOSE)
48
+ pack = Judges::Pack.new(d, nil, Loog::NULL)
49
49
  fb1 = Factbase.new
50
50
  pack.run(fb1, {}, {}, {})
51
51
  assert_equal(1, fb1.size)
@@ -58,7 +58,7 @@ class TestPack < Minitest::Test
58
58
  def test_with_supplemenary_functions
59
59
  Dir.mktmpdir do |d|
60
60
  File.write(File.join(d, 'x.rb'), 'once($fb).insert')
61
- pack = Judges::Pack.new(d, nil, Loog::VERBOSE)
61
+ pack = Judges::Pack.new(d, nil, Loog::NULL)
62
62
  pack.run(Factbase.new, {}, {}, {})
63
63
  end
64
64
  end
@@ -101,7 +101,7 @@ class TestPack < Minitest::Test
101
101
  lib = File.join(d, 'lib')
102
102
  FileUtils.mkdir_p(lib)
103
103
  File.write(File.join(lib, 'y.rb'), '$foo = 42')
104
- pack = Judges::Pack.new(dir, lib, Loog::VERBOSE)
104
+ pack = Judges::Pack.new(dir, lib, Loog::NULL)
105
105
  fb = Factbase.new
106
106
  pack.run(fb, {}, {}, {})
107
107
  assert_equal(42, fb.query('()').each.to_a.first.bar)
data/test/test_packs.rb CHANGED
@@ -36,7 +36,7 @@ class TestPacks < Minitest::Test
36
36
  File.write(File.join(d, 'foo.rb'), 'hey')
37
37
  File.write(File.join(d, 'something.yml'), "---\nfoo: 42")
38
38
  found = 0
39
- Judges::Packs.new(d, nil, Loog::VERBOSE).each do |p|
39
+ Judges::Packs.new(d, nil, Loog::NULL).each do |p|
40
40
  assert_equal('foo.rb', p.script)
41
41
  found += 1
42
42
  assert_equal('something.yml', File.basename(p.tests.first))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: judges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.26
4
+ version: 0.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-17 00:00:00.000000000 Z
11
+ date: 2024-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.23
33
+ version: 0.0.28
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.23
40
+ version: 0.0.28
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: gli
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +114,7 @@ files:
114
114
  - bin/judges
115
115
  - features/gem_package.feature
116
116
  - features/inspect.feature
117
+ - features/join.feature
117
118
  - features/misc.feature
118
119
  - features/print.feature
119
120
  - features/step_definitions/steps.rb
@@ -127,6 +128,8 @@ files:
127
128
  - fixtures/reward_for_good_bug/simple-reward.yml
128
129
  - judges.gemspec
129
130
  - lib/judges.rb
131
+ - lib/judges/commands/eval.rb
132
+ - lib/judges/commands/import.rb
130
133
  - lib/judges/commands/inspect.rb
131
134
  - lib/judges/commands/join.rb
132
135
  - lib/judges/commands/print.rb
@@ -141,6 +144,8 @@ files:
141
144
  - lib/judges/packs.rb
142
145
  - lib/judges/to_rel.rb
143
146
  - renovate.json
147
+ - test/commands/test_eval.rb
148
+ - test/commands/test_import.rb
144
149
  - test/commands/test_inspect.rb
145
150
  - test/commands/test_join.rb
146
151
  - test/commands/test_print.rb