File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments