<commit_before>package org.rust.lang.core.resolve

import com.intellij.psi.PsiElement
import com.intellij.util.indexing.FileBasedIndex
import org.assertj.core.api.Assertions.assertThat
import org.rust.lang.RustTestCaseBase
import org.rust.lang.core.psi.RustNamedElement
import org.rust.lang.core.resolve.indexes.RustModulesIndex
import org.rust.lang.core.resolve.ref.RustReference

abstract class RustResolveTestCaseBase : RustTestCaseBase() {

    override val dataPath = "org/rust/lang/core/resolve/fixtures"

    private fun assertIsValidDeclaration(declaration: PsiElement, usage: RustReference,
                                         expectedOffset: Int?) {

        assertThat(declaration).isInstanceOf(RustNamedElement::class.java)
        declaration as RustNamedElement


        if (expectedOffset != null) {
            assertThat(declaration.textOffset).isEqualTo(expectedOffset)
        } else {
            assertThat(declaration.name).isEqualTo(usage.element.name)
        }
    }

    override fun setUp() {
        super.setUp()

        // Invalidate cache for every run
        FileBasedIndex
            .getInstance()
            .requestRebuild(RustModulesIndex.ID)
    }

    protected fun checkIsBound(atOffset: Int? = null) {
        val usage = myFixture.getReferenceAtCaretPosition(fileName) as RustReference
        assertThat(usage.resolve())
            .withFailMessage("Failed to resolve `${usage.element.text}`.")
            .isNotNull()
        val declaration = usage.resolve()!!

        assertIsValidDeclaration(declaration, usage, atOffset)
    }

    protected fun checkIsUnbound() {
        val usage = myFixture.getReferenceAtCaretPosition(fileName) as RustReference
        val declaration = usage.resolve()

        assertThat(declaration).isNull()
    }
}<commit_msg>(T): better assert messages for resolve tests<commit_after>package org.rust.lang.core.resolve

import com.intellij.psi.PsiElement
import com.intellij.util.indexing.FileBasedIndex
import org.assertj.core.api.Assertions.assertThat
import org.rust.lang.RustTestCaseBase
import org.rust.lang.core.psi.RustNamedElement
import org.rust.lang.core.resolve.indexes.RustModulesIndex
import org.rust.lang.core.resolve.ref.RustReference

abstract class RustResolveTestCaseBase : RustTestCaseBase() {

    override val dataPath = "org/rust/lang/core/resolve/fixtures"

    private fun assertIsValidDeclaration(declaration: PsiElement, usage: RustReference,
                                         expectedOffset: Int?) {

        assertThat(declaration).isInstanceOf(RustNamedElement::class.java)
        declaration as RustNamedElement


        if (expectedOffset != null) {
            assertThat(declaration.textOffset).isEqualTo(expectedOffset)
        } else {
            assertThat(declaration.name).isEqualTo(usage.element.name)
        }
    }

    override fun setUp() {
        super.setUp()

        // Invalidate cache for every run
        FileBasedIndex
            .getInstance()
            .requestRebuild(RustModulesIndex.ID)
    }

    protected fun checkIsBound(atOffset: Int? = null) {
        val usage = getReference()
        assertThat(usage.resolve())
            .withFailMessage("Failed to resolve `${usage.element.text}`.")
            .isNotNull()
        val declaration = usage.resolve()!!

        assertIsValidDeclaration(declaration, usage, atOffset)
    }

    protected fun checkIsUnbound() {
        val declaration = getReference().resolve()
        assertThat(declaration).isNull()
    }

    private fun getReference(): RustReference {
        return requireNotNull(myFixture.getReferenceAtCaretPosition(fileName)) {
            "No reference at caret in `$fileName`"
        } as RustReference
    }
}
{'fraction_non_alphanumeric': 0.09367493995196156, 'fraction_numerical': 0.0, 'mean_word_length': 2.904166666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3751794', 'n_tokens_mistral': 1014, 'n_tokens_neox': 1007, 'n_words': 189}