2 // Copyright (C) 2019-2019 Marcus Rohrmoser, https://code.mro.name/mro/pinboard4shaarli
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
26 "github.com/stretchr/testify/assert"
30 // api_token {"result":"692D3D4BD4A2825D5A4A"}
31 // add {"result_code":"item already exists"}
32 // {"result_code":"done"}
34 // get {"date":"2018-04-09T19:26:54Z","user":"mro","posts":[]}
36 func xm(o
interface{}) string {
38 w
:= bufio
.NewWriter(&b
)
39 enc
:= xml
.NewEncoder(w
)
42 return string(b
.Bytes())
45 func js(o
interface{}) string {
47 w
:= bufio
.NewWriter(&b
)
48 enc
:= json
.NewEncoder(w
)
51 return string(b
.Bytes())
54 func TestXmlEncodeResult(t
*testing
.T
) {
56 r
:= Result
{Code
: "done"}
57 assert
.Equal(t
, "<result code=\"done\"></result>", xm(r
), "ach")
58 assert
.Equal(t
, "{\"result_code\":\"done\"}\n", js(r
), "ach")
61 func TestXmlEncodePosts(t
*testing
.T
) {
64 assert
.Equal(t
, "<posts user=\"\" dt=\"\"><post href=\"uhu\" description=\"\" extended=\"\" hash=\"\" others=\"0\" tag=\"\" time=\"\"></post><post href=\"aha\" description=\"\" extended=\"\" hash=\"\" others=\"0\" tag=\"\" time=\"\"></post></posts>",
65 xm(Posts
{Posts
: []Post
{
69 assert
.Equal(t
, "{\"user\":\"\",\"date\":\"\",\"posts\":[{\"href\":\"uhu\",\"description\":\"\",\"extended\":\"\",\"hash\":\"\",\"meta\":\"\",\"others\":0,\"tag\":\"\",\"time\":\"\"},{\"href\":\"aha\",\"description\":\"\",\"extended\":\"\",\"hash\":\"\",\"meta\":\"\",\"others\":0,\"tag\":\"\",\"time\":\"\"}]}\n",
70 js(Posts
{Posts
: []Post
{