seeing_is_believing 0.0.26 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,198 @@
1
+ require 'seeing_is_believing/binary/remove_previous_annotations'
2
+
3
+ describe SeeingIsBelieving::Binary::RemovePreviousAnnotations do
4
+ def call(code)
5
+ indentation = code[/\A */]
6
+ code = code.gsub /^#{indentation}/, ''
7
+ described_class.call(code).chomp
8
+ end
9
+
10
+ # show some examples of what it should not remove
11
+
12
+ example { call("1#=>1").should == "1" }
13
+ example { call("1 #=>1").should == "1" }
14
+ example { call("1 #=>1").should == "1" }
15
+ example { call("1 #=> 1").should == "1" }
16
+ example { call("1 #=> 1").should == "1" }
17
+ example { call("1 #=> 1").should == "1" }
18
+ example { call("\n1 # => 1").should == "\n1" }
19
+
20
+ example { call("1#~>1").should == "1" }
21
+ example { call("1 #~>1").should == "1" }
22
+ example { call("1 #~>1").should == "1" }
23
+ example { call("1 #~> 1").should == "1" }
24
+ example { call("1 #~> 1").should == "1" }
25
+ example { call("1 #~> 1").should == "1" }
26
+ example { call("\n1 # ~> 1").should == "\n1" }
27
+
28
+ example { call("# >> 1").should == "" }
29
+ example { call("# !> 1").should == "" }
30
+
31
+ example { call(<<-CODE).should == "1" }
32
+ 1
33
+ # >> 2
34
+ CODE
35
+
36
+ example { call(<<-CODE).should == "1" }
37
+ 1
38
+
39
+ # >> 2
40
+ CODE
41
+
42
+ example { call(<<-CODE).should == "1\n" }
43
+ 1
44
+
45
+
46
+ # >> 2
47
+ CODE
48
+
49
+ example { call(<<-CODE).should == "1\n" }
50
+ 1
51
+
52
+
53
+ # >> 2
54
+ # >> 2
55
+ # >> 2
56
+ CODE
57
+
58
+
59
+ example { call(<<-CODE).should == "1\n" }
60
+ 1
61
+
62
+
63
+ # >> 2
64
+ # >> 3
65
+ CODE
66
+
67
+ example { call(<<-CODE).should == "1" }
68
+ 1
69
+ # !> 2
70
+ CODE
71
+
72
+ example { call(<<-CODE).should == "1" }
73
+ 1
74
+
75
+ # !> 2
76
+ CODE
77
+
78
+ example { call(<<-CODE).should == "1" }
79
+ 1
80
+
81
+ # !> 2
82
+ # !> 3
83
+ CODE
84
+
85
+ example { call(<<-CODE).should == "1\n" }
86
+ 1
87
+
88
+
89
+ # !> 2
90
+ # !> 2
91
+ # !> 2
92
+ CODE
93
+
94
+
95
+ example { call(<<-CODE).should == "1" }
96
+ 1
97
+ # ~>2
98
+ CODE
99
+
100
+ example { call(<<-CODE).should == "1" }
101
+ 1
102
+
103
+ # ~> 2
104
+ CODE
105
+
106
+ example { call(<<-CODE).should == "1" }
107
+ 1
108
+
109
+ # ~> 2
110
+ # ~> 3
111
+ CODE
112
+
113
+ example { call(<<-CODE).should == "1\n" }
114
+ 1
115
+
116
+
117
+ # ~> 2
118
+ # ~> 2
119
+ # ~> 2
120
+ CODE
121
+
122
+ example { call(<<-CODE).should == "1\n" }
123
+ 1 # ~> error
124
+
125
+
126
+ # ~> error again
127
+ CODE
128
+
129
+ example { call(<<-CODE).should == "1" }
130
+ 1
131
+
132
+ # >> 1
133
+ # >> 2
134
+
135
+ # !> 3
136
+ # !> 4
137
+
138
+ # ~> 5
139
+ # ~> 6
140
+ CODE
141
+
142
+ example { call(<<-CODE).should == "1" }
143
+ 1
144
+
145
+ # >> 1
146
+
147
+ # >> 2
148
+
149
+ # !> 3
150
+
151
+ # !> 4
152
+
153
+ # ~> 5
154
+
155
+ # ~> 6
156
+ CODE
157
+
158
+ example { call(<<-CODE).should == "1" }
159
+ 1
160
+
161
+ # >> 1
162
+ # >> 2
163
+ # !> 3
164
+ # !> 4
165
+ # ~> 5
166
+ # ~> 6
167
+ CODE
168
+
169
+ example { call(<<-CODE).should == "1\n3" }
170
+ 1
171
+ # >> 1
172
+ # >> 2
173
+ 3
174
+ # !> 4
175
+ # !> 5
176
+ CODE
177
+
178
+ example { call(<<-CODE).should == "1\n3\n6" }
179
+ 1
180
+ # >> 1
181
+ # >> 2
182
+ 3
183
+ # !> 4
184
+ # !> 5
185
+ 6
186
+ # ~> 7
187
+ # ~> 8
188
+ CODE
189
+
190
+ example { call(<<-CODE).should == "1\n\nputs \"omg\"" }
191
+ 1 # => 1
192
+
193
+ puts "omg" # ~> RuntimeError: omg
194
+
195
+ # ~> RuntimeError
196
+ CODE
197
+
198
+ end
@@ -0,0 +1,27 @@
1
+ require 'seeing_is_believing/debugger'
2
+
3
+ describe SeeingIsBelieving::Debugger do
4
+ specify 'the debugger is enabled by default' do
5
+ described_class.new.should be_enabled
6
+ described_class.new(enabled: true).should be_enabled
7
+ described_class.new(enabled: false).should_not be_enabled
8
+ end
9
+
10
+ it 'does not evaluate its contexts when disabled' do
11
+ expect { described_class.new(enabled: true).context('c') { raise 'omg' } }.to raise_error 'omg'
12
+ expect { described_class.new(enabled: false).context('c') { raise 'omg' } }.to_not raise_error
13
+ end
14
+
15
+ it 'caches results under a name which all appear consecutively next to eachother regardless of when they were called' do
16
+ described_class.new(enabled: true, color: false)
17
+ .context('a') { '1' }
18
+ .context('b') { '3' }
19
+ .context('a') { '2' }
20
+ .to_s.should == "a:\n1\n2\n\nb:\n3\n"
21
+ end
22
+
23
+ specify 'colouring is disabled by default' do
24
+ described_class.new(enabled: true, colour: true).context('AAA') { 'BBB' }.to_s.should ==
25
+ "#{described_class::CONTEXT_COLOUR}AAA:#{described_class::RESET_COLOUR}\nBBB\n"
26
+ end
27
+ end
@@ -256,10 +256,10 @@ describe SeeingIsBelieving::ExpressionList do
256
256
  end
