summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-07-08 23:55:15 -0600
committerDan Allen <dan.j.allen@gmail.com>2022-07-09 00:59:08 -0600
commitc642e41441baf9447fecbf081be251813abe9a8c (patch)
treed236bc97e970c4a7ef9416e2901e7c88ebc8d499
parentd5c9ab50a4ced8a1ee8499cb453d67f8d1b3fe6a (diff)
fix Asciidoctor::Cli::Invoker constructor when first argument is a hash
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/cli/invoker.rb2
-rw-r--r--test/invoker_test.rb31
3 files changed, 33 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 82c2ccdb..dbd82cbb 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -63,6 +63,7 @@ Bug Fixes::
* Reset registry if activate is called on it again (#4256)
* Format source location in exception message when extension code is malformed
* Fix lineno on reader when `skip-front-matter` attribute is set but end of front matter is not found
+ * Fix `Asciidoctor::Cli::Invoker` constructor when first argument is a hash
// tag::compact[]
== 2.0.17 (2022-01-05) - @mojavelinux
diff --git a/lib/asciidoctor/cli/invoker.rb b/lib/asciidoctor/cli/invoker.rb
index 8578a735..de16f4fd 100644
--- a/lib/asciidoctor/cli/invoker.rb
+++ b/lib/asciidoctor/cli/invoker.rb
@@ -20,7 +20,7 @@ module Asciidoctor
when Options
@options = first_option
when ::Hash
- @options = Options.new options
+ @options = Options.new first_option
else
if ::Integer === (result = Options.parse! options)
@code = result
diff --git a/test/invoker_test.rb b/test/invoker_test.rb
index 48a9b71b..e5c2ee97 100644
--- a/test/invoker_test.rb
+++ b/test/invoker_test.rb
@@ -4,6 +4,37 @@ require_relative 'test_helper'
require File.join Asciidoctor::LIB_DIR, 'asciidoctor/cli'
context 'Invoker' do
+ test 'should allow Options to be passed as first argument of constructor' do
+ opts = Asciidoctor::Cli::Options.new attributes: { 'toc' => '' }, doctype: 'book', sourcemap: true
+ invoker = Asciidoctor::Cli::Invoker.new opts
+ assert_same invoker.options, opts
+ end
+
+ test 'should allow options Hash to be passed as first argument of constructor' do
+ opts = { attributes: { 'toc' => '' }, doctype: 'book', sourcemap: true }
+ invoker = Asciidoctor::Cli::Invoker.new opts
+ resolved_opts = invoker.options
+ assert_equal opts[:attributes], resolved_opts[:attributes]
+ assert_equal 'book', resolved_opts[:attributes]['doctype']
+ assert resolved_opts[:sourcemap]
+ end
+
+ test 'should parse options from array passed as first argument of constructor' do
+ input_file = fixture_path 'basic.adoc'
+ invoker = Asciidoctor::Cli::Invoker.new ['-s', input_file]
+ resolved_options = invoker.options
+ refute resolved_options[:standalone]
+ assert_equal [input_file], resolved_options[:input_files]
+ end
+
+ test 'should parse options from multiple arguments passed to constructor' do
+ input_file = fixture_path 'basic.adoc'
+ invoker = Asciidoctor::Cli::Invoker.new '-s', input_file
+ resolved_options = invoker.options
+ refute resolved_options[:standalone]
+ assert_equal [input_file], resolved_options[:input_files]
+ end
+
test 'should parse source and convert to html5 article by default' do
invoker = nil
output = nil