wirb 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- == 0.2.3
1
+ == 0.2.3 / 0.2.4
2
2
  * Support for rubygems-test <gem-testers.org>
3
3
 
4
4
  == 0.2.2
@@ -1,3 +1,3 @@
1
1
  module Wirb
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -0,0 +1,88 @@
1
+ #require File.dirname(__FILE__) + '/../lib/wirb' unless defined? Wirb
2
+ #require File.dirname(__FILE__) + '/../lib/wirb/wp'
3
+ require 'wirb'
4
+ require 'wirb/wp'
5
+ require 'zucker/engine'
6
+ require 'zucker/version'
7
+
8
+ def tokenizer(filename)
9
+ filename =~ /tokenizer_(.*)_spec\.rb/
10
+ "Wirb.tokenize" + ($1 ? "(#{$1})" : "")
11
+ end
12
+
13
+ def check_value
14
+ Wirb.tokenize(@a).map{|_,c|c}.join.should == @a
15
+ end
16
+
17
+ def please(*args, &block)
18
+ it *args, &block
19
+ end
20
+
21
+ def check(obj)
22
+ @a = obj.inspect
23
+ wp obj
24
+ end
25
+
26
+ def check_inspected(str)
27
+ @a = str
28
+ puts Wirb.colorize_result str
29
+ end
30
+
31
+ def tokens
32
+ Wirb.tokenize(@a).to_a
33
+ end
34
+
35
+ def only19
36
+ yield if RubyVersion == 1.9
37
+ end
38
+
39
+ def only18
40
+ yield if RubyVersion == 1.8
41
+ end
42
+
43
+ # match regex in arrays (e.g. for object ids)
44
+ RSpec::Matchers.define :be_like do |should_array|
45
+ match do |got_array|
46
+ if got_array.size != should_array.size
47
+ false
48
+ else
49
+ got_array.zip(should_array).all? do |(plain_kind, plain_string),(regex_kind, regex_string)|
50
+ regex_kind == plain_kind &&
51
+ regex_string === plain_string
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ RSpec::Matchers.define :be_sorted do |should_array|
58
+ match do |got_array|
59
+ should_array = should_array.sort_by {|x,y|[x.to_s,y]}
60
+ got_array = got_array.sort_by {|x,y|[x.to_s,y]}
61
+ should_array == got_array
62
+ end
63
+ end
64
+
65
+ RSpec::Matchers.define :be_sorted_like do |should_array|
66
+ match do |got_array|
67
+ should_array = should_array.sort_by {|x,y|[x.to_s,y]}
68
+ got_array = got_array.sort_by {|x,y|[x.to_s,y]}
69
+ if got_array.size != should_array.size
70
+ false
71
+ else
72
+ got_array.zip(should_array).all? do
73
+ |(plain_kind, plain_string),(regex_kind, regex_string)|
74
+ regex_kind == plain_kind &&
75
+ regex_string === plain_string
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ # common regex patterns
82
+ OBJECT_ID = /0x[0-9a-f]+/
83
+
84
+ =begin helper methods for getting tokens
85
+ def ws(obj)
86
+ puts Wirb.tokenize(obj.inspect).map{|*x| x.inspect + ','}*$/
87
+ end
88
+ =end
@@ -0,0 +1,31 @@
1
+ describe tokenizer(__FILE__) do
2
+ after :each do check_value end
3
+
4
+ please do check [1,2,3,4]
5
+ tokens.should == [
6
+ [:open_array, "["],
7
+ [:number, "1"],
8
+ [:comma, ","],
9
+ [:whitespace, " "],
10
+ [:number, "2"],
11
+ [:comma, ","],
12
+ [:whitespace, " "],
13
+ [:number, "3"],
14
+ [:comma, ","],
15
+ [:whitespace, " "],
16
+ [:number, "4"],
17
+ [:close_array, "]"]
18
+ ]
19
+ end
20
+
21
+ please do check [[[]]]
22
+ tokens.should == [
23
+ [:open_array, "["],
24
+ [:open_array, "["],
25
+ [:open_array, "["],
26
+ [:close_array, "]"],
27
+ [:close_array, "]"],
28
+ [:close_array, "]"],
29
+ ]
30
+ end
31
+ end
@@ -0,0 +1,148 @@
1
+ describe tokenizer(__FILE__) do
2
+ after :each do check_value end
3
+
4
+ only19 do
5
+ please do check [2,3,4].each
6
+ tokens.should == [
7
+ [:open_object, "#<"],
8
+ [:object_class, "Enumerator"],
9
+ [:object_description_prefix, ":"],
10
+ [:object_description, " "],
11
+ [:open_enumerator, "["],
12
+ [:number, "2"],
13
+ [:comma, ","],
14
+ [:whitespace, " "],
15
+ [:number, "3"],
16
+ [:comma, ","],
17
+ [:whitespace, " "],
18
+ [:number, "4"],
19
+ [:close_enumerator, "]"],
20
+ [:object_description, ":each"],
21
+ [:close_object, ">"],
22
+ ]
23
+ end
24
+
25
+ please do check [2,Set[{1=>2}],4].map
26
+ tokens.should be_like [
27
+ [:open_object, "#<"],
28
+ [:object_class, "Enumerator"],
29
+ [:object_description_prefix, ":"],
30
+ [:object_description, " "],
31
+ [:open_enumerator, "["],
32
+ [:number, "2"],
33
+ [:comma, ","],
34
+ [:whitespace, " "],
35
+ [:open_object, "#<"],
36
+ [:object_class, "Set"],
37
+ [:object_description_prefix, ":"],
38
+ [:whitespace, " "],
39
+ [:open_set, "{"],
40
+ [:open_hash, "{"],
41
+ [:number, "1"],
42
+ [:refers, "=>"],
43
+ [:number, "2"],
44
+ [:close_hash, "}"],
45
+ [:close_set, "}"],
46
+ [:close_object, ">"],
47
+ [:comma, ","],
48
+ [:whitespace, " "],
49
+ [:number, "4"],
50
+ [:close_enumerator, "]"],
51
+ [:object_description, ":map"],
52
+ [:close_object, ">"],
53
+ ]
54
+ end
55
+
56
+ please do check Wirb.tokenize('[2,3,4]')
57
+ tokens.should == [
58
+ [:open_object, "#<"],
59
+ [:object_class, "Enumerator"],
60
+ [:object_description_prefix, ":"],
61
+ [:object_description, " Wirb:tokenize("],
62
+ [:open_string, "\""],
63
+ [:string, "[2,3,4]"],
64
+ [:close_string, "\""],
65
+ [:object_description, ")"],
66
+ [:close_object, ">"],
67
+ ]
68
+ end
69
+
70
+ require 'prime'
71
+ please do check Prime.each
72
+ tokens.should be_like [
73
+ [:open_object, "#<"],
74
+ [:object_class, "Prime"],
75
+ [:class_separator, "::"],
76
+ [:object_class, "EratosthenesGenerator"],
77
+ [:object_description_prefix, ":"],
78
+ [:object_addr, /#{OBJECT_ID}/],
79
+ [:object_description, ' @last_prime=nil, @ubound=nil'],
80
+ [:close_object, ">"],
81
+ ]
82
+ end
83
+
84
+ please do check [{1=>2},Wirb.tokenize('2'),Set[2,3],[3,4],[5,6].each].map
85
+ tokens.should == [
86
+ [:open_object, "#<"],
87
+ [:object_class, "Enumerator"],
88
+ [:object_description_prefix, ":"],
89
+ [:object_description, " "],
90
+ [:open_enumerator, "["],
91
+ [:open_hash, "{"],
92
+ [:number, "1"],
93
+ [:refers, "=>"],
94
+ [:number, "2"],
95
+ [:close_hash, "}"],
96
+ [:comma, ","],
97
+ [:whitespace, " "],
98
+ [:open_object, "#<"],
99
+ [:object_class, "Enumerator"],
100
+ [:object_description_prefix, ":"],
101
+ [:object_description, " Wirb:tokenize("],
102
+ [:open_string, "\""],
103
+ [:string, "2"],
104
+ [:close_string, "\""],
105
+ [:object_description, ")"],
106
+ [:close_object, ">"],
107
+ [:comma, ","],
108
+ [:whitespace, " "],
109
+ [:open_object, "#<"],
110
+ [:object_class, "Set"],
111
+ [:object_description_prefix, ":"],
112
+ [:whitespace, " "],
113
+ [:open_set, "{"],
114
+ [:number, "2"],
115
+ [:comma, ","],
116
+ [:whitespace, " "],
117
+ [:number, "3"],
118
+ [:close_set, "}"],
119
+ [:close_object, ">"],
120
+ [:comma, ","],
121
+ [:whitespace, " "],
122
+ [:open_array, "["],
123
+ [:number, "3"],
124
+ [:comma, ","],
125
+ [:whitespace, " "],
126
+ [:number, "4"],
127
+ [:close_array, "]"],
128
+ [:comma, ","],
129
+ [:whitespace, " "],
130
+ [:open_object, "#<"],
131
+ [:object_class, "Enumerator"],
132
+ [:object_description_prefix, ":"],
133
+ [:object_description, " "],
134
+ [:open_enumerator, "["],
135
+ [:number, "5"],
136
+ [:comma, ","],
137
+ [:whitespace, " "],
138
+ [:number, "6"],
139
+ [:close_enumerator, "]"],
140
+ [:object_description, ":each"],
141
+ [:close_object, ">"],
142
+ [:close_enumerator, "]"],
143
+ [:object_description, ":map"],
144
+ [:close_object, ">"],
145
+ ]
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,65 @@
1
+ require 'set'
2
+
3
+ describe tokenizer(__FILE__) do
4
+ after :each do check_value end
5
+
6
+ please do check( {1=>2} )
7
+ tokens.should == [
8
+ [:open_hash, "{"],
9
+ [:number, "1"],
10
+ [:refers, "=>"],
11
+ [:number, "2"],
12
+ [:close_hash, "}"],
13
+ ]
14
+ end
15
+
16
+ please do check({:hallo => {1=>Set[2,3,4]}})
17
+ tokens.should be_like [
18
+ [:open_hash, "{"],
19
+ [:symbol_prefix, ":"],
20
+ [:symbol, "hallo"],
21
+ [:refers, "=>"],
22
+ [:open_hash, "{"],
23
+ [:number, "1"],
24
+ [:refers, "=>"],
25
+ [:open_object, "#<"],
26
+ [:object_class, "Set"],
27
+ [:object_description_prefix, ":"],
28
+ [:whitespace, " "],
29
+ [:open_set, "{"],
30
+ [:number, /\d+/],
31
+ [:comma, ","],
32
+ [:whitespace, " "],
33
+ [:number, /\d+/],
34
+ [:comma, ","],
35
+ [:whitespace, " "],
36
+ [:number, /\d+/],
37
+ [:close_set, "}"],
38
+ [:close_object, ">"],
39
+ [:close_hash, "}"],
40
+ [:close_hash, "}"],
41
+ ]
42
+ end
43
+
44
+ please do check( {1=>2, 3=>8, {} => {}} )
45
+ tokens.should be_sorted [
46
+ [:close_hash, "}"],
47
+ [:close_hash, "}"],
48
+ [:close_hash, "}"],
49
+ [:comma, ","],
50
+ [:comma, ","],
51
+ [:number, "1"],
52
+ [:number, "2"],
53
+ [:number, "3"],
54
+ [:number, "8"],
55
+ [:open_hash, "{"],
56
+ [:open_hash, "{"],
57
+ [:open_hash, "{"],
58
+ [:refers, "=>"],
59
+ [:refers, "=>"],
60
+ [:refers, "=>"],
61
+ [:whitespace, " "],
62
+ [:whitespace, " "],
63
+ ]
64
+ end
65
+ end
@@ -0,0 +1,70 @@
1
+ # encoding: US-ASCII
2
+ require 'stringio'
3
+ require 'date'
4
+
5
+ describe tokenizer(__FILE__) do
6
+ after :each do check_value end
7
+
8
+ please do check StringIO.new 'wirb'
9
+ if RubyEngine.rbx?
10
+ tokens.should be_like [
11
+ [:open_object, "#<"],
12
+ [:object_class, "StringIO"],
13
+ [:object_description_prefix, ":"],
14
+ [:object_addr, OBJECT_ID],
15
+ [:object_description, /.*/],
16
+ [:open_string, "\""],
17
+ [:string, "wirb"],
18
+ [:close_string, "\""],
19
+ [:object_description, /.*/],
20
+ [:close_object, ">"],
21
+ ]
22
+ else
23
+ tokens.should be_like [
24
+ [:open_object, "#<"],
25
+ [:object_class, "StringIO"],
26
+ [:object_description_prefix, ":"],
27
+ [:object_addr, OBJECT_ID],
28
+ [:close_object, ">"],
29
+ ]
30
+ end
31
+ end
32
+
33
+ please do check Date.today
34
+ tokens.should be_like [
35
+ [:open_object, "#<"],
36
+ [:object_class, "Date"],
37
+ [:object_description_prefix, ":"],
38
+ [:object_description, /.*/],
39
+ [:close_object, ">"],
40
+ ]
41
+ end
42
+
43
+ please do check "communication".match /.*(.)\1.*/
44
+ tokens.should == [
45
+ [:open_object, "#<"],
46
+ [:object_class, "MatchData"],
47
+ [:object_description_prefix, " "],
48
+ [:open_string, "\""],
49
+ [:string, "communication"],
50
+ [:close_string, "\""],
51
+ [:object_description, " 1:"],
52
+ [:open_string, "\""],
53
+ [:string, "m"],
54
+ [:close_string, "\""],
55
+ [:close_object, ">"],
56
+ ]
57
+ end
58
+
59
+ only19 do
60
+ please do check __ENCODING__
61
+ tokens.should == [
62
+ [:open_object, "#<"],
63
+ [:object_class, "Encoding"],
64
+ [:object_description_prefix, ":"],
65
+ [:object_description, "US-ASCII"],
66
+ [:close_object, ">"],
67
+ ]
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,64 @@
1
+ require 'set'
2
+
3
+ describe tokenizer(__FILE__) do
4
+ after :each do check_value end
5
+
6
+ please do check [2,'sdf',:hallosfe, /34jf3/, [[[[]]]], {{5=> "4"} => {Set.new => binding}}]
7
+ tokens.should be_like [
8
+ [:open_array, "["],
9
+ [:number, "2"],
10
+ [:comma, ","],
11
+ [:whitespace, " "],
12
+ [:open_string, "\""],
13
+ [:string, "sdf"],
14
+ [:close_string, "\""],
15
+ [:comma, ","],
16
+ [:whitespace, " "],
17
+ [:symbol_prefix, ":"],
18
+ [:symbol, "hallosfe"],
19
+ [:comma, ","],
20
+ [:whitespace, " "],
21
+ [:open_regexp, "/"],
22
+ [:regexp, "34jf3"],
23
+ [:close_regexp, "/"],
24
+ [:comma, ","],
25
+ [:whitespace, " "],
26
+ [:open_array, "["],
27
+ [:open_array, "["],
28
+ [:open_array, "["],
29
+ [:open_array, "["],
30
+ [:close_array, "]"],
31
+ [:close_array, "]"],
32
+ [:close_array, "]"],
33
+ [:close_array, "]"],
34
+ [:comma, ","],
35
+ [:whitespace, " "],
36
+ [:open_hash, "{"],
37
+ [:open_hash, "{"],
38
+ [:number, "5"],
39
+ [:refers, "=>"],
40
+ [:open_string, "\""],
41
+ [:string, "4"],
42
+ [:close_string, "\""],
43
+ [:close_hash, "}"],
44
+ [:refers, "=>"],
45
+ [:open_hash, "{"],
46
+ [:open_object, "#<"],
47
+ [:object_class, "Set"],
48
+ [:object_description_prefix, ":"],
49
+ [:whitespace, " "],
50
+ [:open_set, "{"],
51
+ [:close_set, "}"],
52
+ [:close_object, ">"],
53
+ [:refers, "=>"],
54
+ [:open_object, "#<"],
55
+ [:object_class, "Binding"],
56
+ [:object_description_prefix, ":"],
57
+ [:object_addr, OBJECT_ID],
58
+ [:close_object, ">"],
59
+ [:close_hash, "}"],
60
+ [:close_hash, "}"],
61
+ [:close_array, "]"],
62
+ ]
63
+ end
64
+ end
@@ -0,0 +1,15 @@
1
+ describe 'Wirb.tokenize' do
2
+ after :each do check_value end
3
+
4
+ please do check true
5
+ tokens.should == [[:true, "true"]]
6
+ end
7
+
8
+ please do check false
9
+ tokens.should == [[:false, "false"]]
10
+ end
11
+
12
+ please do check nil
13
+ tokens.should == [[:nil, "nil"]]
14
+ end
15
+ end
@@ -0,0 +1,104 @@
1
+ describe tokenizer(__FILE__) do
2
+ after :each do check_value end
3
+
4
+ please do check 42
5
+ tokens.should == [[:number, "42"]]
6
+ end
7
+
8
+ please do check [1..2, 3...4, 'a'..'z', 'a'...'z']
9
+ tokens.should == [
10
+ [:open_array, "["],
11
+ [:number, "1"],
12
+ [:range, ".."],
13
+ [:number, "2"],
14
+ [:comma, ","],
15
+ [:whitespace, " "],
16
+ [:number, "3"],
17
+ [:range, "..."],
18
+ [:number, "4"],
19
+ [:comma, ","],
20
+ [:whitespace, " "],
21
+ [:open_string, "\""],
22
+ [:string, "a"],
23
+ [:close_string, "\""],
24
+ [:range, ".."],
25
+ [:open_string, "\""],
26
+ [:string, "z"],
27
+ [:close_string, "\""],
28
+ [:comma, ","],
29
+ [:whitespace, " "],
30
+ [:open_string, "\""],
31
+ [:string, "a"],
32
+ [:close_string, "\""],
33
+ [:range, "..."],
34
+ [:open_string, "\""],
35
+ [:string, "z"],
36
+ [:close_string, "\""],
37
+ [:close_array, "]"],
38
+ ]
39
+ end
40
+
41
+ please do check [2, 3, 4.0, -3, 99e99, 1e-99, 2_3_4, 4E8]
42
+ tokens.should == [
43
+ [:open_array, "["],
44
+ [:number, "2"],
45
+ [:comma, ","],
46
+ [:whitespace, " "],
47
+ [:number, "3"],
48
+ [:comma, ","],
49
+ [:whitespace, " "],
50
+ [:number, "4.0"],
51
+ [:comma, ","],
52
+ [:whitespace, " "],
53
+ [:number, "-3"],
54
+ [:comma, ","],
55
+ [:whitespace, " "],
56
+ [:number, "9.9e+100"],
57
+ [:comma, ","],
58
+ [:whitespace, " "],
59
+ [:number, "1.0e-99"],
60
+ [:comma, ","],
61
+ [:whitespace, " "],
62
+ [:number, "234"],
63
+ [:comma, ","],
64
+ [:whitespace, " "],
65
+ [:number, "400000000.0"],
66
+ [:close_array, "]"],
67
+ ]
68
+ end
69
+
70
+ only19 do
71
+ please do check Rational(2,3)
72
+ tokens.should == [
73
+ [:open_rational, "("],
74
+ [:number, "2"],
75
+ [:rational_separator, "/"],
76
+ [:number, "3"],
77
+ [:close_rational, ")"],
78
+ ]
79
+ end
80
+ end
81
+
82
+ only18 do
83
+ please do check Rational(2,3)
84
+ tokens.should == [
85
+ [:class, "Rational"],
86
+ [:open_rational, "("],
87
+ [:number, "2"],
88
+ [:rational_separator, ","],
89
+ [:whitespace, " "],
90
+ [:number, "3"],
91
+ [:close_rational, ")"],
92
+ ]
93
+
94
+ # modifying the world, see https://github.com/janlelis/wirb/issues#issue/1
95
+ require 'mathn'
96
+ check Rational(2,3)
97
+ tokens.should == [
98
+ [:number, "2"],
99
+ [:rational_separator, "/"],
100
+ [:number, "3"],
101
+ ]
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,108 @@
1
+ require 'ostruct'
2
+
3
+ describe tokenizer(__FILE__) do
4
+ after :each do check_value end
5
+
6
+ please do check Object.new
7
+ tokens.should be_like [
8
+ [:open_object, "#<"],
9
+ [:object_class, "Object"],
10
+ [:object_description_prefix, ":"],
11
+ [:object_addr, OBJECT_ID],
12
+ [:close_object, ">"],
13
+ ]
14
+ end
15
+
16
+ please do check proc{}
17
+ tokens.should be_like [
18
+ [:open_object, "#<"],
19
+ [:object_class, "Proc"],
20
+ [:object_description_prefix, ":"],
21
+ [:object_addr, OBJECT_ID],
22
+ [:object_line_prefix, "@"],
23
+ [:object_line, /.*tokenizer_object_spec.rb:/],
24
+ [:object_line_number, /\d+/],
25
+ [:close_object, ">"],
26
+ ]
27
+ end
28
+
29
+ please do check lambda{}
30
+ tokens.should be_like [
31
+ [:open_object, "#<"],
32
+ [:object_class, "Proc"],
33
+ [:object_description_prefix, ":"],
34
+ [:object_addr, OBJECT_ID],
35
+ [:object_line_prefix, "@"],
36
+ [:object_line, /.*tokenizer_object_spec.rb:/],
37
+ [:object_line_number, /\d+/],
38
+ RubyVersion == 1.9 ? [:object_description, " (lambda)"] : nil,
39
+ [:close_object, ">"],
40
+ ].compact
41
+ end
42
+
43
+ unless RubyEngine.rbx? # rubinius provides more information
44
+ please do check binding
45
+ tokens.should be_like [
46
+ [:open_object, "#<"],
47
+ [:object_class, "Binding"],
48
+ [:object_description_prefix, ":"],
49
+ [:object_addr, OBJECT_ID],
50
+ [:close_object, ">"],
51
+ ]
52
+ end
53
+ end
54
+
55
+ only19 do
56
+ please do check STDOUT
57
+ tokens.should == [
58
+ [:open_object, "#<"],
59
+ [:object_class, "IO"],
60
+ [:object_description_prefix, ":"],
61
+ [:object_description, "<STDOUT>"],
62
+ [:close_object, ">"],
63
+ ]
64
+ end
65
+
66
+ please do check STDIN
67
+ tokens.should == [
68
+ [:open_object, "#<"],
69
+ [:object_class, "IO"],
70
+ [:object_description_prefix, ":"],
71
+ [:object_description, "<STDIN>"],
72
+ [:close_object, ">"],
73
+ ]
74
+ end
75
+
76
+ please do check Module.new.singleton_class.singleton_class
77
+ tokens.should be_like [
78
+ [:open_object, "#<"],
79
+ [:object_class, "Class"],
80
+ [:object_description_prefix, ":"],
81
+ [:object_description, '#<Class:#<Module:'],
82
+ [:object_addr, OBJECT_ID],
83
+ [:object_description, '>>'],
84
+ [:close_object, ">"]
85
+ ]
86
+ end
87
+ end
88
+
89
+ please do
90
+ SomeStruct=Struct.new :favourite, :language
91
+ check SomeStruct.new :ruby
92
+ tokens.should == [
93
+ [:open_object, "#<"],
94
+ [:object_class, "struct"],
95
+ [:object_description_prefix, " "],
96
+ [:object_description, "SomeStruct favourite=:ruby, language=nil"],
97
+ [:close_object, ">"],
98
+ ]
99
+ end
100
+
101
+ please do check OpenStruct.new
102
+ tokens.should be_like [
103
+ [:open_object, "#<"],
104
+ [:object_class, "OpenStruct"],
105
+ [:close_object, ">"],
106
+ ]
107
+ end
108
+ end
@@ -0,0 +1,19 @@
1
+ # only very basic support so far.. open issues ;)
2
+
3
+ describe tokenizer(__FILE__) do
4
+ after :each do check_value end
5
+
6
+ please do check_inspected "User(Table doesn't exist)"
7
+ tokens.should == [
8
+ [:class, "User"],
9
+ [:object_description, "(Table doesn't exist)"],
10
+ ]
11
+ end
12
+
13
+ please do check_inspected "User(id: integer, name: string, created_at: datetime, updated_at: datetime)"
14
+ tokens.should == [
15
+ [:class, "User"],
16
+ [:object_description, "(id: integer, name: string, created_at: datetime, updated_at: datetime)"],
17
+ ]
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ describe tokenizer(__FILE__) do
2
+ after :each do check_value end
3
+
4
+ please do check /music/
5
+ tokens.should == [[:open_regexp, "/"], [:regexp, "music"], [:close_regexp, "/"]]
6
+ end
7
+
8
+ please do check /music/mix
9
+ tokens.should == [[:open_regexp, "/"], [:regexp, "music"], [:close_regexp, "/"], [:regexp_flags, "mix"]]
10
+ end
11
+
12
+ please do check /mus\/ic/
13
+ tokens.should == [[:open_regexp, "/"], [:regexp, "mus\\/ic"], [:close_regexp, "/"]]
14
+ end
15
+
16
+ please do check /\b([A-Z0-9._%+-]+)@([A-Z0-9.-]+\.[A-Z]{2,4})\b/i
17
+ tokens.should == [
18
+ [:open_regexp, "/"],
19
+ [:regexp, "\\b([A-Z0-9._%+-]+)@([A-Z0-9.-]+\\.[A-Z]{2,4})\\b"],
20
+ [:close_regexp, "/"],
21
+ [:regexp_flags, "i"],
22
+ ]
23
+ end
24
+ end
@@ -0,0 +1,53 @@
1
+ require 'set'
2
+
3
+ describe tokenizer(__FILE__) do
4
+ after :each do check_value end
5
+
6
+ please do check Set[2,3,4]
7
+ tokens.should be_like [
8
+ [:open_object, "#<"],
9
+ [:object_class, "Set"],
10
+ [:object_description_prefix, ":"],
11
+ [:whitespace, " "],
12
+ [:open_set, "{"],
13
+ [:number, /\d/],
14
+ [:comma, ","],
15
+ [:whitespace, " "],
16
+ [:number, /\d/],
17
+ [:comma, ","],
18
+ [:whitespace, " "],
19
+ [:number, /\d/],
20
+ [:close_set, "}"],
21
+ [:close_object, ">"],
22
+ ]
23
+ end
24
+
25
+ please do check Set[[2,3], {1=>{2=>3}}]
26
+ tokens.should be_sorted [
27
+ [:close_array, "]"],
28
+ [:close_hash, "}"],
29
+ [:close_hash, "}"],
30
+ [:close_object, ">"],
31
+ [:close_set, "}"],
32
+ [:comma, ","],
33
+ [:comma, ","],
34
+ [:number, "1"],
35
+ [:number, "2"],
36
+ [:number, "2"],
37
+ [:number, "3"],
38
+ [:number, "3"],
39
+ [:object_class, "Set"],
40
+ [:object_description_prefix, ":"],
41
+ [:open_array, "["],
42
+ [:open_hash, "{"],
43
+ [:open_hash, "{"],
44
+ [:open_object, "#<"],
45
+ [:open_set, "{"],
46
+ [:refers, "=>"],
47
+ [:refers, "=>"],
48
+ [:whitespace, " "],
49
+ [:whitespace, " "],
50
+ [:whitespace, " "],
51
+ ]
52
+ end
53
+ end
@@ -0,0 +1,11 @@
1
+ describe tokenizer(__FILE__) do
2
+ after :each do check_value end
3
+
4
+ please do check "always, again."
5
+ tokens.should == [[:open_string, '"'], [:string, "always, again."], [:close_string, '"']]
6
+ end
7
+
8
+ please do check '"quote"'
9
+ tokens.should == [[:open_string, '"'], [:string, "\\\"quote\\\""], [:close_string, '"']]
10
+ end
11
+ end
@@ -0,0 +1,112 @@
1
+ describe tokenizer(__FILE__) do
2
+ after :each do check_value end
3
+
4
+ please do check %w|a ab ab0 ab= < > * + <=> <= >= == =~ __send__ is_a? [] []= |.map(&:to_sym)
5
+ tokens.should == [
6
+ [:open_array, "["],
7
+ [:symbol_prefix, ":"],
8
+ [:symbol, "a"],
9
+ [:comma, ","],
10
+ [:whitespace, " "],
11
+ [:symbol_prefix, ":"],
12
+ [:symbol, "ab"],
13
+ [:comma, ","],
14
+ [:whitespace, " "],
15
+ [:symbol_prefix, ":"],
16
+ [:symbol, "ab0"],
17
+ [:comma, ","],
18
+ [:whitespace, " "],
19
+ [:symbol_prefix, ":"],
20
+ [:symbol, "ab="],
21
+ [:comma, ","],
22
+ [:whitespace, " "],
23
+ [:symbol_prefix, ":"],
24
+ [:symbol, "<"],
25
+ [:comma, ","],
26
+ [:whitespace, " "],
27
+ [:symbol_prefix, ":"],
28
+ [:symbol, ">"],
29
+ [:comma, ","],
30
+ [:whitespace, " "],
31
+ [:symbol_prefix, ":"],
32
+ [:symbol, "*"],
33
+ [:comma, ","],
34
+ [:whitespace, " "],
35
+ [:symbol_prefix, ":"],
36
+ [:symbol, "+"],
37
+ [:comma, ","],
38
+ [:whitespace, " "],
39
+ [:symbol_prefix, ":"],
40
+ [:symbol, "<=>"],
41
+ [:comma, ","],
42
+ [:whitespace, " "],
43
+ [:symbol_prefix, ":"],
44
+ [:symbol, "<="],
45
+ [:comma, ","],
46
+ [:whitespace, " "],
47
+ [:symbol_prefix, ":"],
48
+ [:symbol, ">="],
49
+ [:comma, ","],
50
+ [:whitespace, " "],
51
+ [:symbol_prefix, ":"],
52
+ [:symbol, "=="],
53
+ [:comma, ","],
54
+ [:whitespace, " "],
55
+ [:symbol_prefix, ":"],
56
+ [:symbol, "=~"],
57
+ [:comma, ","],
58
+ [:whitespace, " "],
59
+ [:symbol_prefix, ":"],
60
+ [:symbol, "__send__"],
61
+ [:comma, ","],
62
+ [:whitespace, " "],
63
+ [:symbol_prefix, ":"],
64
+ [:symbol, "is_a?"],
65
+ [:comma, ","],
66
+ [:whitespace, " "],
67
+ [:symbol_prefix, ":"],
68
+ [:symbol, "[]"],
69
+ [:comma, ","],
70
+ [:whitespace, " "],
71
+ [:symbol_prefix, ":"],
72
+ [:symbol, "[]="],
73
+ [:close_array, "]"],
74
+ ]
75
+ end
76
+
77
+ please do check :'hello"word'
78
+ tokens.should == [
79
+ [:symbol_prefix, ":"], [:open_symbol_string, "\""],
80
+ [:symbol_string, "hello\\\"word"], [:close_symbol_string, "\""]
81
+ ]
82
+ end
83
+
84
+ please do check [[:hallo],{:'hallo'=>:'test'}, {:'hallo='=>:'test='}]
85
+ tokens.should == [
86
+ [:open_array, "["],
87
+ [:open_array, "["],
88
+ [:symbol_prefix, ":"],
89
+ [:symbol, "hallo"],
90
+ [:close_array, "]"],
91
+ [:comma, ","],
92
+ [:whitespace, " "],
93
+ [:open_hash, "{"],
94
+ [:symbol_prefix, ":"],
95
+ [:symbol, "hallo"],
96
+ [:refers, "=>"],
97
+ [:symbol_prefix, ":"],
98
+ [:symbol, "test"],
99
+ [:close_hash, "}"],
100
+ [:comma, ","],
101
+ [:whitespace, " "],
102
+ [:open_hash, "{"],
103
+ [:symbol_prefix, ":"],
104
+ [:symbol, "hallo="],
105
+ [:refers, "=>"],
106
+ [:symbol_prefix, ":"],
107
+ [:symbol, "test="],
108
+ [:close_hash, "}"],
109
+ [:close_array, "]"],
110
+ ]
111
+ end
112
+ end
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.description = "Colorizes your irb results. It's based on Wirble but only provides result highlighting. Just call Wirb.start and enjoy the colors ;)."
13
13
  s.required_rubygems_version = '>= 1.3.6'
14
14
  s.required_ruby_version = '>= 1.8.7'
15
- s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile wirb.gemspec .gemtest}
15
+ s.files = Dir.glob(%w[{lib,test,spec}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile wirb.gemspec .gemtest}
16
16
  s.extra_rdoc_files = ["README.rdoc", "COPYING"]
17
17
  s.license = 'MIT'
18
18
  s.add_development_dependency 'rspec'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Lelis
@@ -73,6 +73,20 @@ files:
73
73
  - lib/wirb/colors.rb
74
74
  - lib/wirb/version.rb
75
75
  - lib/wirb/irb.rb
76
+ - spec/tokenizer_rails_spec.rb
77
+ - spec/tokenizer_hash_spec.rb
78
+ - spec/tokenizer_number_spec.rb
79
+ - spec/tokenizer_regexp_spec.rb
80
+ - spec/tokenizer_array_spec.rb
81
+ - spec/tokenizer_enumerator_spec.rb
82
+ - spec/spec_helper.rb
83
+ - spec/tokenizer_misc_spec.rb
84
+ - spec/tokenizer_nil_false_true_spec.rb
85
+ - spec/tokenizer_symbol_spec.rb
86
+ - spec/tokenizer_set_spec.rb
87
+ - spec/tokenizer_object_spec.rb
88
+ - spec/tokenizer_nested_spec.rb
89
+ - spec/tokenizer_string_spec.rb
76
90
  - README.rdoc
77
91
  - CHANGELOG.rdoc
78
92
  - Rakefile