eden 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/CHANGELOG +4 -0
  2. data/LICENSE +20 -0
  3. data/README.md +48 -0
  4. data/Rakefile +10 -0
  5. data/bin/eden +132 -0
  6. data/lib/eden.rb +10 -0
  7. data/lib/eden/defaults.rb +26 -0
  8. data/lib/eden/formatter.rb +25 -0
  9. data/lib/eden/formatters/block_formatter.rb +45 -0
  10. data/lib/eden/formatters/indenter.rb +91 -0
  11. data/lib/eden/formatters/white_space_cleaner.rb +14 -0
  12. data/lib/eden/line.rb +65 -0
  13. data/lib/eden/source_file.rb +32 -0
  14. data/lib/eden/token.rb +62 -0
  15. data/lib/eden/tokenizer.rb +259 -0
  16. data/lib/eden/tokenizers/basic_tokenizer.rb +167 -0
  17. data/lib/eden/tokenizers/delimited_literal_tokenizer.rb +38 -0
  18. data/lib/eden/tokenizers/number_tokenizer.rb +68 -0
  19. data/lib/eden/tokenizers/operator_tokenizer.rb +211 -0
  20. data/lib/eden/tokenizers/regex_tokenizer.rb +37 -0
  21. data/lib/eden/tokenizers/string_tokenizer.rb +149 -0
  22. data/test/array_literal_tokenization_test.rb +43 -0
  23. data/test/basic_tokenization_test.rb +29 -0
  24. data/test/block_formatter_test.rb +47 -0
  25. data/test/class_var_token_test.rb +21 -0
  26. data/test/identifier_token_test.rb +140 -0
  27. data/test/indenter_test.rb +314 -0
  28. data/test/instance_var_token_test.rb +48 -0
  29. data/test/number_tokenization_test.rb +83 -0
  30. data/test/operator_tokenization_test.rb +180 -0
  31. data/test/regex_tokenization_test.rb +68 -0
  32. data/test/single_character_tokenization_test.rb +87 -0
  33. data/test/string_tokenization_test.rb +291 -0
  34. data/test/symbol_tokenization_test.rb +64 -0
  35. data/test/test_helper.rb +13 -0
  36. data/test/white_space_cleaner_test.rb +35 -0
  37. data/test/whitespace_token_test.rb +63 -0
  38. metadata +108 -0
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + "/test_helper.rb"
2
+
3
+ class ArrayLiteralTokenizationTest < Test::Unit::TestCase
4
+ def setup
5
+ @sf = Eden::SourceFile.new( "dummy.rb" )
6
+ end
7
+
8
+ def test_array_literal_tokenization
9
+ @sf.stubs(:source).returns("%w{rah rah rah}\n%w<rah <rah> rah>")
10
+ @sf.tokenize!
11
+ tokens = @sf.lines[0].tokens
12
+ assert_equal 2, tokens.size
13
+ assert_equal :array_literal, tokens[0].type
14
+ assert_equal "%w{rah rah rah}", tokens[0].content
15
+ tokens = @sf.lines[1].tokens
16
+ assert_equal :array_literal, tokens[0].type
17
+ assert_equal "%w<rah <rah> rah>", tokens[0].content
18
+ end
19
+
20
+ def test_should_not_expand_delimited_array_literal
21
+ @sf.stubs(:source).returns("%w{rah \#{@inst} rah}\n")
22
+ @sf.tokenize!
23
+ tokens = @sf.lines[0].tokens
24
+ assert_equal 2, tokens.size
25
+ assert_equal :array_literal, tokens[0].type
26
+ assert_equal "%w{rah \#{@inst} rah}", tokens[0].content
27
+ end
28
+
29
+ def test_should_tokenize_expanded_array_literal
30
+ @sf.stubs(:source).returns("%W{rah \#{@inst} rah}\n")
31
+ @sf.tokenize!
32
+ tokens = @sf.lines[0].tokens
33
+ assert_equal 6, tokens.size
34
+ assert_equal :array_literal, tokens[0].type
35
+ assert_equal "%W{rah \#", tokens[0].content
36
+ assert_equal :lcurly, tokens[1].type
37
+ assert_equal :instancevar, tokens[2].type
38
+ assert_equal "@inst", tokens[2].content
39
+ assert_equal :rcurly, tokens[3].type
40
+ assert_equal :array_literal, tokens[4].type
41
+ assert_equal " rah}", tokens[4].content
42
+ end
43
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + "/test_helper"
2
+
3
+ class BasicTokenizationTest < Test::Unit::TestCase
4
+ def setup
5
+ @sf = Eden::SourceFile.new("dummy.rb")
6
+ end
7
+
8
+ def test_should_tokenize_linebreak_escape
9
+ @sf.stubs(:source).returns("puts \\\n 'rah'")
10
+ @sf.tokenize!
11
+ tokens = @sf.lines[0].tokens
12
+ assert_equal 4, tokens.size
13
+ assert_equal :backslash, tokens[2].type
14
+ assert_equal :newline, tokens[3].type
15
+ end
16
+
17
+ def test_should_tokenize_question_mark_character_literals
18
+ @sf.stubs(:source).returns("?a ?} ?\u2332\n")
19
+ @sf.tokenize!
20
+ tokens = @sf.lines[0].tokens
21
+ assert_equal 6, tokens.size
22
+ assert_equal :character_literal, tokens[0].type
23
+ assert_equal "?a", tokens[0].content
24
+ assert_equal :character_literal, tokens[2].type
25
+ assert_equal "?}", tokens[2].content
26
+ assert_equal :character_literal, tokens[4].type
27
+ assert_equal "?\u2332", tokens[4].content
28
+ end
29
+ end
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + "/test_helper.rb"
2
+ require File.dirname(__FILE__) + "/../lib/eden/formatters/block_formatter"
3
+
4
+ class BlockFormatterTest < Test::Unit::TestCase
5
+ def setup
6
+ @sf = Eden::SourceFile.new("dummy.rb")
7
+ end
8
+
9
+ def test_should_add_spaces_in_block
10
+ @sf.stubs(:source).returns("things.map {|th|th+1}\n")
11
+ @sf.tokenize!
12
+ BlockFormatter.format( @sf )
13
+ assert_equal @sf.lines[0].joined_tokens, "things.map { |th|th+1 }\n"
14
+ end
15
+
16
+ def test_should_not_change_block_when_disabled
17
+ BlockFormatter.configure do |b|
18
+ b.adjust_blocks false
19
+ end
20
+
21
+ @sf.stubs(:source).returns("things.map {|th|th+1}\n")
22
+ @sf.tokenize!
23
+ BlockFormatter.format( @sf )
24
+ assert_equal @sf.lines[0].joined_tokens, "things.map {|th|th+1}\n"
25
+
26
+ BlockFormatter.configure do |b|
27
+ b.adjust_blocks true
28
+ end
29
+ end
30
+
31
+ def test_should_use_correct_number_of_correct_characters
32
+ BlockFormatter.configure do |b|
33
+ b.padding_character "t"
34
+ b.padding_character_count 2
35
+ end
36
+
37
+ @sf.stubs(:source).returns("things.map {|th|th+1}\n")
38
+ @sf.tokenize!
39
+ BlockFormatter.format( @sf )
40
+ assert_equal @sf.lines[0].joined_tokens, "things.map {tt|th|th+1tt}\n"
41
+
42
+ BlockFormatter.configure do |b|
43
+ b.padding_character " "
44
+ b.padding_character_count 1
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + "/test_helper.rb"
2
+
3
+ class IdentifierTokenTest < Test::Unit::TestCase
4
+ def setup
5
+ @sf = Eden::SourceFile.new( "dummy.rb" )
6
+ end
7
+
8
+ def test_instance_var__tokenization
9
+ @sf.stubs(:source).returns("@@token @@_token @@token2")
10
+ @sf.tokenize!
11
+ line = @sf.lines[0]
12
+ assert_equal 5, line.tokens.size
13
+ assert_equal "@@token", line.tokens[0].content
14
+ assert_equal :classvar, line.tokens[0].type
15
+ assert_equal "@@_token", line.tokens[2].content
16
+ assert_equal :classvar, line.tokens[2].type
17
+ assert_equal "@@token2", line.tokens[4].content
18
+ assert_equal :classvar, line.tokens[4].type
19
+ end
20
+
21
+ end
@@ -0,0 +1,140 @@
1
+ require File.dirname(__FILE__) + "/test_helper.rb"
2
+
3
+ class IdentifierTokenTest < Test::Unit::TestCase
4
+ def setup
5
+ @sf = Eden::SourceFile.new( "dummy.rb" )
6
+ end
7
+
8
+ def test_leading_underscore_identifier_tokenization
9
+ @sf.stubs(:source).returns(" _token")
10
+ @sf.tokenize!
11
+ line = @sf.lines[0]
12
+ assert_equal 2, line.tokens.size
13
+ assert_equal "_token", line.tokens[1].content
14
+ assert_equal :identifier, line.tokens[1].type
15
+ end
16
+
17
+ def test_multiple_token_tokenization
18
+ @sf.stubs(:source).returns("token other_token")
19
+ @sf.tokenize!
20
+ line = @sf.lines[0]
21
+ assert_equal 3, line.tokens.size
22
+ assert_equal "token", line.tokens[0].content
23
+ assert_equal :identifier, line.tokens[0].type
24
+ assert_equal "other_token", line.tokens[2].content
25
+ assert_equal :identifier, line.tokens[2].type
26
+ end
27
+
28
+ def test_keyword_tokenization_1
29
+ @sf.stubs(:source).returns("__FILE__ __ENCODING__ __LINE__ BEGIN END")
30
+ @sf.tokenize!
31
+ tokens = @sf.lines[0].tokens
32
+ assert_equal 9, tokens.size
33
+ assert_equal :__file__, tokens[0].type
34
+ assert_equal "__FILE__", tokens[0].content
35
+ assert_equal :__encoding__, tokens[2].type
36
+ assert_equal "__ENCODING__", tokens[2].content
37
+ assert_equal :__line__, tokens[4].type
38
+ assert_equal "__LINE__", tokens[4].content
39
+ assert_equal :begin_global, tokens[6].type
40
+ assert_equal "BEGIN", tokens[6].content
41
+ assert_equal :end_global, tokens[8].type
42
+ assert_equal "END", tokens[8].content
43
+ end
44
+
45
+ def test_keyword_tokenization_2
46
+ @sf.stubs(:source).returns("alias and begin break case class def do end")
47
+ @sf.tokenize!
48
+ tokens = @sf.lines[0].tokens
49
+ assert_equal 17, tokens.size
50
+ assert_equal :alias, tokens[0].type
51
+ assert_equal "alias", tokens[0].content
52
+ assert_equal :and, tokens[2].type
53
+ assert_equal "and", tokens[2].content
54
+ assert_equal :begin, tokens[4].type
55
+ assert_equal "begin", tokens[4].content
56
+ assert_equal :break, tokens[6].type
57
+ assert_equal "break", tokens[6].content
58
+ assert_equal :case, tokens[8].type
59
+ assert_equal "case", tokens[8].content
60
+ assert_equal :class, tokens[10].type
61
+ assert_equal "class", tokens[10].content
62
+ assert_equal :def, tokens[12].type
63
+ assert_equal "def", tokens[12].content
64
+ assert_equal :do, tokens[14].type
65
+ assert_equal "do", tokens[14].content
66
+ assert_equal :end, tokens[16].type
67
+ assert_equal "end", tokens[16].content
68
+ end
69
+
70
+ def test_keyword_tokenization_3
71
+ @sf.stubs(:source).returns("else elsif ensure for false if in module")
72
+ @sf.tokenize!
73
+ tokens = @sf.lines[0].tokens
74
+ assert_equal 15, tokens.size
75
+ assert_equal :else, tokens[0].type
76
+ assert_equal "else", tokens[0].content
77
+ assert_equal :elsif, tokens[2].type
78
+ assert_equal "elsif", tokens[2].content
79
+ assert_equal :ensure, tokens[4].type
80
+ assert_equal "ensure", tokens[4].content
81
+ assert_equal :for, tokens[6].type
82
+ assert_equal "for", tokens[6].content
83
+ assert_equal :false, tokens[8].type
84
+ assert_equal "false", tokens[8].content
85
+ assert_equal :if, tokens[10].type
86
+ assert_equal "if", tokens[10].content
87
+ assert_equal :in, tokens[12].type
88
+ assert_equal "in", tokens[12].content
89
+ assert_equal :module, tokens[14].type
90
+ assert_equal "module", tokens[14].content
91
+ end
92
+
93
+ def test_keyword_tokenization_4
94
+ @sf.stubs(:source).returns("next nil not or redo rescue retry return super")
95
+ @sf.tokenize!
96
+ tokens = @sf.lines[0].tokens
97
+ assert_equal 17, tokens.size
98
+ assert_equal :next, tokens[0].type
99
+ assert_equal "next", tokens[0].content
100
+ assert_equal :nil, tokens[2].type
101
+ assert_equal "nil", tokens[2].content
102
+ assert_equal :not, tokens[4].type
103
+ assert_equal "not", tokens[4].content
104
+ assert_equal :or, tokens[6].type
105
+ assert_equal "or", tokens[6].content
106
+ assert_equal :redo, tokens[8].type
107
+ assert_equal "redo", tokens[8].content
108
+ assert_equal :rescue, tokens[10].type
109
+ assert_equal "rescue", tokens[10].content
110
+ assert_equal :retry, tokens[12].type
111
+ assert_equal "retry", tokens[12].content
112
+ assert_equal :return, tokens[14].type
113
+ assert_equal "return", tokens[14].content
114
+ assert_equal :super, tokens[16].type
115
+ assert_equal "super", tokens[16].content
116
+ end
117
+
118
+ def test_keyword_tokenization_5
119
+ @sf.stubs(:source).returns("then true undef unless until when while yield")
120
+ @sf.tokenize!
121
+ tokens = @sf.lines[0].tokens
122
+ assert_equal 15, tokens.size
123
+ assert_equal :then, tokens[0].type
124
+ assert_equal "then", tokens[0].content
125
+ assert_equal :true, tokens[2].type
126
+ assert_equal "true", tokens[2].content
127
+ assert_equal :undef, tokens[4].type
128
+ assert_equal "undef", tokens[4].content
129
+ assert_equal :unless, tokens[6].type
130
+ assert_equal "unless", tokens[6].content
131
+ assert_equal :until, tokens[8].type
132
+ assert_equal "until", tokens[8].content
133
+ assert_equal :when, tokens[10].type
134
+ assert_equal "when", tokens[10].content
135
+ assert_equal :while, tokens[12].type
136
+ assert_equal "while", tokens[12].content
137
+ assert_equal :yield, tokens[14].type
138
+ assert_equal "yield", tokens[14].content
139
+ end
140
+ end
@@ -0,0 +1,314 @@
1
+ require File.dirname(__FILE__) + "/test_helper"
2
+ require File.dirname(__FILE__) + "/../lib/eden/formatters/indenter.rb"
3
+
4
+ class IndenterTest < Test::Unit::TestCase
5
+ def setup
6
+ @sf = Eden::SourceFile.new( "dummy.rb" )
7
+ end
8
+
9
+ def test_should_not_indent_when_not_configured
10
+ Indenter.configure do |i|
11
+ i.adjust_indents false
12
+ end
13
+
14
+ @sf.stubs(:source).returns("def function\nreturn nil\nend\n")
15
+ @sf.tokenize!
16
+ Indenter.format( @sf )
17
+ assert_equal "def function\n", @sf.lines[0].joined_tokens
18
+ assert_equal "return nil\n", @sf.lines[1].joined_tokens
19
+ assert_equal "end\n", @sf.lines[2].joined_tokens
20
+
21
+ Indenter.configure do |i|
22
+ i.adjust_indents true
23
+ end
24
+ end
25
+
26
+ def test_should_use_correct_indent_character_when_indenting
27
+ Indenter.configure do |i|
28
+ i.indent_character "\t"
29
+ i.indent_characters_per_step 1
30
+ end
31
+
32
+ @sf.stubs(:source).returns("def function\nreturn nil\nend\n")
33
+ @sf.tokenize!
34
+ Indenter.format( @sf )
35
+ assert_equal "def function\n", @sf.lines[0].joined_tokens
36
+ assert_equal "\treturn nil\n", @sf.lines[1].joined_tokens
37
+ assert_equal "end\n", @sf.lines[2].joined_tokens
38
+
39
+ Indenter.configure do |i|
40
+ i.indent_character " "
41
+ i.indent_characters_per_step 2
42
+ end
43
+ end
44
+
45
+ def test_should_not_indent_heredoc
46
+ @sf.stubs(:source).returns(<<-SOURCE)
47
+ class Test
48
+ def function
49
+ rah = <<-HEREDOC
50
+ rah234
51
+ HEREDOC
52
+ end
53
+ end
54
+ SOURCE
55
+ @sf.tokenize!
56
+ Indenter.format( @sf )
57
+ assert_equal "class Test\n", @sf.lines[0].joined_tokens
58
+ assert_equal " def function\n", @sf.lines[1].joined_tokens
59
+ assert_equal " rah = <<-HEREDOC\n", @sf.lines[2].joined_tokens
60
+ assert_equal "rah234\nHEREDOC\n", @sf.lines[3].joined_tokens
61
+ assert_equal " end\n", @sf.lines[4].joined_tokens
62
+ assert_equal "end\n", @sf.lines[5].joined_tokens
63
+ end
64
+
65
+ def test_should_indent_function_body
66
+ @sf.stubs(:source).returns("def function\nreturn nil\nend\n")
67
+ @sf.tokenize!
68
+ Indenter.format( @sf )
69
+ assert_equal "def function\n", @sf.lines[0].joined_tokens
70
+ assert_equal " return nil\n", @sf.lines[1].joined_tokens
71
+ assert_equal "end\n", @sf.lines[2].joined_tokens
72
+ end
73
+
74
+ def test_should_indent_class_body
75
+ @sf.stubs(:source).returns("class Test\ndef blah\nreturn nil\nend\nend\n")
76
+ @sf.tokenize!
77
+ Indenter.format( @sf )
78
+ assert_equal "class Test\n", @sf.lines[0].joined_tokens
79
+ assert_equal " def blah\n", @sf.lines[1].joined_tokens
80
+ assert_equal " return nil\n", @sf.lines[2].joined_tokens
81
+ assert_equal " end\n", @sf.lines[3].joined_tokens
82
+ assert_equal "end\n", @sf.lines[4].joined_tokens
83
+ end
84
+
85
+ def test_should_indent_module_body
86
+ @sf.stubs(:source).returns("module Test\ndef blah\nreturn nil\nend\nend\n")
87
+ @sf.tokenize!
88
+ Indenter.format( @sf )
89
+ assert_equal "module Test\n", @sf.lines[0].joined_tokens
90
+ assert_equal " def blah\n", @sf.lines[1].joined_tokens
91
+ assert_equal " return nil\n", @sf.lines[2].joined_tokens
92
+ assert_equal " end\n", @sf.lines[3].joined_tokens
93
+ assert_equal "end\n", @sf.lines[4].joined_tokens
94
+ end
95
+
96
+ def test_should_not_indent_one_line_class
97
+ @sf.stubs(:source).returns("class Test; end\nclass Test2; end\n")
98
+ @sf.tokenize!
99
+ Indenter.format( @sf )
100
+ assert_equal "class Test; end\n", @sf.lines[0].joined_tokens
101
+ assert_equal "class Test2; end\n", @sf.lines[1].joined_tokens
102
+ end
103
+
104
+ def test_should_indent_class_to_self_block
105
+ # Note: Each line here has six spaces of indent before it, so this
106
+ # tests the logic in adjust_indent where there is an existing whitespace
107
+ # token at the start of the line
108
+ @sf.stubs(:source).returns(<<-SOURCE)
109
+ class Test
110
+ class << self
111
+ def function
112
+ return nil
113
+ end
114
+ end
115
+ end
116
+ SOURCE
117
+ @sf.tokenize!
118
+ Indenter.format( @sf )
119
+ assert_equal "class Test\n", @sf.lines[0].joined_tokens
120
+ assert_equal " class << self\n", @sf.lines[1].joined_tokens
121
+ assert_equal " def function\n", @sf.lines[2].joined_tokens
122
+ assert_equal " return nil\n", @sf.lines[3].joined_tokens
123
+ assert_equal " end\n", @sf.lines[4].joined_tokens
124
+ assert_equal " end\n", @sf.lines[5].joined_tokens
125
+ assert_equal "end\n", @sf.lines[6].joined_tokens
126
+ end
127
+
128
+ def test_should_indent_block
129
+ @sf.stubs(:source).returns("@item.map do |i|\ni*2\nend\n")
130
+ @sf.tokenize!
131
+ Indenter.format( @sf )
132
+ assert_equal "@item.map do |i|\n", @sf.lines[0].joined_tokens
133
+ assert_equal " i*2\n", @sf.lines[1].joined_tokens
134
+ assert_equal "end\n", @sf.lines[2].joined_tokens
135
+ end
136
+
137
+ def test_should_indent_begin_rescue_block
138
+ @sf.stubs(:source).returns("def function\nbegin\nHttp.get\nrescue\nHttp.post\nend\nend\n")
139
+ @sf.tokenize!
140
+ Indenter.format( @sf )
141
+ assert_equal "def function\n", @sf.lines[0].joined_tokens
142
+ assert_equal " begin\n", @sf.lines[1].joined_tokens
143
+ assert_equal " Http.get\n", @sf.lines[2].joined_tokens
144
+ assert_equal " rescue\n", @sf.lines[3].joined_tokens
145
+ assert_equal " Http.post\n", @sf.lines[4].joined_tokens
146
+ assert_equal " end\n", @sf.lines[5].joined_tokens
147
+ assert_equal "end\n", @sf.lines[6].joined_tokens
148
+ end
149
+
150
+ # Control Flow Statements
151
+ #-----------------------------------------------------------------------------
152
+
153
+ def test_should_indent_if_else_block
154
+ @sf.stubs(:source).returns(<<-SOURCE.gsub(/^ /, ''))
155
+ if @something
156
+ do_something
157
+ elsif @something_else
158
+ do_nothing
159
+ else
160
+ do_something_else
161
+ end
162
+ SOURCE
163
+ @sf.tokenize!
164
+ Indenter.format( @sf )
165
+ assert_equal "if @something\n", @sf.lines[0].joined_tokens
166
+ assert_equal " do_something\n", @sf.lines[1].joined_tokens
167
+ assert_equal "elsif @something_else\n", @sf.lines[2].joined_tokens
168
+ assert_equal " do_nothing\n", @sf.lines[3].joined_tokens
169
+ assert_equal "else\n", @sf.lines[4].joined_tokens
170
+ assert_equal " do_something_else\n", @sf.lines[5].joined_tokens
171
+ assert_equal "end\n", @sf.lines[6].joined_tokens
172
+ end
173
+
174
+ def test_should_indent_case_statement_when_not_set
175
+ @sf.stubs(:source).returns(<<-SOURCE.gsub(/^ /, ''))
176
+ case @something
177
+ when :this
178
+ do_this
179
+ when :that
180
+ do_that
181
+ else
182
+ do_the_other
183
+ end
184
+ SOURCE
185
+ @sf.tokenize!
186
+ Indenter.format( @sf )
187
+ assert_equal "case @something\n", @sf.lines[0].joined_tokens
188
+ assert_equal "when :this\n", @sf.lines[1].joined_tokens
189
+ assert_equal " do_this\n", @sf.lines[2].joined_tokens
190
+ assert_equal "when :that\n", @sf.lines[3].joined_tokens
191
+ assert_equal " do_that\n", @sf.lines[4].joined_tokens
192
+ assert_equal "else\n", @sf.lines[5].joined_tokens
193
+ assert_equal " do_the_other\n", @sf.lines[6].joined_tokens
194
+ assert_equal "end\n", @sf.lines[7].joined_tokens
195
+ end
196
+
197
+ # if suffix condition
198
+ def test_should_not_indent_suffix_conditional
199
+ @sf.stubs(:source).returns(<<-SOURCE.gsub(/^ /,''))
200
+ def function
201
+ do_something if some_condition
202
+ do_something_else
203
+ end
204
+ SOURCE
205
+ @sf.tokenize!
206
+ Indenter.format( @sf )
207
+ assert_equal "def function\n", @sf.lines[0].joined_tokens
208
+ assert_equal " do_something if some_condition\n", @sf.lines[1].joined_tokens
209
+ assert_equal " do_something_else\n", @sf.lines[2].joined_tokens
210
+ assert_equal "end\n", @sf.lines[3].joined_tokens
211
+ end
212
+
213
+ # unless suffix condition
214
+ def test_should_not_indent_suffix_conditional2
215
+ @sf.stubs(:source).returns(<<-SOURCE.gsub(/^ /,''))
216
+ def function
217
+ do_something unless some_condition
218
+ do_something_else
219
+ end
220
+ SOURCE
221
+ @sf.tokenize!
222
+ Indenter.format( @sf )
223
+ assert_equal "def function\n", @sf.lines[0].joined_tokens
224
+ assert_equal " do_something unless some_condition\n", @sf.lines[1].joined_tokens
225
+ assert_equal " do_something_else\n", @sf.lines[2].joined_tokens
226
+ assert_equal "end\n", @sf.lines[3].joined_tokens
227
+ end
228
+
229
+ # Loop Statements
230
+ #-----------------------------------------------------------------------------
231
+
232
+ def test_should_indent_while_statement
233
+ @sf.stubs(:source).returns(<<-SOURCE.gsub(/^ /, ''))
234
+ while @something
235
+ do_something
236
+ end
237
+ SOURCE
238
+ @sf.tokenize!
239
+ Indenter.format( @sf )
240
+ assert_equal "while @something\n", @sf.lines[0].joined_tokens
241
+ assert_equal " do_something\n", @sf.lines[1].joined_tokens
242
+ assert_equal "end\n", @sf.lines[2].joined_tokens
243
+ end
244
+
245
+ def test_should_not_index_suffix_while_statement
246
+ @sf.stubs(:source).returns(<<-SOURCE.gsub(/^ /,''))
247
+ def function
248
+ do_something while some_condition
249
+ do_something_else
250
+ end
251
+ SOURCE
252
+ @sf.tokenize!
253
+ Indenter.format( @sf )
254
+ assert_equal "def function\n", @sf.lines[0].joined_tokens
255
+ assert_equal " do_something while some_condition\n", @sf.lines[1].joined_tokens
256
+ assert_equal " do_something_else\n", @sf.lines[2].joined_tokens
257
+ assert_equal "end\n", @sf.lines[3].joined_tokens
258
+ end
259
+
260
+ def test_should_indent_while_statement_with_optional_do
261
+ @sf.stubs(:source).returns(<<-SOURCE.gsub(/^ /, ''))
262
+ while @something do
263
+ do_something
264
+ end
265
+ SOURCE
266
+ @sf.tokenize!
267
+ Indenter.format( @sf )
268
+ assert_equal "while @something do\n", @sf.lines[0].joined_tokens
269
+ assert_equal " do_something\n", @sf.lines[1].joined_tokens
270
+ assert_equal "end\n", @sf.lines[2].joined_tokens
271
+ end
272
+
273
+ def test_should_indent_until_statement
274
+ @sf.stubs(:source).returns(<<-SOURCE.gsub(/^ /, ''))
275
+ until @something
276
+ do_something
277
+ end
278
+ SOURCE
279
+ @sf.tokenize!
280
+ Indenter.format( @sf )
281
+ assert_equal "until @something\n", @sf.lines[0].joined_tokens
282
+ assert_equal " do_something\n", @sf.lines[1].joined_tokens
283
+ assert_equal "end\n", @sf.lines[2].joined_tokens
284
+ end
285
+
286
+ def test_should_not_index_suffix_until_statement
287
+ @sf.stubs(:source).returns(<<-SOURCE.gsub(/^ /,''))
288
+ def function
289
+ do_something until some_condition
290
+ do_something_else
291
+ end
292
+ SOURCE
293
+ @sf.tokenize!
294
+ Indenter.format( @sf )
295
+ assert_equal "def function\n", @sf.lines[0].joined_tokens
296
+ assert_equal " do_something until some_condition\n", @sf.lines[1].joined_tokens
297
+ assert_equal " do_something_else\n", @sf.lines[2].joined_tokens
298
+ assert_equal "end\n", @sf.lines[3].joined_tokens
299
+ end
300
+
301
+ def test_should_indent_until_statement_with_optional_do
302
+ @sf.stubs(:source).returns(<<-SOURCE.gsub(/^ /, ''))
303
+ until @something do
304
+ do_something
305
+ end
306
+ SOURCE
307
+ @sf.tokenize!
308
+ Indenter.format( @sf )
309
+ assert_equal "until @something do\n", @sf.lines[0].joined_tokens
310
+ assert_equal " do_something\n", @sf.lines[1].joined_tokens
311
+ assert_equal "end\n", @sf.lines[2].joined_tokens
312
+ end
313
+
314
+ end