<commit_before>package xsbt

import org.junit.runner.RunWith
import xsbti.api.ClassLike
import xsbti.api.Def
import xsbt.api.SameAPI
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner

import ScalaCompilerForUnitTesting.ExtractedSourceDependencies

@RunWith(classOf[JUnitRunner])
class DependencySpecification extends Specification {

	"Extracted source dependencies from public members" in {
		val sourceDependencies = extractSourceDependenciesPublic
		val memberRef = sourceDependencies.memberRef
		val inheritance = sourceDependencies.inheritance
		memberRef('A) === Set.empty
		inheritance('A) === Set.empty
		memberRef('B) === Set('A, 'D)
		inheritance('B) === Set('D)
		memberRef('C) === Set('A)
		inheritance('C) === Set.empty
		memberRef('D) === Set.empty
		inheritance('D) === Set.empty
		memberRef('E) === Set.empty
		inheritance('E) === Set.empty
		memberRef('F) === Set('A, 'B, 'C, 'D, 'E)
		inheritance('F) === Set('A, 'C, 'E)
		memberRef('H) === Set('G, 'E)
		// aliases and applied type constructors are expanded so we have inheritance dependency on B
		inheritance('H) === Set('D, 'E, 'B)
	}

	"Extracted source dependencies from private members" in {
		val sourceDependencies = extractSourceDependenciesPrivate
		val memberRef = sourceDependencies.memberRef
		val inheritance = sourceDependencies.inheritance
		memberRef('A) === Set.empty
		inheritance('A) === Set.empty
		memberRef('B) === Set.empty
		inheritance('B) === Set.empty
		memberRef('C) === Set('A)
		inheritance('C) === Set.empty
		memberRef('D) === Set('B)
		inheritance('D) === Set.empty
	}

	private def extractSourceDependenciesPublic: ExtractedSourceDependencies = {
		val srcA = "class A"
		val srcB = "class B extends D[A]"
		val srcC = """|class C {
		  |  def a: A = null
		  |}""".stripMargin
		val srcD = "class D[T]"
		val srcE = "trait E[T]"
		val srcF = "trait F extends A with E[D[B]] { self: C => }"
		val srcG = "object G { type T[x] = B }"
		// T is a type constructor [x]B
		// B extends D
		// E verifies the core type gets pulled out
		val srcH = "trait H extends G.T[Int] with (E[Int] @unchecked)"

		val compilerForTesting = new ScalaCompilerForUnitTesting(memberRefAndInheritanceDeps = false)
		val sourceDependencies = compilerForTesting.extractDependenciesFromSrcs('A -> srcA, 'B -> srcB, 'C -> srcC,
			'D -> srcD, 'E -> srcE, 'F -> srcF, 'G -> srcG, 'H -> srcH)
		sourceDependencies
	}

	private def extractSourceDependenciesPrivate: ExtractedSourceDependencies = {
		val srcA = "class A"
		val srcB = "class B"
		val srcC = "class C { private class Inner1 extends A }"
		val srcD = "class D { def foo: Unit = { class Inner2 extends B } }"

		val compilerForTesting = new ScalaCompilerForUnitTesting(memberRefAndInheritanceDeps = false)
		val sourceDependencies =
			compilerForTesting.extractDependenciesFromSrcs('A -> srcA, 'B -> srcB, 'C -> srcC, 'D -> srcD)
		sourceDependencies
	}
}<commit_msg>Test `memberRef` and `inheritance` in DependencySpecification.<commit_after>package xsbt

import org.junit.runner.RunWith
import xsbti.api.ClassLike
import xsbti.api.Def
import xsbt.api.SameAPI
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner

import ScalaCompilerForUnitTesting.ExtractedSourceDependencies

@RunWith(classOf[JUnitRunner])
class DependencySpecification extends Specification {

	"Extracted source dependencies from public members" in {
		val sourceDependencies = extractSourceDependenciesPublic
		val memberRef = sourceDependencies.memberRef
		val inheritance = sourceDependencies.inheritance
		memberRef('A) === Set.empty
		inheritance('A) === Set.empty
		memberRef('B) === Set('A, 'D)
		inheritance('B) === Set('D)
		memberRef('C) === Set('A)
		inheritance('C) === Set.empty
		memberRef('D) === Set.empty
		inheritance('D) === Set.empty
		memberRef('E) === Set.empty
		inheritance('E) === Set.empty
		memberRef('F) === Set('A, 'B, 'C, 'D, 'E)
		inheritance('F) === Set('A, 'E)
		memberRef('H) === Set('B, 'E, 'G)
		// aliases and applied type constructors are expanded so we have inheritance dependency on B
		inheritance('H) === Set('B, 'E)
	}

	"Extracted source dependencies from private members" in {
		val sourceDependencies = extractSourceDependenciesPrivate
		val memberRef = sourceDependencies.memberRef
		val inheritance = sourceDependencies.inheritance
		memberRef('A) === Set.empty
		inheritance('A) === Set.empty
		memberRef('B) === Set.empty
		inheritance('B) === Set.empty
		memberRef('C) === Set('A)
		inheritance('C) === Set('A)
		memberRef('D) === Set('B)
		inheritance('D) === Set('B)
	}

	private def extractSourceDependenciesPublic: ExtractedSourceDependencies = {
		val srcA = "class A"
		val srcB = "class B extends D[A]"
		val srcC = """|class C {
		  |  def a: A = null
		  |}""".stripMargin
		val srcD = "class D[T]"
		val srcE = "trait E[T]"
		val srcF = "trait F extends A with E[D[B]] { self: C => }"
		val srcG = "object G { type T[x] = B }"
		// T is a type constructor [x]B
		// B extends D
		// E verifies the core type gets pulled out
		val srcH = "trait H extends G.T[Int] with (E[Int] @unchecked)"

		val compilerForTesting = new ScalaCompilerForUnitTesting(memberRefAndInheritanceDeps = true)
		val sourceDependencies = compilerForTesting.extractDependenciesFromSrcs('A -> srcA, 'B -> srcB, 'C -> srcC,
			'D -> srcD, 'E -> srcE, 'F -> srcF, 'G -> srcG, 'H -> srcH)
		sourceDependencies
	}

	private def extractSourceDependenciesPrivate: ExtractedSourceDependencies = {
		val srcA = "class A"
		val srcB = "class B"
		val srcC = "class C { private class Inner1 extends A }"
		val srcD = "class D { def foo: Unit = { class Inner2 extends B } }"

		val compilerForTesting = new ScalaCompilerForUnitTesting(memberRefAndInheritanceDeps = true)
		val sourceDependencies =
			compilerForTesting.extractDependenciesFromSrcs('A -> srcA, 'B -> srcB, 'C -> srcC, 'D -> srcD)
		sourceDependencies
	}
}
{'fraction_non_alphanumeric': 0.13666384419983066, 'fraction_numerical': 0.001354784081287045, 'mean_word_length': 4.39853747714808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6889614', 'n_tokens_mistral': 2113, 'n_tokens_neox': 1918, 'n_words': 538}