Permalink
Browse files

implemented nested constructions handling for the structures compressor

  • Loading branch information...
1 parent 1fe9842 commit e29d29b9daa7b8820d46b712f2c19e8581511245 @MadRabbit committed Aug 24, 2008
@@ -154,19 +154,28 @@ def check_first_block_of(stack)
end
# recoursive call on the rest of the stack
- block + simplify_logical_constructions(stack)
+ simplify_logical_constructions(block) +
+ simplify_logical_constructions(stack)
end
# checks the number of code lines in the string
def number_of_code_lines_in(str)
+ str = str.dup
+
# removing all the method calls, blocks and lists
['[', '(', '{'].each do |token|
- while pos = (str.include?(token))
+ offset = 0
+ while pos = str.index(token, offset)
+ offset = pos + 1
start = str[0, pos]
stack = str[pos, str.size]
block = find_block(stack, token)
- str.gsub! block, token
+ str.gsub! block, case token
+ when '(' then '()'
+ when '[' then '[]'
+ else ';'
+ end
end
end
@@ -152,4 +152,54 @@
while (something()) foo;
}
end
+
+ it "should keep internal multilined constructions safe" do
+ @c.compact(%{
+ if (something) {
+ for (var i=0; i<something.length; i++) {
+ var boo = something[i];
+ var foo = boo % i;
+ }
+ }
+ }).should == %{
+ if (something)
+ for (var i=0; i<something.length; i++) {
+ var boo = something[i];
+ var foo = boo % i;
+ }
+
+ }
+ end
+
+ it "should handle nested constructions" do
+ @c.compact(%{
+ if (something) {
+ for (var k in o) {
+ while(something) {
+ var o[k] = something;
+ }
+ }
+ } else {
+ while (something) {
+ for (var k in o) {
+ something = o[k];
+ }
+ }
+ }
+ }).should == %{
+ if (something)
+ for (var k in o)
+ while(something)
+ var o[k] = something;
+
+
+ else
+ while (something)
+ for (var k in o)
+ something = o[k];
+
+
+
+ }
+ end
end

0 comments on commit e29d29b

Please sign in to comment.