Skip to content

Instantly share code, notes, and snippets.

@pd
Forked from anonymous/window_layout_spec.rb
Last active December 10, 2015 21:29
Show Gist options
  • Save pd/4495802 to your computer and use it in GitHub Desktop.
Save pd/4495802 to your computer and use it in GitHub Desktop.
mkdir -p read_window_layout/features/support
curl https://gist.github.com/raw/4495802/9d28d175fc1808e86e29248df793c01460cf7119/read-layout.feature > read_window_layout/features/read-layout.feature
curl https://gist.github.com/raw/4495802/ba67bac9506bda4522883f19c118fef23604db9e/features-support-env.rb > read_window_layout/features/support/env.rb
def read_layout(string)
# Dumbest implementation
rows = string.split("\n").select { |s| s.start_with?('|') }
[:rows] + rows.map { |s| [:cols] + s.split(/[ |]+/).reject { |c| c == '' } }
end
When 'I read the window layout:' do |s|
@layout = read_layout(s.to_s)
end
Then 'the layout should be $struct' do |structure|
structure.gsub!('(', '[')
structure.gsub!(')', ']')
structure.gsub!('] ', '], ')
structure.gsub!(/(rows|cols) /, ':\1, ')
structure.gsub!('" ', '", ')
@layout.should == eval(structure)
end
Feature: Reading window layouts
Scenario: one window
When I read the window layout:
"""
+---+
| A |
+---+
"""
Then the layout should be (rows (cols "A"))
Scenario: A|B
When I read the window layout:
"""
+---+---+
| A | B |
+---+---+
"""
Then the layout should be (rows (cols "A" "B"))
Scenario: A|B--C
When I read the window layout:
"""
+---+---+
| A | B |
+-------+
| C |
+-------+
"""
Then the layout should be (rows (cols "A" "B") (cols "C"))
Scenario: A|B--C|D
When I read the window layout:
"""
+---+---+
| A | B |
+-------+
| C | D |
+-------+
"""
Then the layout should be (rows (cols "A" "B") (cols "C" "D"))
Scenario: 3 rows
When I read the window layout:
"""
+---+
| A |
+---+
| B |
+---+
| C |
+---+
"""
Then the layout should be (rows (cols "A") (cols "B") (cols "C"))
Scenario: Inner horizontal split
When I read the window layout:
"""
+---+---+
| A | |
+---+ B |
| F | |
+---+---+
| C |
+-------+
| D | E |
+---+---+
"""
Then the layout should be (rows (cols (rows "A" "F") "B") (cols "C") (cols "D" "E"))
Scenario: Inner vertical split
When I read the window layout:
"""
+---+---+---+
| | B | C |
| A +---+---+
| | D |
+---+---+---+
| E |
+-----------+
"""
Then the layout should be (rows (cols "A" (rows (cols "B" "C") (cols "D"))) (cols "E"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment