Skip to content

Commit

Permalink
First draft of csharp test rewrites
Browse files Browse the repository at this point in the history
  • Loading branch information
TwoOfTwelve committed Sep 27, 2023
1 parent dd1a20d commit 79fef14
Show file tree
Hide file tree
Showing 4 changed files with 1,130 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ public void enterAccessor_declarations(Accessor_declarationsContext context) {

@Override
public void exitAccessor_declarations(Accessor_declarationsContext context) {
transformToken(ACCESSORS_END, context.getStart());
transformToken(ACCESSORS_END, context.getStop());
super.enterAccessor_declarations(context);
}

Expand All @@ -494,7 +494,7 @@ public void enterAccessor_body(Accessor_bodyContext context) {

@Override
public void exitAccessor_body(Accessor_bodyContext context) {
transformToken(ACCESSOR_END, context.getStart());
transformToken(ACCESSOR_END, context.getStop());
super.exitAccessor_body(context);
}

Expand Down
64 changes: 64 additions & 0 deletions languages/csharp/src/test/java/de/jplag/csharp/CSharpTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package de.jplag.csharp;

import de.jplag.testutils.LanguageModuleTest;
import de.jplag.testutils.datacollector.TestDataCollector;
import de.jplag.testutils.datacollector.TestSourceIgnoredLinesCollector;

import java.util.ArrayList;
import java.util.List;

import static de.jplag.csharp.CSharpTokenType.ACCESSORS_BEGIN;
import static de.jplag.csharp.CSharpTokenType.ACCESSORS_END;
import static de.jplag.csharp.CSharpTokenType.ACCESSOR_BEGIN;
import static de.jplag.csharp.CSharpTokenType.ACCESSOR_END;
import static de.jplag.csharp.CSharpTokenType.ASSIGNMENT;
import static de.jplag.csharp.CSharpTokenType.CLASS;
import static de.jplag.csharp.CSharpTokenType.CLASS_BEGIN;
import static de.jplag.csharp.CSharpTokenType.CLASS_END;
import static de.jplag.csharp.CSharpTokenType.CONSTRUCTOR;
import static de.jplag.csharp.CSharpTokenType.FIELD;
import static de.jplag.csharp.CSharpTokenType.IF;
import static de.jplag.csharp.CSharpTokenType.IF_BEGIN;
import static de.jplag.csharp.CSharpTokenType.IF_END;
import static de.jplag.csharp.CSharpTokenType.INVOCATION;
import static de.jplag.csharp.CSharpTokenType.LOCAL_VARIABLE;
import static de.jplag.csharp.CSharpTokenType.METHOD;
import static de.jplag.csharp.CSharpTokenType.METHOD_BEGIN;
import static de.jplag.csharp.CSharpTokenType.METHOD_END;
import static de.jplag.csharp.CSharpTokenType.PROPERTY;
import static de.jplag.csharp.CSharpTokenType.RETURN;

public class CSharpTest extends LanguageModuleTest {
public CSharpTest() {
super(new CSharpLanguage(), CSharpTokenType.class);
}

@Override
protected void collectTestData(TestDataCollector collector) {
collector.testFile("TestClass.cs").testSourceCoverage().testTokenSequence(CLASS, CLASS_BEGIN, FIELD, CONSTRUCTOR, LOCAL_VARIABLE, METHOD, METHOD_BEGIN, IF, IF_BEGIN,
INVOCATION, IF_END, IF_BEGIN, INVOCATION, IF_END, METHOD_END, PROPERTY, ACCESSORS_BEGIN, ACCESSOR_BEGIN, ACCESSOR_END, ACCESSOR_BEGIN,
ACCESSOR_END, ACCESSORS_END, FIELD, PROPERTY, ACCESSORS_BEGIN, ACCESSOR_BEGIN, RETURN, ACCESSOR_END, ACCESSOR_BEGIN, ASSIGNMENT,
ACCESSOR_END, ACCESSORS_END, CLASS_END);

ArrayList<CSharpTokenType> tokens = new ArrayList<>(List.of(CSharpTokenType.values()));
tokens.remove(CSharpTokenType.INTERFACE_BEGIN);
tokens.remove(CSharpTokenType.INTERFACE_END);
collector.testFile("AllInOneNoPreprocessor.cs")./*testSourceCoverage().*/testContainedTokens(tokens.toArray(CSharpTokenType[]::new));
}

@Override
protected void configureIgnoredLines(TestSourceIgnoredLinesCollector collector) {
collector.ignoreMultipleLines("/*", "*/");
collector.ignoreLinesByPrefix("//");
collector.ignoreLinesByPrefix("{");
collector.ignoreLinesByPrefix("}");

collector.ignoreLinesByPrefix("extern");
collector.ignoreLinesByPrefix("using");
collector.ignoreLinesByPrefix("namespace");
collector.ignoreLinesByPrefix("base");
collector.ignoreLinesByPrefix("++");

collector.ignoreByCondition(line -> line.trim().matches("[a-zA-Z0-9]+:"));
}
}
Loading

0 comments on commit 79fef14

Please sign in to comment.