seeing_is_believing 2.1.2 → 2.1.3

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
  SHA1:
3
- metadata.gz: da28e937d89552e6cfb5ceeaff5d2d8908d8e0de
4
- data.tar.gz: 2c7f3eb3c304c4eb206893b24ee3f77cf60d4c41
3
+ metadata.gz: 924b2f9837ef55a65692edd1552bb4e28c497e04
4
+ data.tar.gz: c527cc92aea505196789779036ff2b9fb3265056
5
5
  SHA512:
6
- metadata.gz: 75826e4eabec47dfdd07feb60f29893010ed569ff53b8e1edcbcd86f8a05077fff9646975af7019582bda3bf098dfc864789803dcf52c78e402758dae0b46e95
7
- data.tar.gz: 7233ccadb27cc4fe3cc436f51b2576cb2aeb9cfb6d75252f5c89eaa164dd61bbb3291c0ff6077c90916b91e7498a32ef0135168faee7d9acd6ae5c88fbbf60c3
6
+ metadata.gz: a327a0865eb016d325158d9eb17fb34803634e37b2a0c31037df8385f076b3dbb23627c04498b5c9f5d6f4128efa544afe8c90b802536cb194f0b01bed3e53ad
7
+ data.tar.gz: fb8f88092ae5e16ea2ff1ca5f9ee22f7b993062ab8c67f93a4ec02b6ca3a7b0c8876998ee28e6994cbe6affd2af4ac96f6bcdba0fdefa6c2396df3a252542776
data/.travis.yml CHANGED
@@ -3,3 +3,4 @@ script: rake
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
+ - 2.1.2
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'pry'
4
3
  gemspec
