예제 #1
0
func TestFuncSpriteFile(t *testing.T) {

	comp, err := libsass.New(nil, nil,
		libsass.Payload(payload.New()),
		libsass.ImgDir("../test/img"),
		libsass.BuildDir("../test/build"),
		libsass.ImgBuildDir("../test/build/img"),
	)
	if err != nil {
		t.Fatal(err)
	}

	// Add real arguments when sass lists can be [un]marshalled
	lst := []interface{}{"*.png", "139"}
	usv, err := libsass.Marshal(lst)
	if err != nil {
		t.Fatal(err)
	}

	rsv, err := SpriteFile(libsass.NewCompilerContext(comp), usv)
	if err != nil {
		t.Fatal(err)
	}
	var glob, path string
	err = libsass.Unmarshal(*rsv, &glob, &path)
	if err != nil {
		t.Error(err)
	}

	if e := "*.png"; e != glob {
		t.Errorf("got: %s wanted: %s", e, glob)
	}

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

}
예제 #2
0
func TestFuncImageURL(t *testing.T) {
	comp, err := libsass.New(nil, nil,
		libsass.BuildDir("../test/build"),
		libsass.ImgDir("../test/img"),
	)
	if err != nil {
		t.Fatal(err)
	}
	ctx := libsass.NewCompilerContext(comp)

	usv, _ := libsass.Marshal([]string{"139.png"})
	rsv, err := ImageURL(ctx, usv)
	if err != nil {
		t.Fatal(err)
	}
	var path string
	err = libsass.Unmarshal(*rsv, &path)
	if err != nil {
		t.Fatal(err)
	}
	if e := "url('../img/139.png')"; e != path {
		t.Errorf("got: %s wanted: %s", path, e)
	}

	// Test sending invalid date to imageURL
	usv, _ = libsass.Marshal(libs.SassNumber{Value: 1, Unit: "px"})
	_, err = ImageURL(ctx, usv)
	if err == nil {
		t.Fatal("error is nil")
	}

	e := "Invalid Sass type expected: slice got: libs.SassNumber value: 1px"

	if e != err.Error() {
		t.Errorf("got: %s wanted: %s", err, e)
	}

}