instant 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -1,12 +1,13 @@
1
1
  Gemfile
2
- Procfile
2
+ Manifest
3
3
  README.md
4
4
  Rakefile
5
- instant.gemspec
5
+ config.ru
6
6
  lib/instant.rb
7
7
  lib/instant/context.rb
8
8
  lib/instant/processor.rb
9
9
  lib/instant/runner.rb
10
- lib/instant/sinatra/app.rb
11
10
  lib/instant/version.rb
12
- Manifest
11
+ spec/instant/context_spec.rb
12
+ spec/instant/processor_spec.rb
13
+ spec/instant/runner_spec.rb
data/Rakefile CHANGED
@@ -1,14 +1,18 @@
1
+ $LOAD_PATH << "lib"
2
+ require 'instant/version'
1
3
  require 'rubygems'
2
4
  require 'rake'
3
5
  require 'echoe'
4
6
 
5
- Echoe.new('instant', '0.0.1') do |p|
6
- p.description = "Generate a unique token with Active Record."
7
- p.url = "http://github.com/ryanb/uniquify"
8
- p.author = "Ryan Bates"
9
- p.email = "ryan@railscasts.com"
10
- p.ignore_pattern = ["tmp/*", "script/*"]
11
- p.development_dependencies = []
7
+ Echoe.new('instant', Instant::VERSION) do |p|
8
+ p.description = "An experiment on real time visualize development tool."
9
+ p.url = "http://github.com/siuying/instant"
10
+ p.author = "Francis Chong"
11
+ p.email = "francis@ignition.hk"
12
+ p.ignore_pattern = ["pkg/*", "spec/*", "views/*", "public/**/*", "lib/instant/sinatra/*", "Procfile"]
13
+ p.development_dependencies = ["rspec ~>2.9.0", "rake ~>1.1", "echoe", "autotest", "pry"]
14
+ p.runtime_dependencies = ['ruby2ruby ~>1.3.1', 'ruby_parser ~>2.3.1']
15
+ p.retain_gemspec = true
12
16
  end
13
17
 
14
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
18
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/config.ru ADDED
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.require :default
4
+
5
+ $LOAD_PATH << "lib"
6
+ require 'instant'
7
+ require 'instant/sinatra/app'
8
+
9
+ run Instant::Sinatra::App
data/instant.gemspec CHANGED
@@ -2,28 +2,49 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "instant"
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Ryan Bates"]
8
+ s.authors = ["Francis Chong"]
9
9
  s.date = "2012-04-19"
10
- s.description = "Generate a unique token with Active Record."
11
- s.email = "ryan@railscasts.com"
12
- s.extra_rdoc_files = ["README.md", "lib/instant.rb", "lib/instant/context.rb", "lib/instant/processor.rb", "lib/instant/runner.rb", "lib/instant/sinatra/app.rb", "lib/instant/version.rb"]
13
- s.files = ["Gemfile", "Procfile", "README.md", "Rakefile", "instant.gemspec", "lib/instant.rb", "lib/instant/context.rb", "lib/instant/processor.rb", "lib/instant/runner.rb", "lib/instant/sinatra/app.rb", "lib/instant/version.rb", "Manifest"]
14
- s.homepage = "http://github.com/ryanb/uniquify"
10
+ s.description = "An experiment on real time visualize development tool."
11
+ s.email = "francis@ignition.hk"
12
+ s.extra_rdoc_files = ["README.md", "lib/instant.rb", "lib/instant/context.rb", "lib/instant/processor.rb", "lib/instant/runner.rb", "lib/instant/version.rb"]
13
+ s.files = ["Gemfile", "Manifest", "README.md", "Rakefile", "config.ru", "lib/instant.rb", "lib/instant/context.rb", "lib/instant/processor.rb", "lib/instant/runner.rb", "lib/instant/version.rb", "spec/instant/context_spec.rb", "spec/instant/processor_spec.rb", "spec/instant/runner_spec.rb", "instant.gemspec"]
14
+ s.homepage = "http://github.com/siuying/instant"
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Instant", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = "instant"
18
18
  s.rubygems_version = "1.8.15"
19
- s.summary = "Generate a unique token with Active Record."
19
+ s.summary = "An experiment on real time visualize development tool."
20
20
 
21
21
  if s.respond_to? :specification_version then
22
22
  s.specification_version = 3
23
23
 
