<commit_before>package vsolver

import (
	"fmt"
	"strings"
)

// dsp - "depspec with packages"
//
// Wraps a set of tpkgs onto a depspec, and returns it.
func dsp(ds depspec, pkgs ...tpkg) depspec {
	ds.pkgs = pkgs
	return ds
}

// pk makes a tpkg appropriate for use in bimodal testing
func pk(path string, imports ...string) tpkg {
	return tpkg{
		path:    path,
		imports: imports,
	}
}

func init() {
	for k, fix := range bimodalFixtures {
		// Assign the name into the fixture itself
		fix.n = k
		bimodalFixtures[k] = fix
	}
}

// Fixtures that rely on simulated bimodal (project and package-level)
// analysis for correct operation. These all have some extra work done on
// them down in init().
var bimodalFixtures = map[string]bimodalFixture{
	// Simple case, ensures that we do the very basics of picking up and
	// including a single, simple import that is expressed an import
	"simple bimodal add": {
		ds: []depspec{
			dsp(dsv("root 0.0.0"),
				pk("root", "a")),
			dsp(dsv("a 1.0.0"),
				pk("a")),
		},
		r: mkresults(
			"a 1.0.0",
		),
	},
	// Ensure it works when the import jump is not from the package with the
	// same path as root, but from a subpkg
	"subpkg bimodal add": {
		ds: mkbmu(
			dsp(dsv("root 0.0.0"),
				pk("root", "root/foo"),
				pk("root/foo", "a"),
			),
			dsp(dsv("a 1.0.0"),
				pk("a"),
			),
		),
		r: mkresults(
			"a 1.0.0",
		),
	},
	// Ensure that if a constraint is expressed, but no actual import exists,
	// then the constraint is disregarded - the project named in the constraint
	// is not part of the solution.
	"ignore constraint without import": {
		ds: mkbmu(
			dsp(dsv("root 0.0.0", "a 1.0.0"),
				pk("root", "root/foo"),
			),
			dsp(dsv("a 1.0.0"),
				pk("a"),
			),
		),
		r: mkresults(),
	},
}

type tpkg struct {
	// Full import path of this package
	path string
	// Slice of full paths to its virtual imports
	imports []string
}

type bmelem interface {
	_bmelem()
}

func (p tpkg) _bmelem() {}

type bimodalFixture struct {<commit_msg>Several more tests; transitive subpkg fails<commit_after>package vsolver

import (
	"fmt"
	"strings"
)

// dsp - "depspec with packages"
//
// Wraps a set of tpkgs onto a depspec, and returns it.
func dsp(ds depspec, pkgs ...tpkg) depspec {
	ds.pkgs = pkgs
	return ds
}

// pkg makes a tpkg appropriate for use in bimodal testing
func pkg(path string, imports ...string) tpkg {
	return tpkg{
		path:    path,
		imports: imports,
	}
}

func init() {
	for k, fix := range bimodalFixtures {
		// Assign the name into the fixture itself
		fix.n = k
		bimodalFixtures[k] = fix
	}
}

// Fixtures that rely on simulated bimodal (project and package-level)
// analysis for correct operation. These all have some extra work done on
// them down in init().
var bimodalFixtures = map[string]bimodalFixture{
	// Simple case, ensures that we do the very basics of picking up and
	// including a single, simple import that is expressed an import
	"simple bm-add": {
		ds: []depspec{
			dsp(dsv("root 0.0.0"),
				pkg("root", "a")),
			dsp(dsv("a 1.0.0"),
				pkg("a")),
		},
		r: mkresults(
			"a 1.0.0",
		),
	},
	// Ensure it works when the import jump is not from the package with the
	// same path as root, but from a subpkg
	"subpkg bm-add": {
		ds: []depspec{
			dsp(dsv("root 0.0.0"),
				pkg("root", "root/foo"),
				pkg("root/foo", "a"),
			),
			dsp(dsv("a 1.0.0"),
				pkg("a"),
			),
		},
		r: mkresults(
			"a 1.0.0",
		),
	},
	// Importing package from project with no root package
	"bm-add on project with no pkg in root dir": {
		ds: []depspec{
			dsp(dsv("root 0.0.0"),
				pkg("root", "a/foo")),
			dsp(dsv("a 1.0.0"),
				pkg("a/foo")),
		},
		r: mkresults(
			"a 1.0.0",
		),
	},
	// Import jump is in a dep, and points to a transitive dep
	"transitive bm-add": {
		ds: []depspec{
			dsp(dsv("root 0.0.0"),
				pkg("root", "root/foo"),
				pkg("root/foo", "a"),
			),
			dsp(dsv("a 1.0.0"),
				pkg("a", "b"),
			),
			dsp(dsv("b 1.0.0"),
				pkg("b"),
			),
		},
		r: mkresults(
			"a 1.0.0",
			"b 1.0.0",
		),
	},
	// Import jump is in a dep subpkg, and points to a transitive dep
	"transitive subpkg bm-add": {
		ds: []depspec{
			dsp(dsv("root 0.0.0"),
				pkg("root", "root/foo"),
				pkg("root/foo", "a"),
			),
			dsp(dsv("a 1.0.0"),
				pkg("a", "a/bar"),
				pkg("a/bar", "b"),
			),
			dsp(dsv("b 1.0.0"),
				pkg("b"),
			),
		},
		r: mkresults(
			"a 1.0.0",
			"b 1.0.0",
		),
	},
	// Ensure that if a constraint is expressed, but no actual import exists,
	// then the constraint is disregarded - the project named in the constraint
	// is not part of the solution.
	"ignore constraint without import": {
		ds: []depspec{
			dsp(dsv("root 0.0.0", "a 1.0.0"),
				pkg("root", "root/foo"),
			),
			dsp(dsv("a 1.0.0"),
				pkg("a"),
			),
		},
		r: mkresults(),
	},
}

type tpkg struct {
	// Full import path of this package
	path string
	// Slice of full paths to its virtual imports
	imports []string
}

type bmelem interface {
	_bmelem()
}

func (p tpkg) _bmelem() {}

type bimodalFixture struct {
{'fraction_non_alphanumeric': 0.16520700636942676, 'fraction_numerical': 0.018511146496815286, 'mean_word_length': 2.7556053811659194, 'pattern_counts': {'":': 9, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1596091', 'n_tokens_mistral': 2231, 'n_tokens_neox': 1955, 'n_words': 617}