TestSpec_PublicAPI_SanitizeName validates the documented behavior of SanitizeName as described in the package README.md. Specification: "Sanitizes a name for identifiers and filenames using configurable behavior (preserved special characters, optional hyphen trimming, and fallback default value)."
(t *testing.T)
| 813 | // The README documents the SanitizeOptions type as: "Options for SanitizeName |
| 814 | // (preserved characters, hyphen trimming, and default value)." |
| 815 | func TestSpec_PublicAPI_SanitizeName(t *testing.T) { |
| 816 | t.Run("uses default value when sanitized result would be empty", func(t *testing.T) { |
| 817 | opts := &SanitizeOptions{DefaultValue: "fallback"} |
| 818 | result := SanitizeName("!!!", opts) |
| 819 | assert.Equal(t, "fallback", result, |
| 820 | "SanitizeName should return DefaultValue when sanitization yields an empty string") |
| 821 | }) |
| 822 | |
| 823 | t.Run("TrimHyphens removes leading and trailing hyphens", func(t *testing.T) { |
| 824 | opts := &SanitizeOptions{TrimHyphens: true} |
| 825 | result := SanitizeName("---hello---", opts) |
| 826 | assert.NotEmpty(t, result, |
| 827 | "SanitizeName should return non-empty result") |
| 828 | assert.False(t, strings.HasPrefix(result, "-"), |
| 829 | "SanitizeName with TrimHyphens=true should not return a result with leading '-'") |
| 830 | assert.False(t, strings.HasSuffix(result, "-"), |
| 831 | "SanitizeName with TrimHyphens=true should not return a result with trailing '-'") |
| 832 | }) |
| 833 | |
| 834 | t.Run("PreserveSpecialChars preserves listed characters", func(t *testing.T) { |
| 835 | opts := &SanitizeOptions{PreserveSpecialChars: []rune{'.'}} |
| 836 | result := SanitizeName("file.name", opts) |
| 837 | assert.Contains(t, result, ".", |
| 838 | "SanitizeName with '.' in PreserveSpecialChars should preserve '.'") |
| 839 | }) |
| 840 | |
| 841 | t.Run("nil options is accepted", func(t *testing.T) { |
| 842 | result := SanitizeName("hello", nil) |
| 843 | assert.NotEmpty(t, result, |
| 844 | "SanitizeName should accept nil options and return a non-empty sanitized name") |
| 845 | }) |
| 846 | } |
| 847 | |
| 848 | // TestSpec_PublicAPI_FindClosestMatches validates the documented behavior of |
| 849 | // FindClosestMatches as described in the package README.md. |
nothing calls this directly
no test coverage detected