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") } }
// Get reads instances from the clipboard, decoding them to a rbxfile.Root. A // nil value is returned if the clipboard contains no instances, or is unable // to read them. func Get() *rbxfile.Root { b, err := get() if err != nil { return nil } buf := bytes.NewBuffer(b) root, err := bin.DeserializeModel(buf, nil) if err != nil { return nil } return root }