Skip to content

Commit 0701a93

Browse files
liberaldevsorah
authored andcommitted
Add unit tests for to_html_lang filter to ensure correctness and Liquid integration
1 parent 9541964 commit 0701a93

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

test/test_plugin_html_lang.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# frozen_string_literal: true
2+
3+
require "helper"
4+
require "liquid"
5+
require_relative "../_plugins/html_lang"
6+
7+
describe Jekyll::HtmlLangFilter do
8+
include Jekyll::HtmlLangFilter
9+
10+
describe "#to_html_lang" do
11+
it "returns the same string if no underscore is present" do
12+
_(to_html_lang("en")).must_equal "en"
13+
_(to_html_lang("fr")).must_equal "fr"
14+
end
15+
16+
it "converts Jekyll locale with underscore to BCP 47 format" do
17+
_(to_html_lang("zh_cn")).must_equal "zh-CN"
18+
_(to_html_lang("zh_tw")).must_equal "zh-TW"
19+
_(to_html_lang("pt_br")).must_equal "pt-BR"
20+
end
21+
22+
it "returns the input as is if it is not a string" do
23+
_(to_html_lang(nil)).must_be_nil
24+
_(to_html_lang(123)).must_equal 123
25+
end
26+
end
27+
28+
describe "integration with Liquid" do
29+
it "is registered as a liquid filter" do
30+
template = Liquid::Template.parse("{{ 'zh_cn' | to_html_lang }}")
31+
_(template.render).must_equal "zh-CN"
32+
end
33+
34+
it "works correctly in a liquid template for simple lang" do
35+
template = Liquid::Template.parse("{{ 'en' | to_html_lang }}")
36+
_(template.render).must_equal "en"
37+
end
38+
end
39+
end

0 commit comments

Comments
 (0)