speculate_about 0.5.2 → 1.0.1

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: d7347969c0f7e0d357050ba84401e3c069366c052b028a3e123c94ee355b9829
4
- data.tar.gz: 277902ff252cfade683c395485015f03700028839dcd986d965dbfc5f6c1a425
3
+ metadata.gz: 9b33715812d0321ea53813b6a821e91c355f235c088a4ac6410f338e681d4a2b
4
+ data.tar.gz: 2e8cc718817fba9f4aa263f65420de5aa4f70625f7e1c8b7c0b43b352ac69e7e
5
5
  SHA512:
6
- metadata.gz: 62daedfb2b2e00c7d9d1cac4fbe5c5fefcbfbb6dbfd49fed4cbdb4c224c37c54f80edd53aeb23215ca2192e0957a323dd7669c190917443b412e73976b8abbeb
7
- data.tar.gz: 2a8626af0e4d46e63b514416d0341aaa61aa504f28ccf777827c701230ed1dddd08aa6b63314a066820799e05bb490b221f3481002eff144853c79732ce96464
6
+ metadata.gz: 42b7a04f119f34a49bd694509807681f7ebd8d4348556e1a121e648c391447a8f6f28cde03fc7615b93b07e077b6c5d268ef590c437e9c233d18a639b76db622
7
+ data.tar.gz: a5980e1500f466cb7072d55deb5b56fa5b790dc24810e902e28f3e105c053e8d0ab447403ef367ee51a9318151a06e80ede034e4b5f1a21ca62cf39c32c78d3c
@@ -2,7 +2,7 @@ class Speculations::Parser::Context::Include
2
2
 
3
3
  attr_reader :lnb, :parent
4
4
 
5
- def add_line line
5
+ def add_line line
6
6
  lines << line
7
7
  self
8
8
  end
@@ -45,7 +45,7 @@ module Speculations
45
45
 
46
46
  def map_lines(*lines, indent: 0)
47
47
  prefix = " " * (tree_level + indent).succ
48
- lines.flatten.map{ |line| "#{prefix}#{line.strip}" }
48
+ lines.flatten.map{ |line| "#{prefix}#{line.strip}".rstrip }
49
49
  end
50
50
 
51
51
  def to_code
@@ -11,17 +11,17 @@ module Speculations
11
11
  new_parent = node.parent_of_level(level.pred)
12
12
  node = new_parent.new_context(title: match[2], lnb: lnb, level: level)
13
13
  [:out, node]
14
- when match = State.maybe_example(line)
15
- [:candidate, node, match[:title]]
16
14
  when match = State.maybe_include(line)
17
15
  [:candidate, node, :inc]
16
+ when match = State.maybe_example(line)
17
+ [:candidate, node, match[:title]]
18
18
  when match = State.ruby_code_block(line)
19
19
  if ctxt == :inc
20
20
  node = node.new_include(lnb: lnb)
21
21
  else
22
22
  node = node.new_example(title: ctxt, lnb: lnb)
23
23
  end
24
- [:in, node]
24
+ [:in, node, (ctxt == :inc ? :includes : :out)]
25
25
  else
26
26
  [:out, node]
27
27
  end
@@ -0,0 +1,16 @@
1
+ module Speculations
2
+ class Parser
3
+ module State
4
+ module ContextMaker
5
+ private
6
+
7
+ def make_new_context(lnb:, match:, node:)
8
+ level = match[:level].size
9
+ new_parent = node.parent_of_level(level.pred)
10
+ node = new_parent.new_context(title: match[:title], lnb: lnb, level: level)
11
+ [:out, node]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -6,9 +6,9 @@ module Speculations
6
6
  def parse line, _lnb, node, ctxt
7
7
  case
8
8
  when State.eoblock_match(line)
9
- [:out, node.parent]
9
+ [ctxt, node.parent]
10
10
  else
11
- [:in, node.add_line(line)]
11
+ [:in, node.add_line(line), ctxt]
12
12
  end
13
13
  end
14
14
  end
@@ -0,0 +1,24 @@
1
+ require_relative 'context_maker'
2
+ module Speculations
3
+ class Parser
4
+ module State
5
+ module Includes extend self
6
+ include ContextMaker
7
+
8
+ def parse line, lnb, node, _ctxt
9
+ case
10
+ when match = State.context_match(line)
11
+ make_new_context(lnb: lnb, node: node, match: match)
12
+ when match = State.maybe_include(line)
13
+ [:candidate, node, :inc]
14
+ when match = State.maybe_example(line)
15
+ [:candidate, node, match[:title]]
16
+ else
17
+ [:includes, node]
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,7 +1,9 @@
1
+ require_relative 'context_maker'
1
2
  module Speculations
2
3
  class Parser
3
4
  module State
4
5
  module Out extend self
6
+ include ContextMaker
5
7
 
6
8
  def parse line, lnb, node, _ctxt
7
9
  case
