TestSpec_PublicAPI_MarshalCompactNoHTMLEscape validates the documented behavior of MarshalCompactNoHTMLEscape as described in the jsonutil README.md. Specification: - Marshals v to compact JSON without HTML escaping. - Characters like '&', '<', '>' are preserved as-is (not encoded to \u0026, \u003c
(t *testing.T)
| 20 | // - Characters like '&', '<', '>' are preserved as-is (not encoded to \u0026, \u003c, \u003e). |
| 21 | // - Trailing newline emitted by json.Encoder is trimmed so the result matches json.Marshal style. |
| 22 | func TestSpec_PublicAPI_MarshalCompactNoHTMLEscape(t *testing.T) { |
| 23 | t.Run("preserves expression operators (& and |)", func(t *testing.T) { |
| 24 | input := map[string]string{ |
| 25 | "expr": "${{ env.MCP_ENV == 'staging' && env.MCP_URL_STAGING || env.MCP_URL_PROD }}", |
| 26 | } |
| 27 | |
| 28 | result, err := jsonutil.MarshalCompactNoHTMLEscape(input) |
| 29 | require.NoError(t, err, "marshal should succeed") |
| 30 | |
| 31 | assert.Contains(t, result, "&&", "expected && to be preserved") |
| 32 | assert.NotContains(t, result, `\u0026`, "expected & not to be HTML-escaped") |
| 33 | }) |
| 34 | |
| 35 | t.Run("output is compact (no trailing newline)", func(t *testing.T) { |
| 36 | input := map[string]string{"key": "value"} |
| 37 | |
| 38 | result, err := jsonutil.MarshalCompactNoHTMLEscape(input) |
| 39 | require.NoError(t, err, "marshal should succeed") |
| 40 | |
| 41 | assert.False(t, strings.HasSuffix(result, "\n"), "result must not have trailing newline") |
| 42 | }) |
| 43 | |
| 44 | t.Run("preserves angle brackets without HTML escaping", func(t *testing.T) { |
| 45 | input := map[string]string{"x": "<tag>"} |
| 46 | |
| 47 | result, err := jsonutil.MarshalCompactNoHTMLEscape(input) |
| 48 | require.NoError(t, err, "marshal should succeed") |
| 49 | |
| 50 | assert.Contains(t, result, "<tag>", "expected <tag> to be preserved") |
| 51 | assert.NotContains(t, result, `\u003c`, "expected < not to be HTML-escaped") |
| 52 | assert.NotContains(t, result, `\u003e`, "expected > not to be HTML-escaped") |
| 53 | }) |
| 54 | } |
nothing calls this directly
no test coverage detected