TestSpec_PublicAPI_SanitizeIdentifierName validates the documented behavior of SanitizeIdentifierName as described in the package README.md. Specification: "Sanitizes a string for use as a programming-language identifier by replacing invalid characters with underscores and prefixing _ when the iden
(t *testing.T)
| 456 | // runes beyond the normal identifier rules; if extraAllowed is nil, no extra |
| 457 | // characters are allowed." |
| 458 | func TestSpec_PublicAPI_SanitizeIdentifierName(t *testing.T) { |
| 459 | t.Run("replaces invalid characters with underscores", func(t *testing.T) { |
| 460 | result := SanitizeIdentifierName("foo-bar.baz", nil) |
| 461 | assert.Equal(t, "foo_bar_baz", result, |
| 462 | "non-identifier characters should be replaced with underscores") |
| 463 | }) |
| 464 | |
| 465 | t.Run("prefixes underscore when starting with digit", func(t *testing.T) { |
| 466 | result := SanitizeIdentifierName("123name", nil) |
| 467 | assert.True(t, strings.HasPrefix(result, "_"), |
| 468 | "result starting with a digit should be prefixed with underscore") |
| 469 | }) |
| 470 | |
| 471 | t.Run("nil extraAllowed permits no extra characters", func(t *testing.T) { |
| 472 | result := SanitizeIdentifierName("a$b", nil) |
| 473 | assert.NotContains(t, result, "$", |
| 474 | "with nil extraAllowed, $ is not preserved") |
| 475 | }) |
| 476 | |
| 477 | t.Run("extraAllowed permits additional runes", func(t *testing.T) { |
| 478 | result := SanitizeIdentifierName("a$b", func(r rune) bool { return r == '$' }) |
| 479 | assert.Contains(t, result, "$", |
| 480 | "extraAllowed returning true for $ should preserve $") |
| 481 | }) |
| 482 | } |
| 483 | |
| 484 | // TestSpec_PublicAPI_SanitizeParameterName validates the documented behavior of |
| 485 | // SanitizeParameterName as described in the package README.md. |
nothing calls this directly
no test coverage detected