<commit_before>package context

import (
	"bytes"
	"io"
	"testing"
)

func wrapCallback(sc SassCallback, ch chan UnionSassValue) SassCallback {
	return func(c *Context, usv UnionSassValue) UnionSassValue {
		usv = sc(c, usv)
		ch <- usv
		return usv
	}
}

func setupCtx(r io.Reader, out io.Writer, cookies ...Cookie) (Context, chan UnionSassValue, chan error) {
	ctx := Context{
		OutputStyle:  NESTED_STYLE,
		IncludePaths: make([]string, 0),
		BuildDir:     "test/build",
		ImageDir:     "test/img",
		GenImgDir:    "test/build/img",
		Out:          "",
	}
	var cc chan UnionSassValue
	ec := make(chan error, 1)
	_ = ec
	// If callbacks were made, add them to the context
	// and create channels for communicating with them.
	if len(cookies) > 0 {
		cs := make([]Cookie, len(cookies))
		for i, c := range cookies {
			cs[i] = Cookie{
				c.sign,
				wrapCallback(c.fn, cc),
				&ctx,
			}
		}
	}

	ec <- ctx.Compile(r, out)

	return ctx, cc, ec
}

func TestFuncImageURL(t *testing.T) {
	ctx := Context{
		BuildDir: "test/build",
		ImageDir: "test/img",
	}

	usv := testMarshal(t, []string{"image.png"})
	usv = ImageURL(&ctx, usv)
	var path string
	Unmarshal(usv, &path)

	if e := "../img/image.png"; e != path {
		t.Errorf("got: %s wanted: %s", path, e)
	}
}

func TestFuncSpriteMap(t *testing.T) {
	ctx := NewContext()
	ctx.BuildDir = "test/build"
	ctx.GenImgDir = "test/build/img"
	ctx.ImageDir = "test/img"

	// Add real arguments when sass lists can be [un]marshalled
	lst := []interface{}{"*.png", float64(5), float64(0)}
	usv := testMarshal(t, lst)
	usv = SpriteMap(ctx, usv)
	var path string
	err := Unmarshal(usv, &path)
	if err != nil {
		t.Error(err)
	}

	if e := "test/build/img/image-8121ae.png"; e != path {
		t.Errorf("got: %s wanted: %s", path, e)
	}
}

func TestCompileSpriteMap(t *testing.T) {
	in := bytes.NewBufferString(`
$aritymap: sprite-map("*.png",1,2); // Optional arguments
$map: sprite-map("*.png"); // One argument
div {
width: $map;
height: $aritymap;
}`)

	ctx := NewContext()

	ctx.BuildDir = "test/build"
	ctx.GenImgDir = "test/build/img"
	ctx.ImageDir = "test/img"
	var out bytes.Buffer
	err := ctx.Compile(in, &out)
	if err != nil {
		t.Error(err)
	}
	exp := `div {
  width: test/build/img/image-8121ae.png; }
`

	if exp != out.String() {
		t.Errorf("got:\n%s\nwanted:\n%s", out.String(), exp)
	}
}<commit_msg>Fixing sprite test<commit_after>package context

import (
	"bytes"
	"io"
	"testing"
)

func wrapCallback(sc SassCallback, ch chan UnionSassValue) SassCallback {
	return func(c *Context, usv UnionSassValue) UnionSassValue {
		usv = sc(c, usv)
		ch <- usv
		return usv
	}
}

func setupCtx(r io.Reader, out io.Writer, cookies ...Cookie) (Context, chan UnionSassValue, chan error) {
	ctx := Context{
		OutputStyle:  NESTED_STYLE,
		IncludePaths: make([]string, 0),
		BuildDir:     "test/build",
		ImageDir:     "test/img",
		GenImgDir:    "test/build/img",
		Out:          "",
	}
	var cc chan UnionSassValue
	ec := make(chan error, 1)
	_ = ec
	// If callbacks were made, add them to the context
	// and create channels for communicating with them.
	if len(cookies) > 0 {
		cs := make([]Cookie, len(cookies))
		for i, c := range cookies {
			cs[i] = Cookie{
				c.sign,
				wrapCallback(c.fn, cc),
				&ctx,
			}
		}
	}

	ec <- ctx.Compile(r, out)

	return ctx, cc, ec
}

func TestFuncImageURL(t *testing.T) {
	ctx := Context{
		BuildDir: "test/build",
		ImageDir: "test/img",
	}

	usv := testMarshal(t, []string{"image.png"})
	usv = ImageURL(&ctx, usv)
	var path string
	Unmarshal(usv, &path)

	if e := "../img/image.png"; e != path {
		t.Errorf("got: %s wanted: %s", path, e)
	}
}

func TestFuncSpriteMap(t *testing.T) {
	ctx := NewContext()
	ctx.BuildDir = "test/build"
	ctx.GenImgDir = "test/build/img"
	ctx.ImageDir = "test/img"

	// Add real arguments when sass lists can be [un]marshalled
	lst := []interface{}{"*.png", float64(5), float64(0)}
	usv := testMarshal(t, lst)
	usv = SpriteMap(ctx, usv)
	var path string
	err := Unmarshal(usv, &path)
	if err != nil {
		t.Error(err)
	}

	if e := "test/build/img/image-8121ae.png"; e != path {
		t.Errorf("got: %s wanted: %s", path, e)
	}
}

func TestCompileSpriteMap(t *testing.T) {
	in := bytes.NewBufferString(`
$aritymap: sprite-map("*.png",1,2); // Optional arguments
$map: sprite-map("*.png"); // One argument
div {
width: $map;
height: $aritymap;
}`)

	ctx := NewContext()

	ctx.BuildDir = "test/build"
	ctx.GenImgDir = "test/build/img"
	ctx.ImageDir = "test/img"
	var out bytes.Buffer
	err := ctx.Compile(in, &out)
	if err != nil {
		t.Error(err)
	}
	exp := `div {
  width: test/build/img/image-8121ae.png;
  height: test/build/img/image-8121ae.png; }
`

	if exp != out.String() {
		t.Errorf("got:\n%s\nwanted:\n%s", out.String(), exp)
	}
}
{'fraction_non_alphanumeric': 0.17405063291139242, 'fraction_numerical': 0.008860759493670886, 'mean_word_length': 3.439138576779026, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1173534', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1878, 'n_words': 462}