示例#1
0
func TestFontURLFail(t *testing.T) {
	r, w, _ := os.Pipe()
	old := os.Stdout
	defer func() { os.Stdout = old }()
	os.Stdout = w
	in := bytes.NewBufferString(`@font-face {
  src: font-url("arial.eot");
}`)
	var out bytes.Buffer
	ctx := libsass.Context{}
	err := ctx.Compile(in, &out)

	if err != nil {
		t.Error(err)
	}

	outC := make(chan string)
	go func(r *os.File) {
		var buf bytes.Buffer
		io.Copy(&buf, r)
		outC <- buf.String()
	}(r)

	w.Close()
	stdout := <-outC

	if e := "font-url: font path not set\n"; e != stdout {
		t.Errorf("got:\n%s\nwanted:\n%s\n", stdout, e)
	}

}
示例#2
0
文件: http.go 项目: godeep/wellington
// HTTPHandler starts a CORS enabled web server that takes as input
// Sass and outputs CSS.
func HTTPHandler(ctx *libsass.Context) func(w http.ResponseWriter, r *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		var (
			pout bytes.Buffer
			buf  bytes.Buffer
		)
		start := time.Now()
		// Set headers
		if origin := r.Header.Get("Origin"); origin != "" {
			w.Header().Set("Access-Control-Allow-Origin", origin)
		}
		w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
		w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token")
		w.Header().Set("Access-Control-Allow-Credentials", "true")
		_, err := StartParser(ctx, r.Body, &pout, NewPartialMap())
		if err != nil {
			enc := json.NewEncoder(w)
			enc.Encode(Response{
				Start: start,
				Elapsed: strconv.FormatFloat(float64(
					time.Since(start).Nanoseconds())/float64(time.Millisecond),
					'f', 3, 32) + "ms",
				Contents: "",
				Error:    fmt.Sprintf("%s", err),
			})
			return
		}
		err = ctx.Compile(&pout, &buf)
		defer func() {
			enc := json.NewEncoder(w)
			errString := ""
			if err != nil {
				errString = err.Error()
			}
			enc.Encode(Response{
				Start: start,
				Elapsed: strconv.FormatFloat(float64(
					time.Since(start).Nanoseconds())/(1000*1000),
					'f', 3, 32) + "ms",
				Contents: buf.String(),
				Error:    errString,
			})
		}()
	}
}