data/Readme.md CHANGED
@@ -100,7 +100,6 @@ Shit that will probably never get done (or if it does, won't be until after 2.0)
100
100
 
101
101
  * How about if begin/rescue/end was able to record the result on the rescue section
102
102
  * What about recording the result of a line inside of a string interpolation, e.g. "a#{\n1\n}b" could record line 2 is 1 and line 3 is "a\n1\nb"
103
- * Be able to clean an invalid file (used to be able to do this, but parser can't identify comments in an invalid file the way that I'm currently using it, cuke is still there, marked as @not-implemented)
104
103
  * If given a file with a Unicode character, but not set Unicode, inform the user
105
104
 
106
105
  License
@@ -20,12 +20,12 @@ class SeeingIsBelieving
20
20
 
21
21
  def call
22
22
  @call ||= begin
23
- line_num_to_indexes = line_nums_to_last_index_and_col(buffer)
24
- remove_lines_after_data_segment line_num_to_indexes
25
- remove_lines_whose_newline_is_escaped line_num_to_indexes
26
- remove_lines_ending_in_comments line_num_to_indexes, comments
27
- remove_lines_inside_of_strings_and_things line_num_to_indexes, root
28
- line_num_to_indexes
23
+ line_num_to_location = line_nums_to_last_index_and_col(buffer)
24
+ remove_lines_after_data_segment line_num_to_location
25
+ remove_lines_whose_newline_is_escaped line_num_to_location
26
+ remove_lines_ending_in_comments line_num_to_location, comments
27
+ remove_lines_inside_of_strings_and_things line_num_to_location, root
28
+ line_num_to_location
29
29
  end
30
30
  end
31
31
 
@@ -37,44 +37,44 @@ class SeeingIsBelieving
37
37
  attr_accessor :code, :parser, :root, :comments
38
38
 
39
39
  def line_nums_to_last_index_and_col(buffer)
40
- line_num_to_indexes = code.each_char
41
- .with_index
42
- .select { |char, index| char == "\n" } # <-- is this okay? what about other OSes?
43
- .each_with_object(Hash.new) do |(_, index), hash|
44
- line, col = buffer.decompose_position index
45
- hash[line] = [index, col]
46
- end
40
+ line_num_to_location = code.each_char
41
+ .with_index
42
+ .select { |char, index| char == "\n" } # <-- is this okay? what about other OSes?
43
+ .each_with_object(Hash.new) do |(_, index), hash|
44
+ line, col = buffer.decompose_position index
45
+ hash[line] = [index, col]
46
+ end
47
47
  if code[code.size-1] != "\n" # account for the fact that the last line wouldn't have been found above if it doesn't end in a newline
48
48
  line, col = buffer.decompose_position code.size
49
- line_num_to_indexes[line] = [code.size, col]
49
+ line_num_to_location[line] = [code.size, col]
50
50
  end
51
- line_num_to_indexes
51
+ line_num_to_location
52
52
  end
53
53
 
54
- def remove_lines_whose_newline_is_escaped(line_num_to_indexes)
55
- line_num_to_indexes.select { |line_number, (index_of_newline, col)| code[index_of_newline-1] == '\\' }
56
- .each { |line_number, (index_of_newline, col)| line_num_to_indexes.delete line_number }
54
+ def remove_lines_whose_newline_is_escaped(line_num_to_location)
55
+ line_num_to_location.select { |line_number, (index_of_newline, col)| code[index_of_newline-1] == '\\' }
56
+ .each { |line_number, (index_of_newline, col)| line_num_to_location.delete line_number }
57
57
  end
58
58
 
59
- def remove_lines_ending_in_comments(line_num_to_indexes, comments)
59
+ def remove_lines_ending_in_comments(line_num_to_location, comments)
60
60
  comments.each do |comment|
61
61
  if comment.type == :inline
62
- line_num_to_indexes.delete comment.location.line
62
+ line_num_to_location.delete comment.location.line
63
63
  else
64
64
  begin_pos = comment.location.expression.begin_pos
65
65
  end_pos = comment.location.expression.end_pos
66
66
  range = begin_pos...end_pos
67
- line_num_to_indexes.select { |line_number, (index_of_newline, col)| range.include? index_of_newline }
68
- .each { |line_number, (index_of_newline, col)| line_num_to_indexes.delete line_number }
67
+ line_num_to_location.select { |line_number, (index_of_newline, col)| range.include? index_of_newline }
68
+ .each { |line_number, (index_of_newline, col)| line_num_to_location.delete line_number }
69
69
  end
70
70
  end
71
71
  end
72
72
 
73
- def remove_lines_inside_of_strings_and_things(line_num_to_indexes, ast)
73
+ def remove_lines_inside_of_strings_and_things(line_num_to_location, ast)
74
74
  invalid_boundaries = ranges_of_atomic_expressions ast, []
75
75
  invalid_boundaries.each do |invalid_boundary|
76
- line_num_to_indexes.select { |line_number, (index_of_newline, col)| invalid_boundary.include? index_of_newline }
77
- .each { |line_number, (index_of_newline, col)| line_num_to_indexes.delete line_number }
76
+ line_num_to_location.select { |line_number, (index_of_newline, col)| invalid_boundary.include? index_of_newline }
77
+ .each { |line_number, (index_of_newline, col)| line_num_to_location.delete line_number }
78
78
  end
79
79
  end
80
80
 
@@ -106,8 +106,8 @@ class SeeingIsBelieving
106
106
  end
107
107
  end
108
108
 
109
- def remove_lines_after_data_segment(line_num_to_indexes)
110
- data_segment_line, _ = line_num_to_indexes.find do |line_number, (end_index, col)|
109
+ def remove_lines_after_data_segment(line_num_to_location)
110
+ data_segment_line, _ = line_num_to_location.find do |line_number, (end_index, col)|
111
111
  if end_index == 7
112
112
  code.start_with? '__END__'
113
113
  elsif end_index < 7
@@ -117,8 +117,8 @@ class SeeingIsBelieving
117
117
  end
118
118
  end
119
119
  return unless data_segment_line
120
- max_line = line_num_to_indexes.keys.max
121
- data_segment_line.upto(max_line) { |line_number| line_num_to_indexes.delete line_number }
120
+ max_line = line_num_to_location.keys.max
121
+ data_segment_line.upto(max_line) { |line_number| line_num_to_location.delete line_number }
122
122
  end
123
123
  end
124
124
  end
@@ -186,21 +186,21 @@ class SeeingIsBelieving
186
186
  { stdout: results.stdout,
187
187
  stderr: results.stderr,
188
188
  exit_status: results.exitstatus,
189
- exception: if results.has_exception?
189
+ exception: (if results.has_exception?
190
190
  { line_number_in_this_file: results.each_with_line_number.find { |line_number, result| result.has_exception? }.first,
191
191
  class_name: results.exception.class_name,
192
192
  message: results.exception.message,
193
193
  backtrace: results.exception.backtrace,
194
194
  }
195
- end,
195
+ end),
196
196
  lines: results.each_with_line_number.each_with_object(Hash.new) { |(line_number, result), hash|
197
197
  hash[line_number] = { results: result.to_a,
198
- exception: if result.has_exception?
198
+ exception: (if result.has_exception?
199
199
  { class_name: results.exception.class_name,
200
200
  message: results.exception.message,
201
201
  backtrace: results.exception.backtrace,
202
202
  }
203
- end
203
+ end)
204
204
  }
205
205
  },
206
206
  }
@@ -1,3 +1,3 @@
1
1
  class SeeingIsBelieving
2
- VERSION = '2.1.2'
2
+ VERSION = '2.1.3'
3
3
  end
@@ -213,14 +213,18 @@ class SeeingIsBelieving
213
213
  add_to_wrappings range, meta
214
214
  add_children ast
215
215
  when :begin
216
- last_child = ast.children.last
217
- if heredoc? last_child
218
- range = Parser::Source::Range.new buffer,
219
- ast.location.expression.begin_pos,
220
- heredoc_hack(last_child).location.expression.end_pos
221
- add_to_wrappings range unless void_value? ast.children.last
216
+ if ast.location.expression.source.start_with?("(") && # e.g. `(1)` we want `<(1)>`
217
+ !void_value?(ast) # e.g. `(return 1)` we want `(return <1>)`
218
+ add_to_wrappings ast
219
+ else # e.g. `A\nB` we want `<A>\n<B>`
220
+ last_child = ast.children.last
221
+ if heredoc? last_child
222
+ range = Parser::Source::Range.new buffer,
223
+ ast.location.expression.begin_pos,
224
+ heredoc_hack(last_child).location.expression.end_pos
225
+ add_to_wrappings range unless void_value? ast.children.last
226
+ end
222
227
  end
223
-
224
228
  add_children ast
225
229
  when :str, :dstr, :xstr, :regexp
226
230
  add_to_wrappings heredoc_hack ast
@@ -1,9 +1,5 @@
1
1
  require 'seeing_is_believing/binary/comment_lines'
2
2
 
3
- # FIXME: For now ignoring heredocs
4
- # because we know the user of this class won't have output on them
5
- # and it's a PITA to deal with.
6
- # Eventually, though, Parser should take this into account
7
3
  describe SeeingIsBelieving::Binary::CommentLines, 'passes in the each commentable line and the line number, and adds the returned text (whitespace+comment) to the end' do
8
4
  def call(code, &block)
9
5
  described_class.call code, &block
@@ -15,7 +15,7 @@ describe SeeingIsBelieving::Debugger do
15
15
  described_class.new(colour: true).should be_coloured
16
16
  end
17
17
 
18
- context 'when given a steram' do
18
+ context 'when given a stream' do
19
19
  it 'prints the the context and the value of the block' do
20
20
  described_class.new(stream: stream).context('C') { 'V' }
21
21
  stream.string.should == "C:\nV\n"
@@ -56,18 +56,26 @@ describe SeeingIsBelieving::HardCoreEnsure do
56
56
  end
57
57
 
58
58
  it 'invokes the code even if an interrupt is sent and interrupts are set to ignore' do
59
- channel = IChannel.new Marshal
60
- pid = fork do
61
- old_handler = trap 'INT', 'IGNORE'
62
- result = call code: -> { sleep 0.1; 'code result' }, ensure: -> { channel.put "ensure invoked" }
63
- channel.put result
64
- trap 'INT', old_handler
59
+ test = lambda do
60
+ channel = IChannel.new Marshal
61
+ pid = fork do
62
+ old_handler = trap 'INT', 'IGNORE'
63
+ result = call code: -> { sleep 0.1; 'code result' }, ensure: -> { channel.put "ensure invoked" }
64
+ channel.put result
65
+ trap 'INT', old_handler
66
+ end
67
+ sleep 0.05
68
+ Process.kill 'INT', pid
69
+ Process.wait pid
70
+ channel.get.should == "ensure invoked"
71
+ channel.get.should == 'code result'
72
+ channel.should_not be_readable
73
+ end
74
+
75
+ if RUBY_VERSION == '2.1.1' || RUBY_VERSION == '2.1.2'
76
+ pending 'This test can\'t run on 2.1.1 or 2.1.2'
77
+ else
78
+ test.call
65
79
  end
66
- sleep 0.05
67
- Process.kill 'INT', pid
68
- Process.wait pid
69
- channel.get.should == "ensure invoked"
70
- channel.get.should == 'code result'
71
- channel.should_not be_readable
72
80
  end
73
81
  end
@@ -33,6 +33,11 @@ describe SeeingIsBelieving::WrapExpressions do
33
33
  described_class.call("1# abc", options).should == "[<1>]# abc"
34
34
  end
35
35
 
36
+ it 'wraps bodies that are wrapped in parentheses' do
37
+ wrap('(1)').should == '<(1)>'
38
+ wrap("(\n<<doc\ndoc\n)").should == "<(\n<<<doc>\ndoc\n)>"
39
+ end
40
+
36
41
  context 'fucking heredocs' do
37
42
  example 'single heredoc' do
38
43
  described_class.call("<<A\nA", options).should == "[<<<A>]\nA"
@@ -161,8 +166,8 @@ describe SeeingIsBelieving::WrapExpressions do
161
166
 
162
167
  it 'wraps multiple expressions' do
163
168
  wrap("A\nB").should == "<A>\n<B>"
164
- wrap("(1\n2)").should == "(<1>\n<2>)"
165
- # wrap("(1\n2\n)").should == "<(<1>\n<2>\n)>" # just not worth the effort of identifying it, really
169
+ wrap("(1\n2)").should == "<(<1>\n2)>"
170
+ wrap("(1\n2\n)").should == "<(<1>\n<2>\n)>"
166
171
  wrap("begin\n1\n2\nend").should == "<begin\n<1>\n<2>\nend>"
167
172
  end
168
173
 
metadata CHANGED
@@ -1,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seeing_is_believing
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Cheek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-02 00:00:00.000000000 Z
11
+ date: 2014-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 2.1.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.1.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: haiti
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.0.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.0.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 10.0.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 10.0.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: 2.12.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 2.12.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: cucumber
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.2.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.2.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: ichannel
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 5.1.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 5.1.1
97
97
  description: Records the results of every line of code in your file (intended to be
@@ -104,8 +104,8 @@ executables:
104
104
  extensions: []
105
105
  extra_rdoc_files: []
106
106
  files:
107
- - .gitignore
108
- - .travis.yml
107
+ - ".gitignore"
108
+ - ".travis.yml"
109
109
  - Gemfile
110
110
  - Rakefile
111
111
  - Readme.md
@@ -202,17 +202,17 @@ require_paths:
202
202
  - lib
203
203
  required_ruby_version: !ruby/object:Gem::Requirement
204
204
  requirements:
205
- - - '>='
205
+ - - ">="
206
206
  - !ruby/object:Gem::Version
207
207
  version: '0'
208
208
  required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  requirements:
210
- - - '>='
210
+ - - ">="
211
211
  - !ruby/object:Gem::Version
212
212
  version: '0'
213
213
  requirements: []
214
214
  rubyforge_project: seeing_is_believing
215
- rubygems_version: 2.0.3
215
+ rubygems_version: 2.2.2
216
216
  signing_key:
217
217
  specification_version: 4
218
218
  summary: Records results of every line of code in your file
@@ -233,4 +233,3 @@ test_files:
233
233
  - spec/line_spec.rb
234
234
  - spec/seeing_is_believing_spec.rb
235
235
  - spec/wrap_expressions_spec.rb
236
- has_rdoc: