Skip to content

Commit 6498ef1

Browse files
committed
test: ensure all patterns of syntax files in langpack are parseable
1 parent 513eb04 commit 6498ef1

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

  • org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/parser

org.eclipse.tm4e.core/src/test/java/org/eclipse/tm4e/core/internal/parser/TMParserTest.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@
2323
import java.nio.file.Paths;
2424
import java.nio.file.SimpleFileVisitor;
2525
import java.nio.file.attribute.BasicFileAttributes;
26+
import java.util.Collection;
2627
import java.util.List;
2728
import java.util.Set;
2829
import java.util.concurrent.atomic.AtomicInteger;
2930

3031
import org.eclipse.jdt.annotation.NonNullByDefault;
32+
import org.eclipse.jdt.annotation.Nullable;
3133
import org.eclipse.tm4e.core.Data;
34+
import org.eclipse.tm4e.core.internal.grammar.raw.IRawRule;
3235
import org.eclipse.tm4e.core.internal.grammar.raw.RawGrammar;
3336
import org.eclipse.tm4e.core.internal.grammar.raw.RawGrammarReader;
37+
import org.eclipse.tm4e.core.internal.oniguruma.OnigRegExp;
3438
import org.eclipse.tm4e.core.internal.utils.ResourceUtils;
3539
import org.junit.jupiter.api.MethodOrderer;
3640
import org.junit.jupiter.api.Test;
@@ -197,6 +201,33 @@ void testParseYAML() throws Exception {
197201
}
198202
}
199203

204+
private void assertParseablePattern(final @Nullable String pattern) {
205+
if (pattern == null)
206+
return;
207+
try {
208+
assertNotNull(new OnigRegExp(pattern));
209+
} catch (final RuntimeException ex) {
210+
final var msg = ex.getMessage();
211+
if (msg != null && msg.contains("invalid backref number/name")) {
212+
// ignore
213+
} else
214+
throw ex;
215+
}
216+
}
217+
218+
private void assertParseablePatterns(final @Nullable Collection<IRawRule> patterns) {
219+
if (patterns == null || patterns.isEmpty())
220+
return;
221+
222+
for (final var rule : patterns) {
223+
assertParseablePattern(rule.getBegin());
224+
assertParseablePattern(rule.getEnd());
225+
assertParseablePattern(rule.getMatch());
226+
assertParseablePattern(rule.getWhile());
227+
assertParseablePatterns(rule.getPatterns());
228+
}
229+
}
230+
200231
@Test
201232
@NonNullByDefault({})
202233
void testLanguagePackGrammars() throws IOException {
@@ -210,9 +241,12 @@ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attr
210241
final var grammar = TMParserJSON.INSTANCE.parse(input, RawGrammarReader.OBJECT_FACTORY);
211242
count.incrementAndGet();
212243
assertFalse(grammar.getScopeName().isBlank());
213-
assertFalse(castNonNull(grammar.getPatterns()).isEmpty());
214244
assertNotNull(grammar.getFileTypes());
215245
assertNotNull(grammar.getRepository());
246+
247+
final var patterns = castNonNull(grammar.getPatterns());
248+
assertFalse(patterns.isEmpty());
249+
assertParseablePatterns(patterns);
216250
} catch (final Exception ex) {
217251
throw new RuntimeException(ex);
218252
}

0 commit comments

Comments
 (0)