speculate_about 0.3.0 → 0.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/lib/speculations/parser/context.rb +19 -1
- data/lib/speculations/parser/state.rb +10 -0
- data/lib/speculations/parser/state/out.rb +12 -5
- data/lib/speculations/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a40862f65330fcfdc48e0b22fb9a09447269ecad7ca0582522ecda4450b3257a
|
4
|
+
data.tar.gz: a65d170a63cdd08c0dfa711854beaf876a5810d84f9a82eab489ffcaa0331e57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c42854aae7633c76e4d4cb8ce663915b55c48529833920252c3f2b57546cbe59490940db5c375a7468fede051cb237510255c3e5894b9e3ab87aa1feda126e1
|
7
|
+
data.tar.gz: 9c0e44f422c8638346fb416a3b4451a7a17001f1f9db08e70dbf4ed526b5b377fca96fb54ab9b1b3354d9fbbe91e2b97dde1b0bf15f2a261eec697677f7bc030
|
@@ -13,12 +13,13 @@ class Speculations::Parser::Context
|
|
13
13
|
|
14
14
|
def add_example(lnb:, line:)
|
15
15
|
examples << Example.new(lnb: lnb, parent: self, line: line, name: potential_name)
|
16
|
-
|
16
|
+
reset_context
|
17
17
|
examples.last
|
18
18
|
end
|
19
19
|
|
20
20
|
def add_include(lnb:)
|
21
21
|
includes << Include.new(lnb: lnb, parent: self)
|
22
|
+
@given = false
|
22
23
|
includes.last
|
23
24
|
end
|
24
25
|
|
@@ -30,6 +31,10 @@ class Speculations::Parser::Context
|
|
30
31
|
@__examples__ ||= []
|
31
32
|
end
|
32
33
|
|
34
|
+
def given?
|
35
|
+
@given
|
36
|
+
end
|
37
|
+
|
33
38
|
def includes
|
34
39
|
@__includes__ ||= []
|
35
40
|
end
|
@@ -39,8 +44,20 @@ class Speculations::Parser::Context
|
|
39
44
|
lines.flatten.map{ |line| "#{prefix}#{line.strip}" }.join("\n")
|
40
45
|
end
|
41
46
|
|
47
|
+
def reset_context
|
48
|
+
@potential_name = nil
|
49
|
+
@given = false
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def set_given given
|
54
|
+
@given = given
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
42
58
|
def set_name(potential_name)
|
43
59
|
@potential_name = potential_name
|
60
|
+
self
|
44
61
|
end
|
45
62
|
|
46
63
|
def set_setup(lnb:)
|
@@ -63,6 +80,7 @@ class Speculations::Parser::Context
|
|
63
80
|
def initialize(alternate_syntax: false, lnb:, name:, filename: nil, orig_filename: nil, parent: nil)
|
64
81
|
_init_from_parent filename, orig_filename, parent
|
65
82
|
@alternate_syntax = alternate_syntax
|
83
|
+
@given = false
|
66
84
|
@level = parent ? parent.level.succ : 1
|
67
85
|
@lnb = lnb
|
68
86
|
@setup = nil
|
@@ -8,9 +8,11 @@ module Speculations::Parser::State extend self
|
|
8
8
|
CONTEXT_RGX = %r[\A\s{0,3}\#{1,7}\s+Context\s+(.*)]
|
9
9
|
EOBLOCK_RGX = %r[\A\s{0,3}```\s*\z]
|
10
10
|
EXAMPLE_RGX = %r[\A\s{0,3}```.*\s:example]
|
11
|
+
GIVEN_RGX = %r[\A\s{0,3}(?:Given|When)\b]
|
11
12
|
INCLUDE_RGX = %r[\A\s{0,3}```.*\s:include]
|
12
13
|
NAME_RGX = %r[\A\s{0,3}Example:?\s+(.*)]i
|
13
14
|
RUBY_RGX = %r[\A\s{0,3}```ruby]
|
15
|
+
THEN_RGX = %r[\A\s{0,3}Then\s+(.*)]
|
14
16
|
WS_RGX = %r[\A\s*\z]
|
15
17
|
|
16
18
|
def before_match line
|
@@ -30,6 +32,10 @@ module Speculations::Parser::State extend self
|
|
30
32
|
def example_match line
|
31
33
|
EXAMPLE_RGX =~ line
|
32
34
|
end
|
35
|
+
|
36
|
+
def given_match line
|
37
|
+
GIVEN_RGX =~ line
|
38
|
+
end
|
33
39
|
|
34
40
|
def include_match line
|
35
41
|
INCLUDE_RGX =~ line
|
@@ -43,6 +49,10 @@ module Speculations::Parser::State extend self
|
|
43
49
|
RUBY_RGX =~ line
|
44
50
|
end
|
45
51
|
|
52
|
+
def then_match line
|
53
|
+
THEN_RGX.match(line)
|
54
|
+
end
|
55
|
+
|
46
56
|
def ws_match line
|
47
57
|
WS_RGX =~ line
|
48
58
|
end
|
@@ -18,24 +18,31 @@ module Speculations
|
|
18
18
|
when name = State.context_match(line)
|
19
19
|
node = node.parent if node.parent
|
20
20
|
new_node = node.add_child(name: name, lnb: lnb)
|
21
|
-
new_node.
|
22
|
-
[:out, new_node]
|
21
|
+
[:out, new_node.reset_context]
|
23
22
|
when State.ws_match(line)
|
24
23
|
[:out, node]
|
25
24
|
when name = State.potential_name(line)
|
26
25
|
node.set_name(name[1])
|
26
|
+
node.set_given(false)
|
27
|
+
[:out, node]
|
28
|
+
when name = State.then_match(line)
|
29
|
+
node.set_name(name[1])
|
30
|
+
node.set_given(false)
|
27
31
|
[:out, node]
|
32
|
+
when State.given_match(line)
|
33
|
+
[:out, node.set_given(true)]
|
28
34
|
when State.ruby_match(line)
|
29
35
|
if node.potential_name
|
30
36
|
node = node.add_example(lnb: lnb, line: line)
|
31
37
|
[:exa, node]
|
32
|
-
|
38
|
+
elsif node.given?
|
33
39
|
node = node.add_include(lnb: lnb)
|
34
40
|
[:inc, node]
|
41
|
+
else
|
42
|
+
[:out, node]
|
35
43
|
end
|
36
44
|
else
|
37
|
-
node.
|
38
|
-
[:out, node]
|
45
|
+
[:out, node.reset_context]
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
data/lib/speculations/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|