summaryrefslogtreecommitdiffstats
path: root/marshall_test.go
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2016-11-24 21:46:30 -0500
committerGuillaume Horel <guillaume.horel@gmail.com>2016-11-24 21:46:30 -0500
commitfc0f5810f93b6406aa23780bd9357c8169070cb2 (patch)
tree7a8c933cfb2cfe404129ea5df090a90434d05896 /marshall_test.go
parentf7a85af3fc9065d15ec9fd3084252351ff598035 (diff)
downloadlastfm-api-fc0f5810f93b6406aa23780bd9357c8169070cb2.tar.gz
json and xml marshalling almost working
Diffstat (limited to 'marshall_test.go')
-rw-r--r--marshall_test.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/marshall_test.go b/marshall_test.go
new file mode 100644
index 0000000..b5e9fae
--- /dev/null
+++ b/marshall_test.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+ "encoding/json"
+ "encoding/xml"
+ "fmt"
+ "os"
+ "testing"
+)
+
+func TestMarshallXML(t *testing.T) {
+ s := []Scrobble{
+ Scrobble{Artist: Correctable{Name: "Led Zeppelin"},
+ TrackName: Correctable{Name: "Loser"},
+ Time: 1479682785,
+ Album: Correctable{Name: "Mellow Gold"}},
+ }
+ fmt.Printf("%v\n", s)
+ scrobbles := Scrobbles{Scrobbles: s,
+ Attrs: Attrs{1, 0}}
+ output, err := xml.MarshalIndent(scrobbles, " ", " ")
+ if err != nil {
+ fmt.Printf("error: %v\n", err)
+ }
+ os.Stdout.Write(output)
+}
+
+func TestMarshallJSON(t *testing.T) {
+ s := []Scrobble{
+ Scrobble{Artist: Correctable{Name: "Mumford & Sons"},
+ Time: 1479682537,
+ Album: Correctable{Name: "Sign No More"},
+ TrackName: Correctable{Name: "Little Lion Man"}},
+ }
+ scrobbles := Scrobbles{Scrobbles: s,
+ Attrs: Attrs{1, 0}}
+ jsonscrobble := map[string]Scrobbles{"scrobbles": scrobbles}
+ output, err := json.MarshalIndent(jsonscrobble, " ", " ")
+ if err != nil {
+ fmt.Printf("error: %v\n", err)
+ }
+ os.Stdout.Write(output)
+}