speculate_about 0.6.0 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddf1c9fa5d8bb2d18f142e4fcc18aad6ca71d0694829b7bd0f7d291b0e3c97d2
4
- data.tar.gz: '06689091cee69a4f3df817efc5ba8be2ed754d85fe98ed5cb9d27c28b58be506'
3
+ metadata.gz: 418165840fa00627dbf34678bfc9eec5133565b4d9eaf697a8a748242b8fe759
4
+ data.tar.gz: 4a1cbab184f1b6861ef38112750e4783b257a19d61dbf19ae4a4385aed47fcde
5
5
  SHA512:
6
- metadata.gz: c382d674930d2e61a8494de4331a4b4f3afef2cc6b77193fbb09af4610f3c8944f65edb09ff5ff550dfea5f56114692c1d93f37f04a88d30e91d014deba7b7f0
7
- data.tar.gz: b29b76a402e49063919eeded1724c7ea2d87c557fba1ea6f4e526d9e9a322da746669d460d3effbc4146090f57559a4c77523464e9cc44f324172c0363e783f1
6
+ metadata.gz: 251c5d8c14c559797d1246aac8e1ba9cc269be9e68cbe496808768989ffaaf99d0fa2c60d4571ead528cecb7104a7ecee4335119bd28244a9f9678e906855bc1
7
+ data.tar.gz: 070a7aaa0842f8627876be6516bed4a9cf3615d738bda0d58f0414df4f6b72d5b49302e607960d33dcf524589a4304e3fa31ce30eef5968dfce94e496301e53c
@@ -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.6.0"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: speculate_about
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-21 00:00:00.000000000 Z
11
+ date: 2022-02-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Allows Markdown or other text files to be used as literal specs, à la
14
14
  Elixr doctest, but from any file.
@@ -28,7 +28,9 @@ files:
28
28
  - lib/speculations/parser/context/include.rb
29
29
  - lib/speculations/parser/state.rb
30
30
  - lib/speculations/parser/state/candidate.rb
31
+ - lib/speculations/parser/state/context_maker.rb
31
32
  - lib/speculations/parser/state/in.rb
33
+ - lib/speculations/parser/state/includes.rb
32
34
  - lib/speculations/parser/state/out.rb
33
35
  - lib/speculations/parser/state/triggers.rb
34
36
  - lib/speculations/version.rb