Example #1
0
func TestFunctions(t *testing.T) {
	inputBytes, _ := hex.DecodeString(inputModel)
	inputBuf := bytes.NewBuffer(inputBytes)
	inputRoot, err := bin.DeserializeModel(inputBuf, nil)
	if err != nil {
		t.Fatalf("rbxfile/bin failed to decode file: %s", err)
	}
	if !rbxclip.Set(nil) {
		t.Error("clear clipboard failed")
	}
	if rbxclip.Has() {
		t.Error("Has: expected no instances in clipboard")
	}
	if rbxclip.Get() != nil {
		t.Error("Get: expected no root")
	}
	if !rbxclip.Set(inputRoot) {
		t.Error("set clipboard failed")
	}
	if !rbxclip.Has() {
		t.Error("Has: expected instances in clipboard")
	}
	root := rbxclip.Get()
	if root == nil {
		t.Fatal("Get: expected root")
	}
	var buf bytes.Buffer
	if err := bin.SerializeModel(&buf, nil, root); err != nil {
		t.Fatal("failed to serialize output")
	}
	if !bytes.Equal(inputBytes, buf.Bytes()) {
		t.Fatal("output bytes do not equal input bytes")
	}
}
Example #2
0
// Set writes instances to the clipboard, encoding from a rbxfile.Root.
// Passing nil will simply clear the clipboard. Returns whether or not the
// call was successful.
func Set(root *rbxfile.Root) bool {
	if root == nil {
		return clear() == nil
	}
	var buf bytes.Buffer
	if err := bin.SerializeModel(&buf, nil, root); err != nil {
		return false
	}
	clear()
	return set(buf.Bytes()) == nil
}