Skip to content

Commit

Permalink
more tests restored
Browse files Browse the repository at this point in the history
  • Loading branch information
VISTALL committed Jan 15, 2025
1 parent fa45829 commit c728e9a
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 83 deletions.
82 changes: 0 additions & 82 deletions csharp-impl/src/test/java_/consulo/csharp/VmQNameTest.java

This file was deleted.

97 changes: 97 additions & 0 deletions tests/src/test/java/consulo/csharp/VmQNameTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2013-2017 consulo.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package consulo.csharp;

import consulo.annotation.access.RequiredReadAction;
import consulo.csharp.lang.CSharpFileType;
import consulo.dotnet.psi.DotNetTypeDeclaration;
import consulo.language.psi.PsiElement;
import consulo.language.psi.PsiFile;
import consulo.language.psi.PsiFileFactory;
import consulo.language.psi.util.PsiTreeUtil;
import consulo.test.junit.impl.extension.ConsuloProjectLoader;
import consulo.test.junit.impl.extension.NoParamDisplayNameGenerator;
import consulo.test.junit.impl.language.SimpleParsingTest;
import consulo.util.io.StreamUtil;
import jakarta.annotation.Nonnull;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtendWith;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;

/**
* @author VISTALL
* @since 08.04.2016
*/
@ExtendWith(ConsuloProjectLoader.class)
@DisplayNameGeneration(NoParamDisplayNameGenerator.class)
public class VmQNameTest {
private static final String ourTarget = "<target>";

@RequiredReadAction
@Test
public void testNormalType(TestInfo testInfo, PsiFileFactory psiFileFactory) throws Exception {
assertEqualVmQName(testInfo, psiFileFactory, "System.Media.Maybe", "Maybe");
}

@RequiredReadAction
@Test
public void testGenericType(TestInfo testInfo, PsiFileFactory psiFileFactory) throws Exception {
assertEqualVmQName(testInfo, psiFileFactory, "System.Test`4", "Test`4");
}

@RequiredReadAction
@Test
public void testNestedGenericType(TestInfo testInfo, PsiFileFactory psiFileFactory) throws Exception {
assertEqualVmQName(testInfo, psiFileFactory, "System.Test`4/AA`1", "AA`1");
}

@RequiredReadAction
@Test
private void assertEqualVmQName(@Nonnull TestInfo testInfo,
@Nonnull PsiFileFactory psiFileFactory,
@Nonnull String vmQName,
@Nonnull String vmName) throws Exception {
String testResName = NoParamDisplayNameGenerator.getName(testInfo.getTestMethod().get().getName(), false);

InputStream stream = getClass().getResourceAsStream("/vmqname/" + testResName + CSharpFileType.DOT_EXTENSION);

String text = StreamUtil.readText(stream, StandardCharsets.UTF_8);
int index = text.indexOf(ourTarget);
if (index == -1) {
throw new IllegalArgumentException("no target set");
}
text = text.replace(ourTarget, "");

PsiFile psiFile = psiFileFactory.createFileFromText("test.cs", CSharpFileType.INSTANCE, text);

SimpleParsingTest.ensureParsed(psiFile);

PsiElement elementAt = psiFile.findElementAt(index);
DotNetTypeDeclaration declaration = PsiTreeUtil.getParentOfType(elementAt, DotNetTypeDeclaration.class);
if (declaration == null) {
throw new IllegalArgumentException("no type");
}

Assertions.assertEquals(vmQName, declaration.getVmQName(), "VmQName is not equal");
Assertions.assertEquals(vmName, declaration.getVmName(), "VmName is not equal");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package preprocessorTest;
package consulo.csharp.preprocessorTest;

import consulo.csharp.lang.impl.parser.preprocessor.IfPreprocessorDirective;
import consulo.csharp.lang.impl.parser.preprocessor.PreprocessorDirective;
Expand Down

0 comments on commit c728e9a

Please sign in to comment.