Created
June 4, 2018 18:09
-
-
Save baweaver/3cbfd144b525ff32c1f013774a5bfac7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The goal of this problem is to extract headers from a block of text, | |
# and arrange them hierarchically. | |
# | |
# See the specs for more detail on the output | |
def header_hierarchy(html) | |
raise "TODO" | |
end | |
describe '#header_hierarchy' do | |
context 'EASY' do | |
it 'can extract a single header' do | |
expect(header_hierarchy("<h1>Foo</h1>")).to eq(['[h1] Foo']) | |
end | |
it 'can extract one nested level of header' do | |
expect( | |
header_hierarchy("<h1>Foo</h1><h2>Bar</h2>") | |
).to eq([ | |
'[h1] Foo', | |
' [h2] Bar' | |
]) | |
end | |
end | |
context 'MEDIUM' do | |
it 'can extract multiple levels of nested headers' do | |
expect( | |
header_hierarchy("<h1>Foo</h1><h2>Bar</h2><h3>Baz</h3><h4>Bam</h4>") | |
).to eq([ | |
'[h1] Foo', | |
' [h2] Bar', | |
' [h3] Baz', | |
' [h4] Bam' | |
]) | |
end | |
end | |
context 'HARD' do | |
it 'can extract multiple nested headers in multiple branches' do | |
expect( | |
header_hierarchy("<h1>Foo</h1><h2>Bar</h2><h3>Baz</h3><h2>Bam</h2><h3>Ba</h3>") | |
).to eq([ | |
'[h1] Foo', | |
' [h2] Bar', | |
' [h3] Baz', | |
' [h2] Bam', | |
' [h3] Ba' | |
]) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My solution:
EDIT - Modified tests to reflect the 'ROOT' element, going to leave the original specification alone for a bit.