TestErrorSpecialCharacters tests Error with special characters and edge cases
(t *testing.T)
| 69 | |
| 70 | // TestErrorSpecialCharacters tests Error with special characters and edge cases |
| 71 | func TestErrorSpecialCharacters(t *testing.T) { |
| 72 | testCases := []struct { |
| 73 | name string |
| 74 | errorName string |
| 75 | message string |
| 76 | expectedErr string |
| 77 | }{ |
| 78 | { |
| 79 | "unicode_characters", |
| 80 | "UnicodeError", |
| 81 | "处理中文字符时出错", |
| 82 | "UnicodeError: 处理中文字符时出错", |
| 83 | }, |
| 84 | { |
| 85 | "special_symbols", |
| 86 | "SymbolError", |
| 87 | "Error with symbols: @#$%^&*()", |
| 88 | "SymbolError: Error with symbols: @#$%^&*()", |
| 89 | }, |
| 90 | { |
| 91 | "newlines_and_tabs", |
| 92 | "FormatError", |
| 93 | "Error with\nnewlines\tand\ttabs", |
| 94 | "FormatError: Error with\nnewlines\tand\ttabs", |
| 95 | }, |
| 96 | { |
| 97 | "quotes", |
| 98 | "QuoteError", |
| 99 | `Error with "double" and 'single' quotes`, |
| 100 | `QuoteError: Error with "double" and 'single' quotes`, |
| 101 | }, |
| 102 | { |
| 103 | "colons_only", |
| 104 | ":", |
| 105 | ":", |
| 106 | ":: :", |
| 107 | }, |
| 108 | { |
| 109 | "whitespace_only", |
| 110 | " ", |
| 111 | "\t\n ", |
| 112 | " : \t\n ", |
| 113 | }, |
| 114 | { |
| 115 | "control_characters", |
| 116 | "ControlError", |
| 117 | "Message with \x00 null byte and \x07 bell", |
| 118 | "ControlError: Message with \x00 null byte and \x07 bell", |
| 119 | }, |
| 120 | } |
| 121 | |
| 122 | for _, tc := range testCases { |
| 123 | t.Run(tc.name, func(t *testing.T) { |
| 124 | err := &Error{ |
| 125 | Name: tc.errorName, |
| 126 | Message: tc.message, |
| 127 | } |
| 128 | require.EqualValues(t, tc.expectedErr, err.Error()) |