257
257
 
258
258
  example "example: smoke test debug option" do
259
- stream = StringIO.new
260
- call(%w[a+ b], debug: true, debug_stream: stream) { |*expressions, _| expressions.join("\n") }
261
- stream.string.should include "GENERATED"
262
- stream.string.should include "REDUCED"
259
+ debugger = SeeingIsBelieving::Debugger.new
260
+ call(%w[a+ b], debugger: debugger) { |*expressions, _| expressions.join("\n") }
261
+ debugger.to_s.should include "GENERATED"
262
+ debugger.to_s.should include "REDUCED"
263
263
  end
264
264
 
265
265
  # in reality, the problem may just lie with our lib
@@ -11,16 +11,12 @@ describe SeeingIsBelieving do
11
11
  invoke(input).to_a
12
12
  end
13
13
 
14
- def stream(string)
15
- StringIO.new string
16
- end
17
-
18
14
  let(:proving_grounds_dir) { File.expand_path '../../proving_grounds', __FILE__ }
19
15
 
20
- it 'takes a string or stream and returns a result of the line numbers (counting from 1) and each inspected result from that line' do
16
+ it 'takes a string or and returns a result of the line numbers (counting from 1) and each inspected result from that line' do
21
17
  input = "1+1\n'2'+'2'"
22
18
  invoke(input)[1].should == ["2"]
23
- invoke(stream input)[2].should == ['"22"']
19
+ invoke(input)[2].should == ['"22"']
24
20
  end
25
21
 
26
22
  it 'remembers context of previous lines' do
@@ -116,7 +112,7 @@ describe SeeingIsBelieving do
116
112
  values_for("def meth\n<<-A\n1\nA\nend").should == [[], [], [], [], ['nil']]
117
113
  end
118
114
 
119
- it 'does not insert code into the middle of heredocs', t:true do
115
+ it 'does not insert code into the middle of heredocs' do
120
116
  invoked = invoke(<<-HEREDOC.gsub(/^ /, ''))
121
117
  puts <<DOC1
122
118
  doc1
@@ -311,6 +307,20 @@ describe SeeingIsBelieving do
311
307
  3#comment tres').should == [['2'], [], ['3']]
312
308
  end
313
309
 
