@@ -2,13 +2,12 @@ package drafty
22
33import (
44 "encoding/json"
5- "reflect"
65 "testing"
76)
87
98var validInputs = []string {
109 `{
11- "ent":[{"data":{"mime":"image/jpeg","name":"hello.jpg","val":"<38992, bytes: ...>"},"tp":"EX"}],
10+ "ent":[{"data":{"mime":"image/jpeg","name":"hello.jpg","val":"<38992, bytes: ...>","width":100, "height":80 },"tp":"EX"}],
1211 "fmt":[{"at":-1, "key":0}]
1312 }` ,
1413 `{
@@ -96,50 +95,14 @@ func TestToPlainText(t *testing.T) {
9695}
9796
9897func TestPreview (t * testing.T ) {
99- expect := []map [string ]interface {}{
100- map [string ]interface {}{
101- "fmt" : []map [string ]interface {}{map [string ]interface {}{"at" : - 1 , "key" : 0 }},
102- "ent" : []map [string ]interface {}{map [string ]interface {}{
103- "tp" : "EX" ,
104- "data" : map [string ]interface {}{"mime" : "image/jpeg" , "name" : "hello.jpg" }},
105- },
106- },
107- map [string ]interface {}{
108- "txt" : "https://api.tin" ,
109- "fmt" : []map [string ]interface {}{map [string ]interface {}{"len" : 22 , "key" : 0 }},
110- "ent" : []map [string ]interface {}{map [string ]interface {}{"tp" : "LN" }},
111- },
112- map [string ]interface {}{
113- "txt" : "https://api.tin" ,
114- "fmt" : []map [string ]interface {}{map [string ]interface {}{"len" : 22 , "key" : 0 }},
115- "ent" : []map [string ]interface {}{map [string ]interface {}{"tp" : "LN" }},
116- },
117- map [string ]interface {}{
118- "txt" : " " ,
119- "fmt" : []map [string ]interface {}{map [string ]interface {}{"len" : 1 , "key" : 0 }},
120- "ent" : []map [string ]interface {}{map [string ]interface {}{
121- "tp" : "IM" ,
122- "data" : map [string ]interface {}{
123- "width" : 638.0 ,
124- "height" : 213.0 ,
125- "mime" : "image/jpeg" ,
126- "name" : "roses.jpg" ,
127- },
128- }},
129- },
130- map [string ]interface {}{
131- "txt" : "This text is fo" ,
132- "fmt" : []map [string ]interface {}{
133- map [string ]interface {}{"at" : 5 , "len" : 4 , "tp" : "ST" },
134- map [string ]interface {}{"at" : 13 , "len" : 9 , "tp" : "EM" },
135- },
136- },
137- map [string ]interface {}{
138- "txt" : "мультибайтовый " ,
139- "fmt" : []map [string ]interface {}{map [string ]interface {}{"tp" : "ST" , "len" : 14 }},
140- },
98+ expect := []string {
99+ `{"ent":[{"data":{"height":80,"mime":"image/jpeg","name":"hello.jpg","width":100},"tp":"EX"}],"fmt":[{"at":-1,"key":0}]}` ,
100+ `{"ent":[{"tp":"LN"}],"fmt":[{"key":0,"len":22}],"txt":"https://api.tin"}` ,
101+ `{"ent":[{"tp":"LN"}],"fmt":[{"key":0,"len":22}],"txt":"https://api.tin"}` ,
102+ `{"ent":[{"data":{"height":213,"mime":"image/jpeg","name":"roses.jpg","width":638},"tp":"IM"}],"fmt":[{"key":0,"len":1}],"txt":" "}` ,
103+ `{"fmt":[{"at":5,"len":4,"tp":"ST"},{"at":13,"len":9,"tp":"EM"}],"txt":"This text is fo"}` ,
104+ `{"fmt":[{"len":14,"tp":"ST"}],"txt":"мультибайтовый "}` ,
141105 }
142-
143106 for i := range validInputs {
144107 var val interface {}
145108 json .Unmarshal ([]byte (validInputs [i ]), & val )
@@ -148,7 +111,7 @@ func TestPreview(t *testing.T) {
148111 t .Error (err )
149112 }
150113
151- if ! reflect . DeepEqual ( res , expect [i ]) {
114+ if res != expect [i ] {
152115 t .Errorf ("%d output '%s' does not match '%s'" , i , res , expect [i ])
153116 }
154117 }
0 commit comments