diff options
| author | Guillaume Grossetie <g.grossetie@gmail.com> | 2019-02-10 23:41:11 +0100 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2019-02-10 15:41:11 -0700 |
| commit | a50cfdcfe00c616bdb5ae9a55cf00beb6eaddcdb (patch) | |
| tree | 259066f4a9be46f38f4c387dcf9a51ada774f911 /test/document_test.rb | |
| parent | 65c83533fbcd7f7f270d041d0b8ab50e4f26641b (diff) | |
resolves #3064 compute docyear and docdatetime from docdate and doctime (PR #3065)
Diffstat (limited to 'test/document_test.rb')
| -rw-r--r-- | test/document_test.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/document_test.rb b/test/document_test.rb index b9218a01..1eb479d8 100644 --- a/test/document_test.rb +++ b/test/document_test.rb @@ -1718,4 +1718,44 @@ context 'Document' do assert_equal expect, result end end + + context 'Date time attributes' do + test 'should compute docyear and docdatetime from docdate and doctime' do + doc = Asciidoctor::Document.new [], attributes: {'docdate' => '2015-01-01', 'doctime' => '10:00:00-0700'} + assert_equal '2015-01-01', (doc.attr 'docdate') + assert_equal '2015', (doc.attr 'docyear') + assert_equal '10:00:00-0700', (doc.attr 'doctime') + assert_equal '2015-01-01 10:00:00-0700', (doc.attr 'docdatetime') + end + test 'should allow docdate and doctime to be overridden' do + doc = Asciidoctor::Document.new [], input_mtime: ::Time.now, attributes: {'docdate' => '2015-01-01', 'doctime' => '10:00:00-0700'} + assert_equal '2015-01-01', (doc.attr 'docdate') + assert_equal '2015', (doc.attr 'docyear') + assert_equal '10:00:00-0700', (doc.attr 'doctime') + assert_equal '2015-01-01 10:00:00-0700', (doc.attr 'docdatetime') + end + test 'should compute docdatetime from doctime' do + doc = Asciidoctor::Document.new [], attributes: {'doctime' => '10:00:00-0700'} + assert_equal '10:00:00-0700', (doc.attr 'doctime') + assert (doc.attr 'docdatetime').end_with?(' 10:00:00-0700') + end + test 'should compute docyear from docdate' do + doc = Asciidoctor::Document.new [], attributes: {'docdate' => '2015-01-01'} + assert_equal '2015', (doc.attr 'docyear') + assert (doc.attr 'docdatetime').start_with?('2015-01-01 ') + end + test 'should allow doctime to be overridden' do + doc = Asciidoctor::Document.new [], input_mtime: ::Time.new(2019, 01, 02, 3, 4, 5, "+06:00"), attributes: {'doctime' => '10:00:00-0700'} + assert_equal '2019-01-02', (doc.attr 'docdate') + assert_equal '2019', (doc.attr 'docyear') + assert_equal '10:00:00-0700', (doc.attr 'doctime') + assert_equal '2019-01-02 10:00:00-0700', (doc.attr 'docdatetime') + end + test 'should allow docdate to be overridden' do + doc = Asciidoctor::Document.new [], input_mtime: ::Time.new(2019, 01, 02, 3, 4, 5, "+06:00"), attributes: {'docdate' => '2015-01-01'} + assert_equal '2015-01-01', (doc.attr 'docdate') + assert_equal '2015', (doc.attr 'docyear') + assert_equal '2015-01-01 03:04:05 +0600', (doc.attr 'docdatetime') + end + end end |
