Home / Function/ Test_Ctx_Charset() — fiber Function Reference

Test_Ctx_Charset() — fiber Function Reference

Architecture documentation for the Test_Ctx_Charset() function in ctx_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  9a3cf98c_aec7_3ee9_e4f1_00f5d0acb925["Test_Ctx_Charset()"]
  7b3d4933_5ae3_f84d_ff6d_0cb34e268026["ctx_test.go"]
  9a3cf98c_aec7_3ee9_e4f1_00f5d0acb925 -->|defined in| 7b3d4933_5ae3_f84d_ff6d_0cb34e268026
  style 9a3cf98c_aec7_3ee9_e4f1_00f5d0acb925 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

ctx_test.go lines 158–228

func Test_Ctx_Charset(t *testing.T) {
	t.Parallel()

	testCases := []struct {
		name        string
		contentType string
		expected    string
	}{
		{
			name:        "no_parameters",
			contentType: "text/plain",
			expected:    "",
		},
		{
			name:        "trailing_semicolon",
			contentType: "text/plain;",
			expected:    "",
		},
		{
			name:        "empty_param_before_charset",
			contentType: "text/plain; ; charset=utf-8",
			expected:    "utf-8",
		},
		{
			name:        "charset_with_spaces",
			contentType: "text/plain; charset = utf-8",
			expected:    "utf-8",
		},
		{
			name:        "charset_in_middle",
			contentType: "text/plain; foo=bar; charset=iso-8859-1; baz=qux",
			expected:    "iso-8859-1",
		},
		{
			name:        "charset_quoted",
			contentType: "text/plain; charset=\"utf-8\"; foo=bar",
			expected:    "utf-8",
		},
		{
			name:        "non_charset_only",
			contentType: "text/plain; foo=bar",
			expected:    "",
		},
		{
			name:        "missing_equals",
			contentType: "text/plain; charset",
			expected:    "",
		},
		{
			name:        "empty_charset_value",
			contentType: "text/plain; charset=",
			expected:    "",
		},
		{
			name:        "case_insensitive_charset",
			contentType: "text/plain; chArSet=Shift_JIS",
			expected:    "Shift_JIS",
		},
	}

	for _, testCase := range testCases {
		t.Run(testCase.name, func(t *testing.T) {
			t.Parallel()

			app := New()
			c := app.AcquireCtx(&fasthttp.RequestCtx{})
			c.Request().Header.Set(HeaderContentType, testCase.contentType)
			require.Equal(t, testCase.expected, c.Charset())
		})
	}
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does Test_Ctx_Charset() do?
Test_Ctx_Charset() is a function in the fiber codebase, defined in ctx_test.go.
Where is Test_Ctx_Charset() defined?
Test_Ctx_Charset() is defined in ctx_test.go at line 158.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free