Logo: Relish

  1. Sign in

Project: Redcar

Align Assignment

Background
When
I open a new edit tab
Scenarios
align simple assignments
When
I replace the contents with "a = 4\nbc = 5\nd = 123"
And
I select all
And
I run the command Redcar::EditView::AlignAssignmentCommand
Then
the contents should be "<c>a = 4\nbc = 5\nd = 123<s>"
align rows that have empty lines
When
I replace the contents with "a = 1\n\nab = 123"
And
I select all
And
I run the command Redcar::EditView::AlignAssignmentCommand
Then
the contents should be "<c>a = 1\n\nab = 123<s>"
preserve trailing newline
Given
the content is:
def foo
<c>  a = 1
  bb = 2
  ccc = 3
<s>end
When
I run the command Redcar::EditView::AlignAssignmentCommand
Then
the content should be:
def foo
<c>  a   = 1
  bb  = 2
  ccc = 3<s>
end
preserve non-selected indentation
Given
the content is:
def foo
  <c>a = 1
  bb = 2
  ccc = 3<s>
end
When
I run the command Redcar::EditView::AlignAssignmentCommand
Then
the content should be:
def foo
<c>  a   = 1
  bb  = 2
  ccc = 3<s>
end
align the right hand side of the operator
Given
the content is:
def foo
<c>  a = 1
  bb =     2
  ccc = 3<s>
end
When
I run the command Redcar::EditView::AlignAssignmentCommand
Then
the content should be:
def foo
<c>  a   = 1
  bb  = 2
  ccc = 3<s>
end
aligning different length operators
Given
the content is:
Integer === 1
two =~ /2/
@three||= 3333
bits &= 0b101010
And
I select all
When
I run the command Redcar::EditView::AlignAssignmentCommand
Then
the content should be:
<c>Integer === 1
two      =~ /2/
@three  ||= 3333
bits &    = 0b101010<s>
aligning hashes
Given
the content is:
{:one => 1,
:two => 22,
:threee => 333}
And
I select all
When
I run the command Redcar::EditView::AlignAssignmentCommand
Then
the content should be:
<c>{:one   => 1,
:two    => 22,
:threee => 333}<s>

Last published over 4 years ago by danlucraft.