@@ -16,15 +18,6 @@ module Speculations
16
18
  end
17
19
  end
18
20
 
19
- private
20
-
21
- def make_new_context(lnb:, match:, node:)
22
- level = match[:level].size
23
- new_parent = node.parent_of_level(level.pred)
24
- node = new_parent.new_context(title: match[:title], lnb: lnb, level: level)
25
- [:out, node]
26
- end
27
-
28
21
  end
29
22
  end
30
23
  end
@@ -3,10 +3,10 @@ module Speculations::Parser::State::Triggers
3
3
  BLANK_RGX = %r{\A\s*\z}
4
4
  CONTEXT_RGX = %r[\A\s{0,3}(?<level>\#{1,7})\s+Context:?\s+(?<title>.*)]
5
5
  EOBLOCK_RGX = %r[\A\s{0,3}```\s*\z]
6
- GIVEN_RGX = %r[\A\s{0,3}(?:Given|When)\b]
6
+ GIVEN_RGX = %r[\A\s{0,3}(?:Given|When|And)\b]
7
7
  EXAMPLE_RGX = %r[\A\s{0,3}Example:?\s+(<?title>.*)]
8
8
  RUBY_RGX = %r[\A\s{0,3}```ruby]
9
- THEN_RGX = %r[\A\s{0,3}(?:Then|But|And|Also)\b\s*(?<title>.*)]
9
+ THEN_RGX = %r[\A\s{0,3}(?:Then|But|And|Also|Or)\b\s*(?<title>.*)]
10
10
 
11
11
  def blank_line line
12
12
  BLANK_RGX.match(line)
@@ -1,6 +1,7 @@
1
1
  module Speculations::Parser::State extend self
2
2
  require_relative './state/candidate'
3
3
  require_relative './state/in'
4
+ require_relative './state/includes'
4
5
  require_relative './state/out'
5
6
  require_relative './state/triggers'
6
7
 
@@ -8,6 +8,7 @@ module Speculations
8
8
  @__parsers__ ||= {
9
9
  candidate: State::Candidate,
10
10
  in: State::In,
11
+ includes: State::Includes,
11
12
  out: State::Out
12
13
  }
13
14
  end
@@ -31,7 +32,8 @@ module Speculations
31
32
  root = node = Context.new(filename: @filename)
32
33
  ctxt = nil
33
34
  @input.each_with_index do |line, lnb|
34
- @state, node, ctxt = self.class.parsers.fetch(@state).parse(line, lnb.succ, node, ctxt)
35
+ parser = self.class.parsers.fetch(@state)
36
+ @state, node, ctxt = parser.parse(line, lnb.succ, node, ctxt)
35
37
  end
36
38
  root
37
39
  end
@@ -1,3 +1,3 @@
1
1
  module Speculations
2
- VERSION = "0.5.2"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/speculations.rb CHANGED
@@ -15,7 +15,7 @@ module Speculations extend self
15
15
  raise ArgumentError, "#{infile} not found" unless File.readable? infile
16
16
  outfile ||= _speculation_path(infile)
17
17
  if _out_of_date?(outfile, infile)
18
- ast = Speculations::Parser.new.parse_from_file(infile)
18
+ ast = p Speculations::Parser.new.parse_from_file(infile)
19
19
  code = _decorated_ast_code ast, infile
20
20
  File.write(outfile, code.join("\n"))
21
21
  end
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: speculate_about
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-02 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '13.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '13.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '3.10'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '3.10'
11
+ date: 2022-02-06 00:00:00.000000000 Z
12
+ dependencies: []
41
13
  description: Allows Markdown or other text files to be used as literal specs, à la
42
14
  Elixr doctest, but from any file.
43
15
  email: robert.dober@gmail.com
@@ -56,7 +28,9 @@ files:
56
28
  - lib/speculations/parser/context/include.rb
57
29
  - lib/speculations/parser/state.rb
58
30
  - lib/speculations/parser/state/candidate.rb
31
+ - lib/speculations/parser/state/context_maker.rb
59
32
  - lib/speculations/parser/state/in.rb
33
+ - lib/speculations/parser/state/includes.rb
60
34
  - lib/speculations/parser/state/out.rb
61
35
  - lib/speculations/parser/state/triggers.rb
62
36
  - lib/speculations/version.rb
@@ -72,14 +46,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
46
  requirements:
73
47
  - - ">="
74
48
  - !ruby/object:Gem::Version
75
- version: 2.7.0
49
+ version: 3.1.0
76
50
  required_rubygems_version: !ruby/object:Gem::Requirement
77
51
  requirements:
78
52
  - - ">="
79
53
  - !ruby/object:Gem::Version
80
54
  version: '0'
81
55
  requirements: []
82
- rubygems_version: 3.2.3
56
+ rubygems_version: 3.3.3
83
57
  signing_key:
84
58
  specification_version: 4
85
59
  summary: Extract RSpecs from Markdown