Improve tests

This commit is contained in:
Alex Kotov 2023-09-30 03:52:45 +04:00
parent 967d64e61f
commit a4102d29f8
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08

160
test.rb
View file

@ -6,6 +6,62 @@ require 'open3'
EXE = File.expand_path('exe/referator', __dir__).freeze
RAW_REFS = {
self: {
foo: {
'kind' => 'self',
'id' => '/blog/foo',
'slug' => 'blog-foo',
'text' => 'Foo',
}.freeze,
bar: {
'kind' => 'self',
'id' => '/blog/bar',
'slug' => 'blog-bar',
'text' => 'Bar',
}.freeze,
}.freeze,
link: {
example_com: {
'kind' => 'link',
'id' => 'example_com',
'slug' => 'example-com',
'url' => 'https://example.com',
'text' => 'Example Domain',
}.freeze,
causa_arcana_com: {
'kind' => 'link',
'id' => 'causa_arcana_com',
'slug' => 'causa-arcana-com',
'url' => 'https://causa-arcana.com',
'text' => 'Causa Arcana',
}.freeze,
}.freeze,
}.freeze
REFS = {
self: {
foo: RAW_REFS[:self][:foo].merge(
'anchor' => 'self-blog-foo',
'fragment' => '#self-blog-foo',
).freeze,
bar: RAW_REFS[:self][:bar].merge(
'anchor' => 'self-blog-bar',
'fragment' => '#self-blog-bar',
).freeze,
}.freeze,
link: {
example_com: RAW_REFS[:link][:example_com].merge(
'anchor' => 'link-example-com',
'fragment' => '#link-example-com',
).freeze,
causa_arcana_com: RAW_REFS[:link][:causa_arcana_com].merge(
'anchor' => 'link-causa-arcana-com',
'fragment' => '#link-causa-arcana-com',
).freeze,
}.freeze,
}.freeze
@stdin, @stdout, @wait_thr = Open3.popen2 EXE, chdir: __dir__
@stdin.sync = true
@ -45,6 +101,7 @@ cmd :REGISTER_FORMAT, { name: :html,
args: ['test/render.rb',
{ template: nil },
{ format: nil }] }
cmd :REGISTER_FORMAT, { name: :json,
stdin: { notes: nil },
args: ['test/render.rb',
@ -55,58 +112,29 @@ cmd :REGISTER_FORMAT, { name: :json,
# ADD_REF #
###########
cmd :ADD_REF,
{ kind: :self,
id: '/blog/foo',
slug: 'blog-foo',
text: 'Foo' }
cmd :ADD_REF,
{ kind: :self,
id: '/blog/bar',
slug: 'blog-bar',
text: 'Bar' }
cmd :ADD_REF,
{ kind: :link,
id: :example_com,
slug: 'example-com',
url: 'https://example.com',
text: 'Example Domain' }
cmd :ADD_REF,
{ kind: :link,
id: :causa_arcana_com,
slug: 'causa-arcana-com',
url: 'https://causa-arcana.com',
text: 'Causa Arcana' }
cmd :ADD_REF, RAW_REFS[:self][:foo]
cmd :ADD_REF, RAW_REFS[:self][:bar]
cmd :ADD_REF, RAW_REFS[:link][:example_com]
cmd :ADD_REF, RAW_REFS[:link][:causa_arcana_com]
#######
# REF #
#######
cmd(:REF, { 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',
}
raise unless result == REFS[:self][:foo]
end
raise unless result == expected
cmd(:REF, { kind: :self, id: '/blog/bar' }).tap do |result|
raise unless result == REFS[:self][:bar]
end
cmd(:REF, { 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',
}
raise unless result == REFS[:link][:example_com]
end
raise unless result == expected
cmd(:REF, { kind: :link, id: :causa_arcana_com }).tap do |result|
raise unless result == REFS[:link][:causa_arcana_com]
end
############
@ -114,61 +142,19 @@ end
############
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
raise unless result == REFS[:self][:foo].merge('index' => 1)
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
raise unless result == REFS[:link][:example_com].merge('index' => 2)
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
raise unless result == REFS[:self][:bar].merge('index' => 3)
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
raise unless result == REFS[:link][:causa_arcana_com].merge('index' => 4)
end
####################