Exemplo n.º 1
0
func TestSV_equal(t *testing.T) {
	b := libs.MakeBool(true)
	bb := libs.MakeBool(true)

	if libs.Interface(b) != libs.Interface(bb) {
		t.Fatal("equal failed")
	}

	c := libs.MakeColor(color.RGBA{})
	cc := libs.MakeColor(color.RGBA{})

	if libs.Interface(c) != libs.Interface(cc) {
		t.Fatal("equal failed")
	}

	s := libs.MakeString("hi")
	ss := libs.MakeString("hi")
	if libs.Interface(s) != libs.Interface(ss) {
		t.Fatal("equal failed")
	}
}
Exemplo n.º 2
0
// make is needed to create types for use by test
func makevalue(v interface{}) (SassValue, error) {
	f := reflect.ValueOf(v)
	var err error
	switch f.Kind() {
	default:
		return SassValue{value: libs.MakeNil()}, nil
	case reflect.Bool:
		b := v.(bool)
		return SassValue{value: libs.MakeBool(b)}, nil
	case reflect.String:
		s := v.(string)
		return SassValue{value: libs.MakeString(s)}, nil
	case reflect.Struct: //only SassNumber and color.RGBA are supported
		if sn, ok := v.(libs.SassNumber); ok {
			return SassValue{
				value: libs.MakeNumber(sn.Float(), sn.UnitOf()),
			}, err
		} else if sc, ok := v.(color.RGBA); ok {
			return SassValue{value: libs.MakeColor(sc)}, nil
		} else {
			err = errors.New(fmt.Sprintf("The struct type %s is unsupported for marshalling", reflect.TypeOf(v).String()))
			return SassValue{value: libs.MakeNil()}, err
		}
	case reflect.Slice:
		// Initialize the list
		lst := libs.MakeList(f.Len())
		for i := 0; i < f.Len(); i++ {
			t, er := makevalue(f.Index(i).Interface())
			if err == nil && er != nil {
				err = er
			}
			libs.SetIndex(lst, i, t.Val())
		}
		return SassValue{value: lst}, err
	}
}