Skip to content

Commit

Permalink
Merge pull request #1285 from kmuto/unknown-chap
Browse files Browse the repository at this point in the history
章付きキー参照で章がないときに内部例外ではなくKeyErrorを発生させるようにする
  • Loading branch information
kmuto authored Apr 5, 2019
2 parents 035e7b5 + 660f158 commit 75d744a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/review/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,9 @@ def get_chap(chapter = @chapter)
def extract_chapter_id(chap_ref)
m = /\A([\w+-]+)\|(.+)/.match(chap_ref)
if m
return [@book.contents.detect { |chap| chap.id == m[1] }, m[2]]
ch = @book.contents.detect { |chap| chap.id == m[1] }
raise KeyError unless ch
return [ch, m[2]]
end
[@chapter, chap_ref]
end
Expand Down
16 changes: 16 additions & 0 deletions test/test_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ def test_compile_inline_backslash
assert_equal [:text, text], @b.compile_inline(text)
end

def test_inline_missing_ref
b = Builder.new
chapter = ReVIEW::Book::Chapter.new(ReVIEW::Book::Base.load, 1, 'chap1', nil, StringIO.new)
b.bind(nil, chapter, nil)
e = assert_raises(ReVIEW::ApplicationError) { b.inline_list('unknown|list1') }
assert_equal ': error: unknown list: unknown|list1', e.message
e = assert_raises(ReVIEW::ApplicationError) { b.inline_table('unknown|table1') }
assert_equal ': error: unknown table: unknown|table1', e.message
e = assert_raises(ReVIEW::ApplicationError) { b.inline_img('unknown|img1') }
assert_equal ': error: unknown image: unknown|img1', e.message
e = assert_raises(ReVIEW::ApplicationError) { b.inline_column('unknown|column1') }
assert_equal ': error: unknown column: unknown|column1', e.message
e = assert_raises(ReVIEW::ApplicationError) { b.inline_fn('unknown|footnote1') }
assert_equal ': error: unknown footnote: unknown|footnote1', e.message
end

class XBuilder < Builder
def list_header(id, caption)
end
Expand Down

0 comments on commit 75d744a

Please sign in to comment.