TestTokenizerError tests error creation and formatting functions.
(t *testing.T)
| 98 | |
| 99 | // TestTokenizerError tests error creation and formatting functions. |
| 100 | func TestTokenizerError(t *testing.T) { |
| 101 | loc := models.Location{ |
| 102 | Line: 2, |
| 103 | Column: 5, |
| 104 | } |
| 105 | |
| 106 | t.Run("NewError creates error with location", func(t *testing.T) { |
| 107 | err := NewError("test error message", loc) |
| 108 | if err == nil { |
| 109 | t.Fatal("NewError() returned nil") |
| 110 | } |
| 111 | |
| 112 | errStr := err.Error() |
| 113 | if !strings.Contains(errStr, "test error message") { |
| 114 | t.Errorf("Error message doesn't contain expected text: %s", errStr) |
| 115 | } |
| 116 | if !strings.Contains(errStr, "line 2") { |
| 117 | t.Errorf("Error message doesn't contain line number: %s", errStr) |
| 118 | } |
| 119 | if !strings.Contains(errStr, "column 5") { |
| 120 | t.Errorf("Error message doesn't contain column number: %s", errStr) |
| 121 | } |
| 122 | }) |
| 123 | |
| 124 | t.Run("ErrorUnexpectedChar creates appropriate error", func(t *testing.T) { |
| 125 | err := ErrorUnexpectedChar('$', loc) |
| 126 | if err == nil { |
| 127 | t.Fatal("ErrorUnexpectedChar() returned nil") |
| 128 | } |
| 129 | |
| 130 | errStr := err.Error() |
| 131 | if !strings.Contains(errStr, "$") || !strings.Contains(errStr, "unexpected") { |
| 132 | t.Errorf("ErrorUnexpectedChar message doesn't mention unexpected char: %s", errStr) |
| 133 | } |
| 134 | }) |
| 135 | |
| 136 | t.Run("ErrorUnterminatedString creates appropriate error", func(t *testing.T) { |
| 137 | err := ErrorUnterminatedString(loc) |
| 138 | if err == nil { |
| 139 | t.Fatal("ErrorUnterminatedString() returned nil") |
| 140 | } |
| 141 | |
| 142 | errStr := err.Error() |
| 143 | if !strings.Contains(errStr, "unterminated") || !strings.Contains(errStr, "string") { |
| 144 | t.Errorf("ErrorUnterminatedString message doesn't mention unterminated string: %s", errStr) |
| 145 | } |
| 146 | }) |
| 147 | |
| 148 | t.Run("ErrorInvalidNumber creates appropriate error", func(t *testing.T) { |
| 149 | err := ErrorInvalidNumber("12.34.56", loc) |
| 150 | if err == nil { |
| 151 | t.Fatal("ErrorInvalidNumber() returned nil") |
| 152 | } |
| 153 | |
| 154 | errStr := err.Error() |
| 155 | if !strings.Contains(errStr, "12.34.56") || !strings.Contains(errStr, "invalid") { |
| 156 | t.Errorf("ErrorInvalidNumber message doesn't describe issue: %s", errStr) |
| 157 | } |
nothing calls this directly
no test coverage detected