Skip to content

Commit

Permalink
remove setupCtx from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drewwells committed Jan 18, 2016
1 parent 3bcc5bb commit 2f222c7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 61 deletions.
65 changes: 29 additions & 36 deletions handlers/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -403,18 +404,18 @@ div {
background: sprite($map, "140");
}`)

ctx := oldContext()

ctx.BuildDir = "../test/build"
ctx.GenImgDir = "../test/build/img"
ctx.ImageDir = "../test/img"
var out bytes.Buffer
err := ctx.Compile(in, &out)
comp, err := libsass.New(os.Stdout, in,
libsass.Payload(payload.New()),
libsass.ImgDir("../test/img"),
libsass.BuildDir("../test/build"),
libsass.ImgBuildDir("../test/build/img"),
)
if err != nil {
fmt.Println(err)
log.Fatal(err)
}
if err := comp.Run(); err != nil {
log.Fatal(err)
}

io.Copy(os.Stdout, &out)

// Output:
// div {
Expand All @@ -428,12 +429,8 @@ div {
background: sprite($map, "140", 10px, 10px);
}`)

ctx := oldContext()
ctx.BuildDir = "../test/build"
ctx.GenImgDir = "../test/build/img"
ctx.ImageDir = "../test/img"
var out bytes.Buffer
err := ctx.Compile(in, &out)
_, err := setupComp(t, in, &out)

if err != nil {
t.Fatal("expected error")
Expand All @@ -454,12 +451,8 @@ div {
background: sprite($map, "140", 0, 0);
}`)

ctx := oldContext()
ctx.BuildDir = "../test/build"
ctx.GenImgDir = "../test/build/img"
ctx.ImageDir = "../test/img"
var out bytes.Buffer
err := ctx.Compile(in, &out)
_, err := setupComp(t, in, &out)

e := `Error > stdin:4
error in C function sprite: Please specify unit for offset ie. (2px)
Expand Down Expand Up @@ -490,18 +483,24 @@ div {
background: sprite($map, "140");
}`)

ctx := oldContext()
ctx.IncludePaths = []string{"../test"}
ctx.HTTPPath = "http://foo.com"
ctx.BuildDir = "../test/build"
ctx.GenImgDir = "../test/build/img"
ctx.ImageDir = "../test/img"
var out bytes.Buffer
err := ctx.Compile(in, &out)

comp, err := libsass.New(&out, in,
libsass.OutputStyle(libsass.NESTED_STYLE),
libsass.BuildDir("../test/build"),
libsass.ImgDir("../test/img"),
libsass.FontDir("../test/font"),
libsass.Payload(payload.New()),
libsass.ImgBuildDir("../test/build/img"),
libsass.HTTPPath("http://foo.com"),
)
if err != nil {
t.Error(err)
t.Fatal(err)
}

if err := comp.Run(); err != nil {
t.Fatal(err)
}

e := `div {
background: url("http://foo.com/build/4f0c6e.png") 0px -149px; }
`
Expand All @@ -523,14 +522,8 @@ div {
background: sprite($map, "twitt");
}`)

ctx := oldContext()

ctx.BuildDir = "../test/build"
ctx.GenImgDir = "../test/build/img"
ctx.ImageDir = "../test/img"
var out bytes.Buffer
err := ctx.Compile(in, &out)

_, err := setupComp(t, in, &out)
if err != nil {
t.Error(err)
}
Expand Down
44 changes: 19 additions & 25 deletions handlers/spriting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package handlers

import (
"bytes"
"fmt"
"io"
"log"
"os"
"testing"

libsass "github.com/wellington/go-libsass"
"github.com/wellington/wellington/payload"
)

func ExampleSprite_position() {
Expand All @@ -21,17 +21,20 @@ div.retina {
background-position: 10px ceil(nth(sprite-position($map, "140"), 2) /2 );
}`)

ctx := oldContext()
ctx.BuildDir = "../test/build"
ctx.GenImgDir = "../test/build/img"
ctx.ImageDir = "../test/img"
var out bytes.Buffer
err := ctx.Compile(in, &out)
comp, err := libsass.New(os.Stdout, in,
libsass.Payload(payload.New()),
libsass.ImgDir("../test/img"),
libsass.BuildDir("../test/build"),
libsass.ImgBuildDir("../test/build/img"),
)
if err != nil {
fmt.Println(err)
log.Fatal(err)
}

io.Copy(os.Stdout, &out)
err = comp.Run()
if err != nil {
log.Fatal(err)
}

// Output:
// div {
Expand All @@ -42,6 +45,7 @@ div.retina {
}

func TestFuncSpriteFile(t *testing.T) {

ctx := oldContext()
ctx.BuildDir = "../test/build"
ctx.GenImgDir = "../test/build/img"
Expand Down Expand Up @@ -104,22 +108,17 @@ height: $aritymap;
line-height: $paddedmap;
}`)

ctx := oldContext()

ctx.BuildDir = "../test/build"
ctx.GenImgDir = "../test/build/img"
ctx.ImageDir = "../test/img"
var out bytes.Buffer
err := ctx.Compile(in, &out)
_, err := setupComp(t, in, &out)
if err != nil {
t.Error(err)
t.Fatal(err)
}

exp := `div {
width: *.png0;
height: *.png0;
line-height: *.png1; }
`

if exp != out.String() {
t.Errorf("got:\n%s\nwanted:\n%s", out.String(), exp)
}
Expand All @@ -131,17 +130,12 @@ div {
content: $map;
}`)

ctx := oldContext()

ctx.ImageDir = "../test/img"
ctx.BuildDir = "../test/build"
ctx.GenImgDir = "../test/build/img"

var out bytes.Buffer
err := ctx.Compile(in, &out)
_, err := setupComp(t, in, &out)
if err != nil {
t.Error(err)
}

exp := `div {
content: *.png10; }
`
Expand Down

0 comments on commit 2f222c7

Please sign in to comment.