24
24
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_runtime_dependency(%q<ruby2ruby>, ["~> 1.3.1"])
26
+ s.add_runtime_dependency(%q<ruby_parser>, ["~> 2.3.1"])
27
+ s.add_development_dependency(%q<rspec>, ["~> 2.9.0"])
28
+ s.add_development_dependency(%q<rake>, ["~> 1.1"])
29
+ s.add_development_dependency(%q<echoe>, [">= 0"])
30
+ s.add_development_dependency(%q<autotest>, [">= 0"])
31
+ s.add_development_dependency(%q<pry>, [">= 0"])
25
32
  else
33
+ s.add_dependency(%q<ruby2ruby>, ["~> 1.3.1"])
34
+ s.add_dependency(%q<ruby_parser>, ["~> 2.3.1"])
35
+ s.add_dependency(%q<rspec>, ["~> 2.9.0"])
36
+ s.add_dependency(%q<rake>, ["~> 1.1"])
37
+ s.add_dependency(%q<echoe>, [">= 0"])
38
+ s.add_dependency(%q<autotest>, [">= 0"])
39
+ s.add_dependency(%q<pry>, [">= 0"])
26
40
  end
27
41
  else
42
+ s.add_dependency(%q<ruby2ruby>, ["~> 1.3.1"])
43
+ s.add_dependency(%q<ruby_parser>, ["~> 2.3.1"])
44
+ s.add_dependency(%q<rspec>, ["~> 2.9.0"])
45
+ s.add_dependency(%q<rake>, ["~> 1.1"])
46
+ s.add_dependency(%q<echoe>, [">= 0"])
47
+ s.add_dependency(%q<autotest>, [">= 0"])
48
+ s.add_dependency(%q<pry>, [">= 0"])
28
49
  end
29
50
  end
