Skip to content

Commit

Permalink
add test to merge default configs
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Oct 9, 2024
1 parent d5bd093 commit 4f37ae6
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/config_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true

require "test_helper"

class ConfigTest < Minitest::Test
def test_process_options
user_config = {
parse: {
smart: true,
},
render: {
unsafe: false,
},
}
processed_config = Commonmarker::Config.process_options(user_config)

expected_config = [:parse, :render, :extension].each_with_object({}) do |type, hash|
hash[type] = Commonmarker::Config::OPTIONS[type].merge(user_config[type] || {})
end

assert_equal(expected_config, processed_config)
end

def test_process_plugins
user_config = {
syntax_highlighter: {
path: "./themes",
},
}
processed_config = Commonmarker::Config.process_plugins(user_config)
expected_config = [:syntax_highlighter].each_with_object({}) do |type, hash|
hash[type] = Commonmarker::Config::PLUGINS[type].merge(user_config[type])
end

assert_equal(expected_config, processed_config)
end

def test_config_merges_directly
# hardbreaks work, the `\n` in between is rendered
assert_equal("<p>aaaa<br />\nbbbb</p>\n", Commonmarker.to_html("aaaa\nbbbb"))

# hardbreaks still work
assert_equal("<p>aaaa<br />\nbbbb</p>\n", Commonmarker.to_html("aaaa\nbbbb", options: { render: { unsafe: false } }))
end
end

0 comments on commit 4f37ae6

Please sign in to comment.