Add tests

This commit is contained in:
Alex Kotov 2023-09-30 03:40:39 +04:00
parent 3548d5995a
commit 967d64e61f
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

87
test.rb
View file

@ -29,9 +29,17 @@ def cmd(name, data)
end
end
#################
# REGISTER_KIND #
#################
cmd :REGISTER_KIND, :self
cmd :REGISTER_KIND, :link
###################
# REGISTER_FORMAT #
###################
cmd :REGISTER_FORMAT, { name: :html,
stdin: { notes: nil },
args: ['test/render.rb',
@ -43,6 +51,10 @@ cmd :REGISTER_FORMAT, { name: :json,
{ template: nil },
{ format: nil }] }
###########
# ADD_REF #
###########
cmd :ADD_REF,
{ kind: :self,
id: '/blog/foo',
@ -66,6 +78,10 @@ cmd :ADD_REF,
url: 'https://causa-arcana.com',
text: 'Causa Arcana' }
#######
# REF #
#######
cmd(:REF, { kind: :self, id: '/blog/foo' }).tap do |result|
expected = {
'kind' => 'self',
@ -78,6 +94,7 @@ cmd(:REF, { kind: :self, id: '/blog/foo' }).tap do |result|
raise unless result == expected
end
cmd(:REF, { kind: :link, id: :example_com }).tap do |result|
expected = {
'kind' => 'link',
@ -92,10 +109,71 @@ cmd(:REF, { kind: :link, id: :example_com }).tap do |result|
raise unless result == expected
end
cmd :ADD_NOTE, { kind: :self, id: '/blog/foo' }
cmd :ADD_NOTE, { kind: :link, id: :example_com }
cmd :ADD_NOTE, { kind: :self, id: '/blog/bar' }
cmd :ADD_NOTE, { kind: :link, id: :causa_arcana_com }
############
# ADD_NOTE #
############
cmd(:ADD_NOTE, { kind: :self, id: '/blog/foo' }).tap do |result|
expected = {
'kind' => 'self',
'id' => '/blog/foo',
'slug' => 'blog-foo',
'anchor' => 'self-blog-foo',
'fragment' => '#self-blog-foo',
'text' => 'Foo',
'index' => 1,
}.freeze
raise unless result == expected
end
cmd(:ADD_NOTE, { kind: :link, id: :example_com }).tap do |result|
expected = {
'kind' => 'link',
'id' => 'example_com',
'slug' => 'example-com',
'anchor' => 'link-example-com',
'fragment' => '#link-example-com',
'url' => 'https://example.com',
'text' => 'Example Domain',
'index' => 2,
}.freeze
raise unless result == expected
end
cmd(:ADD_NOTE, { kind: :self, id: '/blog/bar' }).tap do |result|
expected = {
'kind' => 'self',
'id' => '/blog/bar',
'slug' => 'blog-bar',
'anchor' => 'self-blog-bar',
'fragment' => '#self-blog-bar',
'text' => 'Bar',
'index' => 3,
}.freeze
raise unless result == expected
end
cmd(:ADD_NOTE, { kind: :link, id: :causa_arcana_com }).tap do |result|
expected = {
'kind' => 'link',
'id' => 'causa_arcana_com',
'slug' => 'causa-arcana-com',
'anchor' => 'link-causa-arcana-com',
'fragment' => '#link-causa-arcana-com',
'url' => 'https://causa-arcana.com',
'text' => 'Causa Arcana',
'index' => 4,
}.freeze
raise unless result == expected
end
####################
# RENDER_FOOTNOTES #
####################
cmd(:RENDER_FOOTNOTES, :html).tap do |result|
expected = <<~HTML
@ -124,6 +202,7 @@ cmd(:RENDER_FOOTNOTES, :html).tap do |result|
raise unless result == expected
end
cmd(:RENDER_FOOTNOTES, :json).tap do |result|
expected = <<~JSON
{