@@ -1,3 +1,3 @@
1
1
  module Instant
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'pp'
3
+
4
+ describe Instant::Context do
5
+ it "should log assignment" do
6
+ subject.log_assign(:a, "10")
7
+ subject.to_s.strip.should == "a = 10"
8
+ end
9
+
10
+ it "should log assignment inside loop" do
11
+ subject.loop_begin
12
+
13
+ subject.loop_inside_begin
14
+ subject.log_assign(:a, "10")
15
+ subject.loop_inside_end
16
+
17
+ subject.loop_inside_begin
18
+ subject.log_assign(:a, "11")
19
+ subject.loop_inside_end
20
+
21
+ subject.loop_inside_begin
22
+ subject.log_assign(:a, "12")
23
+ subject.loop_inside_end
24
+
25
+ subject.loop_end
26
+
27
+ subject.to_s.strip.should == "a = 10 | 11 | 12"
28
+ end
29
+
30
+ it "should log multiple assignment inside loop" do
31
+ subject.loop_begin
32
+
33
+ subject.loop_inside_begin
34
+ subject.log_assign(:a, "10")
35
+ subject.log_assign(:b, "A")
36
+ subject.loop_inside_end
37
+
38
+ subject.loop_inside_begin
39
+ subject.log_assign(:a, "11")
40
+ subject.loop_inside_end
41
+
42
+ subject.loop_inside_begin
43
+ subject.log_assign(:a, "12")
44
+ subject.log_assign(:b, "C")
45
+ subject.loop_inside_end
46
+
47
+ subject.loop_end
48
+
49
+ outputs = subject.to_s.split("\n").collect{|l| l.strip}
50
+ outputs.should be_include("a = 10 | 11 | 12")
51
+ outputs.should be_include("b = A | | C")
52
+ end
53
+ end
@@ -0,0 +1,143 @@
1
+ require 'spec_helper'
2
+ require 'pp'
3
+
4
+ describe Instant::Processor do
5
+ let(:parser) { RubyParser.new }
6
+
7
+ it "should log assignment in method arguments" do
8
+ source = "def hello(a=1)
9
+ a = 2
10
+ end"
11
+ expected = "def hello(a = log_assign(:a, 1))
12
+ a = log_assign(:a, 2)
13
+ end"
14
+
15
+ subject.process(source).should == expected.strip
16
+ end
17
+
18
+ it "should log simple assignment" do
19
+ source = "def hello
20
+ a = 1
21
+ end"
22
+ expected = "def hello
23
+ a = log_assign(:a, 1)
24
+ end"
25
+
26
+ subject.process(source).should == expected.strip
27
+ end
28
+
29
+ it "should log assignment with operator" do
30
+ source = "def hello
31
+ a = 1
32
+ b = 2
33
+ c = a + b
34
+ end"
35
+ expected = "def hello
36
+ a = log_assign(:a, 1)
37
+ b = log_assign(:b, 2)
38
+ c = log_assign(:c, (a + b))
39
+ end"
40
+
41
+ subject.process(source).should == expected.strip
42
+ end
43
+
44
+ it "should log while loop" do
45
+ source = "def hello
46
+ i = 0
47
+ k = 0
48
+ while (i < 5) do
49
+ k = (k - 1)
50
+ i = (i + 1)
51
+ end
52
+ end"
53
+
54
+ expected = "def hello
55
+ i = log_assign(:i, 0)
56
+ k = log_assign(:k, 0)
57
+ loop_begin
58
+ while (i < 5) do
59
+ loop_inside_begin
60
+ (k = log_assign(:k, (k - 1))
61
+ i = log_assign(:i, (i + 1)))
62
+ loop_inside_end
63
+ end
64
+ loop_end
65
+ end"
66
+
67
+ subject.process(source).should == expected.strip
68
+ end
69
+
70
+ it "should log if in while loop" do
71
+ source = "def hello
72
+ i = 0
73
+ j = 0
74
+ k = 0
75
+ while (i < 5) do
76
+ if i < 3
77
+ k = (k + i)
78
+ else
79
+ j = (j + i)
80
+ end
81
+ i = (i + 1)
82
+ end
83
+ end"
84
+
85
+ expected = "def hello
86
+ i = log_assign(:i, 0)
87
+ j = log_assign(:j, 0)
88
+ k = log_assign(:k, 0)
89
+ loop_begin
90
+ while (i < 5) do
91
+ loop_inside_begin
92
+ ((i < 3) ? (k = log_assign(:k, (k + i))) : (j = log_assign(:j, (j + i)))
93
+ i = log_assign(:i, (i + 1)))
94
+ loop_inside_end
95
+ end
96
+ loop_end
97
+ end"
98
+
99
+ # pp parser.process source
100
+ # pp parser.process expected
101
+
102
+ subject.process(source).should == expected.strip
103
+ end
104
+
105
+ it "should render while loop with return" do
106
+ source = "def hello
107
+ k = 1
108
+ i = 2
109
+ while true do
110
+ k = (k - 1)
111
+ i = (i + 1)
112
+
113
+ if k < 10
114
+ return k
115
+ end
116
+ end
117
+ end
118
+ hello"
119
+
120
+ expected = "def hello
121
+ k = log_assign(:k, 1)
122
+ i = log_assign(:i, 2)
123
+ loop_begin
124
+ while true do
125
+ loop_inside_begin
126
+ (k = log_assign(:k, (k - 1))
127
+ i = log_assign(:i, (i + 1))
128
+ return k if (k < 10))
129
+ loop_inside_end
130
+ end
131
+ loop_end
132
+ end
133
+ hello"
134
+ #pp parser.process source
135
+ #pp parser.process expected
136
+
137
+ subject.process(source).strip.should == expected
138
+ end
139
+
140
+ it "should log method arguments"
141
+ it "should log return"
142
+
143
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'pp'
3
+
4
+ describe Instant::Runner do
5
+ context "#run" do
6
+ it "should process the input" do
7
+ source = "def hello; a = 1; end"
8
+ processed_source = stub(:processed_source)
9
+
10
+ processor = stub(:processor)
11
+ processor.should_receive(:process).with(source).and_return(processed_source)
12
+
13
+ context_stub = stub(:context)
14
+ context_stub.should_receive(:instance_eval).with(processed_source)
15
+ context_stub.should_receive(:close)
16
+
17
+ Instant::Context.stub(:new => context_stub)
18
+ runner = Instant::Runner.new(processor)
19
+ runner.run(source)
20
+ end
21
+
22
+ it "should not die in infinite loop" do
23
+ source = "def hello
24
+ k = 1
25
+ i = 2
26
+ while true do
27
+ k = (k - 1)
28
+ i = (i + 1)
29
+ end
30
+ end; hello"
31
+ runner = Instant::Runner.new
32
+ result = runner.run(source)
33
+ result[:status].should == :error
34
+ result[:cause].should == :loop_too_deep
35
+ results = result[:result].split("\n")
36
+ results[0].strip.should =~ /k = 1/
37
+ results[1].strip.should =~ /i = 2/
38
+ results[2].strip.should =~ /k = 0 | -1 | -2 | -3 | -4/
39
+ results[3].strip.should =~ /i = 0 | 1 | 2 | 3 | 4/
40
+ end
41
+
42
+ it "should print output in the while loop" do
43
+ source = "def hello
44
+ k = 1
45
+ i = 2
46
+ while true do
47
+ k = (k - 1)
48
+ i = (i + 1)
49
+
50
+ if k < -5
51
+ return k
52
+ end
53
+ end
54
+ end; hello"
55
+
56
+ runner = Instant::Runner.new
57
+ result = runner.run(source)
58
+ result[:status].should == :ok
59
+ results = result[:result].split("\n")
60
+ puts results
61
+
62
+ results.length.should == 4
63
+
64
+ results[0].strip.should =~ /k = 1/
65
+ results[1].strip.should =~ /i = 2/
66
+ results[2].strip.should =~ /k = 0 | -1 | -2 | -3 | -4/
67
+ results[3].strip.should =~ /i = 0 | 1 | 2 | 3 | 4/
68
+ end
69
+ end
70
+ end
metadata CHANGED
@@ -1,18 +1,95 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Ryan Bates
8
+ - Francis Chong
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-04-19 00:00:00.000000000 Z
13
- dependencies: []
14
- description: Generate a unique token with Active Record.
15
- email: ryan@railscasts.com
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ruby2ruby
16
+ requirement: &70096086954740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70096086954740
25
+ - !ruby/object:Gem::Dependency
26
+ name: ruby_parser
27
+ requirement: &70096086954240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.3.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70096086954240
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70096086953720 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.9.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70096086953720
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70096086953200 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70096086953200
58
+ - !ruby/object:Gem::Dependency
59
+ name: echoe
60
+ requirement: &70096086952740 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70096086952740
69
+ - !ruby/object:Gem::Dependency
70
+ name: autotest
71
+ requirement: &70096086952280 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70096086952280
80
+ - !ruby/object:Gem::Dependency
81
+ name: pry
82
+ requirement: &70096086951760 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70096086951760
91
+ description: An experiment on real time visualize development tool.
92
+ email: francis@ignition.hk
16
93
  executables: []