310
+ it "doesn't fuck up when there are lines with magic comments in the middle of the app" do
311
+ values_for('1+1
312
+ # encoding: wtf').should == [['2'], []]
313
+ end
314
+
315
+ it "doesn't remove multiple leading comments" do
316
+ values_for("#!/usr/bin/env ruby\n"\
317
+ "# encoding: utf-8\n"\
318
+ "'ç'").should == [[], [], ['"ç"']]
319
+ values_for("#!/usr/bin/env ruby\n"\
320
+ "1 # encoding: utf-8\n"\
321
+ "2").should == [[], ['1'], ['2']]
322
+ end
323
+
314
324
  it 'can record the middle of a chain of calls', not_implemented: true do
315
325
  values_for("[*1..5]
316
326
  .select(&:even?)
@@ -330,4 +340,29 @@ describe SeeingIsBelieving do
330
340
  # values_for("1\\\n+ 2").should == [['1'], ['3']]
331
341
  end
332
342
 
343
+ context 'when given a debugger' do
344
+ let(:debugger) { SeeingIsBelieving::Debugger.new enabled: true }
345
+
346
+ def call
347
+ invoke "1", debugger: debugger
348
+ end
349
+
350
+ it 'prints the program without comments' do
351
+ call
352
+ debugger.to_s.should include "SOURCE WITHOUT COMMENTS:"
353
+ debugger.to_s.should include "\n1\n"
354
+ end
355
+
356
+ it 'prints the pre-evaluated program' do
357
+ call
358
+ debugger.to_s.should include "TRANSLATED PROGRAM:"
359
+ debugger.to_s.should include "\nbegin;" # there is more, but we're just interested in showing that it wound up in the stream
360
+ end
361
+
362
+ it 'has the ExpressionList print its debug options into the output' do
363
+ call
364
+ debugger.to_s.should include "EXPRESSION EVALUATION:"
365
+ end
366
+ end
367
+
333
368
  end
@@ -55,6 +55,7 @@ describe SeeingIsBelieving::SyntaxAnalyzer do
55
55
  is_comment['a # whatev'].should be_true
56
56
  is_comment["a \n b # whatev"].should be_true
57
57
  is_comment["=begin\n1\n=end"].should be_true
58
+ is_comment["# Transfer-Encoding: chunked"].should be_true
58
59
 
59
60
  # false
60
61
  is_comment['a'].should be_false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seeing_is_believing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.26
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Cheek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-29 00:00:00.000000000 Z
11
+ date: 2013-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 2.0.0.beta9
19
+ version: 2.0.0.pre1
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
- version: 2.0.0.beta9
26
+ version: 2.0.0.pre1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: haiti
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -117,12 +117,14 @@ files:
117
117
  - features/support/env.rb
118
118
  - lib/seeing_is_believing.rb
119
119
  - lib/seeing_is_believing/binary.rb
120
+ - lib/seeing_is_believing/binary/add_annotations.rb
120
121
  - lib/seeing_is_believing/binary/align_chunk.rb
121
122
  - lib/seeing_is_believing/binary/align_file.rb
122
123
  - lib/seeing_is_believing/binary/align_line.rb
123
124
  - lib/seeing_is_believing/binary/arg_parser.rb
124
125
  - lib/seeing_is_believing/binary/line_formatter.rb
125
- - lib/seeing_is_believing/binary/print_results_next_to_lines.rb
126
+ - lib/seeing_is_believing/binary/remove_previous_annotations.rb
127
+ - lib/seeing_is_believing/debugger.rb
126
128
  - lib/seeing_is_believing/error.rb
127
129
  - lib/seeing_is_believing/evaluate_by_moving_files.rb
128
130
  - lib/seeing_is_believing/expression_list.rb
@@ -137,11 +139,13 @@ files:
137
139
  - lib/seeing_is_believing/tracks_line_numbers_seen.rb
138
140
  - lib/seeing_is_believing/version.rb
139
141
  - seeing_is_believing.gemspec
140
- - spec/arg_parser_spec.rb
142
+ - spec/binary/arg_parser_spec.rb
143
+ - spec/binary/line_formatter_spec.rb
144
+ - spec/binary/remove_previous_annotations_spec.rb
145
+ - spec/debugger_spec.rb
141
146
  - spec/evaluate_by_moving_files_spec.rb
142
147
  - spec/expression_list_spec.rb
143
148
  - spec/hard_core_ensure_spec.rb
144
- - spec/line_formatter_spec.rb
145
149
  - spec/line_spec.rb
146
150
  - spec/queue_spec.rb
147
151
  - spec/seeing_is_believing_spec.rb
@@ -167,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
171
  version: '0'
168
172
  requirements: []
169
173
  rubyforge_project: seeing_is_believing
170
- rubygems_version: 2.0.0
174
+ rubygems_version: 2.0.5
171
175
  signing_key:
172
176
  specification_version: 4
173
177
  summary: Records results of every line of code in your file
@@ -177,11 +181,13 @@ test_files:
177
181
  - features/flags.feature
178
182
  - features/regression.feature
179
183
  - features/support/env.rb
180
- - spec/arg_parser_spec.rb
184
+ - spec/binary/arg_parser_spec.rb
185
+ - spec/binary/line_formatter_spec.rb
186
+ - spec/binary/remove_previous_annotations_spec.rb
187
+ - spec/debugger_spec.rb
181
188
  - spec/evaluate_by_moving_files_spec.rb
182
189
  - spec/expression_list_spec.rb
183
190
  - spec/hard_core_ensure_spec.rb
184
- - spec/line_formatter_spec.rb
185
191
  - spec/line_spec.rb
186
192
  - spec/queue_spec.rb
187
193
  - spec/seeing_is_believing_spec.rb