Open stevo opened 6 years ago
require 'rails_helper'
RSpec.describe MarkdownChecklist do
describe '#each' do
context 'when there are no checklist items in source' do
it 'yields noting' do
source = <<~MARKDOWN
some markdown without checklist items
MARKDOWN
markdown_checklist = MarkdownChecklist.new(source)
expect { |b| markdown_checklist.each(&b) }.not_to yield_control
end
end
context 'when there checklist items in source' do
context 'when there was no header specified before checklist items' do
it 'yields summary of total and checked items for "nil" subject' do
source = <<~MARKDOWN
[ ] Item one
[x] Item two
MARKDOWN
markdown_checklist = MarkdownChecklist.new(source)
expect { |b| markdown_checklist.each(&b) }.to \
yield_with_args(nil, { total: 2, checked: 1 })
end
end
end
end
end
#
# mc = MarkdownChecklist.new('markdown')
#
#
# yield_successive_args([:a, :b], [:c, :d]) }
#
# expect { |b| markdown_checklist.each(&b) }.to \
# yield_successive_args([nil, { total: 2, checked: 1 }], ["GIT", { total: 2, checked: 5 }])
#
#
# ##
# [ ]
# [x]
#
# ##
# #
# # []
# mc.each do |subject, stats|
# # subject: "Working with GIT using CLI"
# # stats: { :total => 17, :checked => 15 }
# #
# #
# # # subject: nil
# # # stats: { :total => 17, :checked => 15 }
# #
# # subject: "Gems and Libraries -> Testing"
# # stats: {:total=>9, :checked=>7}
# # subject: "Gems and Libraries -> Development"
# # stats: {:total=>9, :checked=>7}
# end
# mc.each do |subject, stats|
# # subject: ["Working with GIT using CLI"]
# # items: { 'Not nice :blue_diamond:' => false, 'Nice' => true }
# #
# #
# # # subject: [nil]
# # # stats: { :total => 17, :checked => 15 }
# #
\s*#+\s*(?<subject>.*) -> Headers
\s*\[[x\s]]\s*(?<item>.*) -> Items
' [x] jasjdjasdjsd '.match(/\s*\[[x\s]]\s*(?<item>.*)/)[:item]
\s*\[(?<checked>[x\s])]\s*(?<item>.*)
" ### aaa"=~ /\s*\#{2,}/
pseudocode
items = {}
subjects = []
get_line
parse_line
if line is item
store item and its status in "current_items"
elsif line is subject (##+)?
check if there are any items in buffer
if yes
yield current subjects and items
clean all items from buffer
if subject nesting is > current subjects
add subject to current subjects
elsif subject nesting is equal to current subjects
replace last subject from current subjects with one at hand
else
trim current subjects to level of subject at hand and replace as above
end
if anything is left in items
yield current subjects and items
ruby ~/Downloads/result.rb {url}
->"{:\"Working with GIT using CLI\"=>{:total=>17, :checked=>15}, :\"Ruby core and stdlib\"=>{:total=>150, :checked=>111, :_total=>1}, :Rails=>{:ActiveSupport=>{:total=>81, :checked=>19}}, :\"Core rails skills\"=>{:ActiveRecord=>{:total=>125, :checked=>112}, :\"Views and Forms\"=>{:total=>22, :checked=>13}, :ActionController=>{:total=>22, :checked=>13}, :Routing=>{:total=>25, :checked=>11}, :I18n=>{:total=>9, :checked=>0}, :\"Action Mailer\"=>{:total=>10, :checked=>6}, :\"Active Job and Sidekiq\"=>{:total=>11, :checked=>7}, :\"Active Storage\"=>{:total=>7, :checked=>0}, :\"Action Cable\"=>{:total=>2, :checked=>1}, :Testing=>{:total=>48, :checked=>37}}, :Patterns=>{:total=>21, :checked=>19}, :Other=>{:total=>21, :checked=>14}, :\"Gems and Libraries\"=>{:Development=>{:total=>19, :checked=>12}, :Testing=>{:total=>9, :checked=>7}}, :Tooling=>{:total=>5, :checked=>3}}"
"{:\"Ruby core and stdlib\"=>{:total=>152, :checked=>0, :small_blue_diamond_total=>22, :small_orange_diamond_total=>13, :small_red_triangle_total=>8, :_total=>1}, :ActiveSupport=>{:total=>88, :checked=>0, :small_orange_diamond_total=>11, :small_red_triangle_total=>6, :small_blue_diamond_total=>7}}"
Cover this behavior with tests