17
94
  extensions: []
18
95
  extra_rdoc_files:
@@ -21,22 +98,23 @@ extra_rdoc_files:
21
98
  - lib/instant/context.rb
22
99
  - lib/instant/processor.rb
23
100
  - lib/instant/runner.rb
24
- - lib/instant/sinatra/app.rb
25
101
  - lib/instant/version.rb
26
102
  files:
27
103
  - Gemfile
28
- - Procfile
104
+ - Manifest
29
105
  - README.md
30
106
  - Rakefile
31
- - instant.gemspec
107
+ - config.ru
32
108
  - lib/instant.rb
33
109
  - lib/instant/context.rb
34
110
  - lib/instant/processor.rb
35
111
  - lib/instant/runner.rb
36
- - lib/instant/sinatra/app.rb
37
112
  - lib/instant/version.rb
38
- - Manifest
39
- homepage: http://github.com/ryanb/uniquify
113
+ - spec/instant/context_spec.rb
114
+ - spec/instant/processor_spec.rb
115
+ - spec/instant/runner_spec.rb
116
+ - instant.gemspec
117
+ homepage: http://github.com/siuying/instant
40
118
  licenses: []
41
119
  post_install_message:
42
120
  rdoc_options:
@@ -65,5 +143,5 @@ rubyforge_project: instant
65
143
  rubygems_version: 1.8.15
66
144
  signing_key:
67
145
  specification_version: 3
68
- summary: Generate a unique token with Active Record.
146
+ summary: An experiment on real time visualize development tool.
69
147
  test_files: []
data/Procfile DELETED
@@ -1 +0,0 @@
1
- server: bundle exec rackup -p $PORT
@@ -1,30 +0,0 @@
1
- require 'json'
2
- require 'sinatra/synchrony'
3
-
4
- module Instant
5
- module Sinatra
6
- class App < ::Sinatra::Base
7
- register ::Sinatra::Synchrony
8
-
9
- set :public_folder, File.expand_path(File.join(File.dirname(__FILE__), "../../../public"))
10
- set :views, File.expand_path(File.join(File.dirname(__FILE__), "../../../views"))
11
-
12
- get '/' do
13
- erb :index
14
- end
15
-
16
- post '/compile' do
17
- content_type :json
18
- source = params[:source]
19
-
20
- puts "source:" + source
21
- if source && source.strip != ""
22
- result = Instant::Runner.new.run(source.strip)
23
- result.to_json
24
- else
25
- {:status => :ok, :result => ""}.to_json
26
- end
27
- end
28
- end
29
- end
30
- end