 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.var.crossfire.model.validation.checks;
22 import java.awt.Point;
32 import org.jetbrains.annotations.NotNull;
33 import org.junit.Assert;
34 import org.junit.Test;
39 @SuppressWarnings(
"JavaDoc")
44 Assert.assertEquals(
"" +
45 "non-ASCII character" +
46 "", validateRegExErrors(
"รถ"));
51 Assert.assertEquals(
"" +
52 "non-ASCII character" +
53 "", validateRegExErrors(
"\u001F"));
58 Assert.assertEquals(
"" +
59 "negated character range" +
60 "", validateRegExErrors(
"[^a]"));
65 Assert.assertEquals(
"" +
66 "unterminated character range" +
67 "", validateRegExErrors(
"["));
72 Assert.assertEquals(
"" +
73 "unterminated character range" +
74 "", validateRegExErrors(
"[abc"));
79 Assert.assertEquals(
"" +
80 "unterminated character range" +
81 "", validateRegExErrors(
"[-"));
86 Assert.assertEquals(
"" +
87 "unterminated character range" +
88 "", validateRegExErrors(
"[a-"));
93 Assert.assertEquals(
"" +
94 "confusing trailing '-' in character range" +
95 "", validateRegExErrors(
"[a-]"));
100 Assert.assertEquals(
"" +
101 "character ranges should use only a-z, A-Z, or 0-9" +
102 "the word '[a-B]' checks for upper-case letters. Matches are case-insensitive, therefore matches should be specified in lower-case letters only" +
103 "", validateRegExErrors(
"[a-B]"));
108 Assert.assertEquals(
"" +
109 "character ranges should use only a-z, A-Z, or 0-9" +
110 "", validateRegExErrors(
"[0-a]"));
115 Assert.assertEquals(
"", validateRegExErrors(
"[a-z]"));
120 Assert.assertEquals(
"" +
121 "the word '[A-Z]' checks for upper-case letters. Matches are case-insensitive, therefore matches should be specified in lower-case letters only" +
122 "", validateRegExErrors(
"[A-Z]"));
127 Assert.assertEquals(
"", validateRegExErrors(
"[0-9]"));
132 Assert.assertEquals(
"" +
133 "invalid character range" +
134 "", validateRegExErrors(
"[b-a]"));
139 Assert.assertEquals(
"" +
140 "invalid character range" +
141 "the word '[B-A]' checks for upper-case letters. Matches are case-insensitive, therefore matches should be specified in lower-case letters only",
142 validateRegExErrors(
"[B-A]"));
147 Assert.assertEquals(
"" +
148 "invalid character range" +
149 "", validateRegExErrors(
"[1-0]"));
154 Assert.assertEquals(
"" +
155 "single-character character range" +
156 "", validateRegExErrors(
"[a-a]"));
161 Assert.assertEquals(
"" +
162 "single-character character range" +
163 "", validateRegExErrors(
"[a-a]"));
168 Assert.assertEquals(
"" +
169 "duplicate character 'a' in character range" +
170 "", validateRegExErrors(
"[aa]"));
175 Assert.assertEquals(
"" +
176 "duplicate character 'b' in character range" +
177 "", validateRegExErrors(
"[abcbd]"));
182 Assert.assertEquals(
"" +
183 "duplicate character 'b' in character range" +
184 "", validateRegExErrors(
"[a-cb]"));
189 Assert.assertEquals(
"" +
190 "duplicate character 'b' in character range" +
191 "", validateRegExErrors(
"[ba-c]"));
196 Assert.assertEquals(
"" +
197 "duplicate character 'c' in character range" +
198 "", validateRegExErrors(
"[a-ec-f]"));
203 Assert.assertEquals(
"" +
204 "empty character range" +
205 "", validateRegExErrors(
"[]"));
210 Assert.assertEquals(
"" +
211 "the word 'ant[s]' is the same as 'ants' which is probably not what was intended" +
212 "", validateRegExErrors(
"ant[s]"));
217 Assert.assertEquals(
"" +
219 "", validateRegExErrors(
"abc\\"));
224 Assert.assertEquals(
"" +
225 "use of regular expression operator '?'. This is usually not useful and therefore should be avoided" +
226 "", validateRegExErrors(
"a?"));
231 Assert.assertEquals(
"" +
232 "use of regular expression operator '*'. This is usually not useful and therefore should be avoided" +
233 "", validateRegExErrors(
"a*"));
238 Assert.assertEquals(
"" +
239 "use of regular expression operator '+'. This is usually not useful and therefore should be avoided" +
240 "", validateRegExErrors(
"a+"));
245 Assert.assertEquals(
"" +
246 "use of regular expression operator '.'. This is usually not useful and therefore should be avoided" +
247 "", validateRegExErrors(
"a."));
252 Assert.assertEquals(
"" +
253 "use of regular expression operator '\\'. This is usually not useful and therefore should be avoided" +
254 "", validateRegExErrors(
"a\\."));
259 Assert.assertEquals(
"", validateRegExErrors(
"^a"));
264 Assert.assertEquals(
"", validateRegExErrors(
"a[a^]"));
269 Assert.assertEquals(
"" +
270 "the regular expression operator '^' must be used at the start of the word" +
271 "", validateRegExErrors(
"a^"));
276 Assert.assertEquals(
"" +
277 "the regular expression operator '^' must be used at the start of the word" +
278 "", validateRegExErrors(
"a^a"));
283 Assert.assertEquals(
"", validateRegExErrors(
"a$"));
288 Assert.assertEquals(
"", validateRegExErrors(
"[$a]a"));
293 Assert.assertEquals(
"" +
294 "the regular expression operator '$' must be used at the end of the word" +
295 "", validateRegExErrors(
"$a"));
300 Assert.assertEquals(
"" +
301 "the regular expression operator '$' must be used at the end of the word" +
302 "", validateRegExErrors(
"a$a"));
307 Assert.assertEquals(
"" +
308 "the word ' word' starts with a space" +
309 "", validateRegExErrors(
" word"));
314 Assert.assertEquals(
"" +
315 "the word ' word2' starts with a space" +
316 "", validateRegExErrors(
"word1| word2"));
321 Assert.assertEquals(
"" +
322 "the word 'word ' ends with a space" +
323 "", validateRegExErrors(
"word "));
328 Assert.assertEquals(
"" +
329 "the word 'word1 ' ends with a space" +
330 "", validateRegExErrors(
"word1 |word2"));
335 Assert.assertEquals(
"" +
336 "the word 'word1 ' ends with a space" +
337 "the word ' word2' starts with a space" +
338 "", validateRegExErrors(
"word1 | word2"));
343 Assert.assertEquals(
"" +
344 "the word 'hEllo' checks for upper-case letters. Matches are case-insensitive, therefore matches should be specified in lower-case letters only" +
345 "", validateRegExErrors(
"hi|hEllo"));
368 parser.
parse(regEx, generator);
369 final StringBuilder sb =
new StringBuilder();
372 sb.append(error.getParameter(1));
374 Assert.fail(
"invalid validation error: " + error.getClass().getName() +
":" + error);
377 return sb.toString();
An Archetype implementation for testing purposes.
void validateRegEx_wordWithUpperCaseLetter_reportsError()
void validateRegEx_quotedEndOperator_reportsOk()
A @match line contains an invalid regular expression.
A MapModel reflects the data of a map.
void validateRegEx_unterminatedCharacterRange4_reportsError()
Generator for SuspiciousMsgChecker related error messages.
void validateRegEx_trailingBackslash_reportsError()
Base package of all Gridarta classes.
Super class of all errors that could occur during map validation.
void endTransaction()
End a transaction.
A GameObject implementation for testing purposes.
void beginTransaction(@NotNull String name)
Starts a new transaction.
void validateRegEx_operator3_reportsError()
void validateRegEx_operator1_reportsError()
Iterable< ValidationError< G, A, R > > getErrors()
Get all errors.
Helper class for regression tests to create MapModel instances.
void validateRegEx_duplicateCharacterInCharacterRange3_reportsError()
Parser for Crossfire regular expressions.
void addGameObjectToMap(@NotNull G gameObject, @NotNull Point pos, @NotNull InsertionMode insertionMode)
Add a gameObject to the map.
void validateRegEx_lowerCaseLetterCharacterRange_reportsOk()
void validateRegEx_unterminatedCharacterRange1_reportsError()
void validateRegEx_nonAsciiCharacter2_reportsError()
void parse(@NotNull final String regEx, @NotNull final ErrorGenerator<?, ?, ?> generator)
Parses a regular expression.
void validateRegEx_singleCharacterInCharacterRange2_reportsError()
void validateRegEx_beginOperator_reportsOk()
void validateRegEx_endOperatorNotAtEnd2_reportsError()
void validateRegEx_duplicateCharacterInCharacterRange1_reportsError()
GameObjects are the objects based on Archetypes found on maps.
void validateRegEx_operator5_reportsError()
void validateRegEx_backwardCharacterRange2_reportsError()
void validateRegEx_wordWithLeadingSpace2_reportsError()
MapModel< TestGameObject, TestMapArchObject, TestArchetype > newMapModel(final int w, final int h)
Creates a new MapModel instance.
Regression tests for RegExParser.
void validateRegEx_duplicateCharacterInCharacterRange2_reportsError()
void validateRegEx_singleCharacterInCharacterRange1_reportsError()
Main package of Gridarta4Crossfire, contains all classes specific to the Crossfire version of the Gri...
void validateRegEx_emptyCharacterRange_reportsError()
void validateRegEx_trailingMinusInCharacterRange_reportsError()
void validateRegEx_endOperator_reportsOk()
void validateRegEx_wordWithTrailingSpace1_reportsError()
static String validateRegExErrors(@NotNull final String regEx)
Calls RegExParser#parse(String, ErrorGenerator) on a regular expression and returns all error message...
An interface for classes that collect errors.
This package contains the framework for validating maps.
void validateRegEx_wordWithLeadingSpace1_reportsError()
void validateRegEx_operator2_reportsError()
void validateRegEx_operator4_reportsError()
void validateRegEx_negatedCharacterRange_reportsError()
void validateRegEx_duplicateCharacterInCharacterRange5_reportsError()
void validateRegEx_unterminatedCharacterRange2_reportsError()
TestGameObject newGameObject(@NotNull final String archetypeName, @NotNull final String objectName)
Creates a new game object.
InsertionMode getTopmostInsertionMode()
Returns the "topmost" insertion mode.
void validateRegEx_invalidCharacterRange1_reportsError()
void validateRegEx_backwardCharacterRange1_reportsError()
void validateRegEx_wordWithTrailingSpace2_reportsError()
void validateRegEx_quotedBeginOperator_reportsOk()
void validateRegEx_backwardCharacterRange3_reportsError()
void validateRegEx_duplicateCharacterInCharacterRange4_reportsError()
void validateRegEx_beginOperatorNotAtStart1_reportsError()
void validateRegEx_endOperatorNotAtEnd1_reportsError()
void validateRegEx_beginOperatorNotAtStart2_reportsError()
void validateRegEx_nonAsciiCharacter1_reportsError()
void validateRegEx_invalidCharacterRange2_reportsError()
void validateRegEx_unterminatedCharacterRange3_reportsError()
A MapArchObject implementation for testing purposes.
Simple error collector that just collects the error in a collection for later retrieval through itera...
void validateRegEx_upperCaseLetterCharacterRange_reportsError()
void validateRegEx_digitCharacterRange_reportsOk()
void validateRegEx_singleCharCharacterRange_reportsError()
void validateRegEx_wordWithLeadingAndTrailingSpace_reportsError()