Skip to content

Commit

Permalink
refactor: #904 rectify drafty test file
Browse files Browse the repository at this point in the history
  • Loading branch information
dilshans2k committed Apr 4, 2024
1 parent b776e3c commit 5181939
Showing 1 changed file with 68 additions and 73 deletions.
141 changes: 68 additions & 73 deletions server/drafty/drafty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,60 @@ import (
)

var validInputs = []string{
// `"This is a plain text string."`,
// `{
// "txt":"This is a string with a line break.",
// "fmt":[{"at":9,"tp":"BR"}]
// }`,
// `{
// "ent":[{"data":{"mime":"image/jpeg","name":"hello.jpg","val":"<38992, bytes: ...>","width":100, "height":80},"tp":"EX"}],
// "fmt":[{"at":-1, "key":0}]
// }`,
// `{
// "ent":[{"data":{"url":"https://www.youtube.com/watch?v=dQw4w9WgXcQ"},"tp":"LN"}],
// "fmt":[{"len":22}],
// "txt":"https://api.tinode.co/"
// }`,
// `{
// "ent":[{"data":{"url":"https://api.tinode.co/"},"tp":"LN"}],
// "fmt":[{"len":22}],
// "txt":"https://api.tinode.co/"
// }`,
// `{
// "ent":[{"data":{"url":"http://tinode.co"},"tp":"LN"}],
// "fmt":[{"at":9,"len":3}, {"at":4,"len":3}],
// "txt":"Url one, two"
// }`,
// `{
// "ent":[{"data":{"height":213,"mime":"image/jpeg","name":"roses.jpg","val":"<38992, bytes: ...>","width":638},"tp":"IM"}],
// "fmt":[{"len":1}],
// "txt":" "
// }`,
// `{
// "txt":"This text has staggered formats",
// "fmt":[{"at":5,"len":8,"tp":"EM"},{"at":10,"len":13,"tp":"ST"}]
// }`,
// `{
// "txt":"This text is formatted and deleted too",
// "fmt":[{"at":5,"len":4,"tp":"ST"},{"at":13,"len":9,"tp":"EM"},{"at":35,"len":3,"tp":"ST"},{"at":27,"len":11,"tp":"DL"}]
// }`,
// `{
// "txt":"мультибайтовый юникод",
// "fmt":[{"len":14,"tp":"ST"},{"at":15,"len":6,"tp":"EM"}]
// }`,
// `{
// "txt":"Alice Johnson This is a test",
// "fmt":[{"at":13,"len":1,"tp":"BR"},{"at":15,"len":1},{"len":13,"key":1},{"len":16,"tp":"QQ"},{"at":16,"len":1,"tp":"BR"}],
// "ent":[{"tp":"IM","data":{"mime":"image/jpeg","val":"<1292, bytes: /9j/4AAQSkZJ...rehH5o6D/9k=>","width":25,"height":14,"size":968}},{"tp":"MN","data":{"color":2}}]
// }`,
// `{
// "txt": "Hello 😀, o😀k https://google.com",
// "fmt":[{"at":9,"len":3,"tp":"ST"},{"at":13,"len":18}],
// "ent":[{"tp":"LN","data":{"url":"https://google.com"}}]
// }`,
// `{
// "txt": "Hi 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿",
// "fmt":[{"at":3,"len":4,"tp":"ST"},{"at":8,"len":4,"tp":"ST"}]
// }`,
`{
"txt": "Hi 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿"
`"This is a plain text string."`,
`{
"txt":"This is a string with a line break.",
"fmt":[{"at":9,"tp":"BR"}]
}`,
`{
"ent":[{"data":{"mime":"image/jpeg","name":"hello.jpg","val":"<38992, bytes: ...>","width":100, "height":80},"tp":"EX"}],
"fmt":[{"at":-1, "key":0}]
}`,
`{
"ent":[{"data":{"url":"https://www.youtube.com/watch?v=dQw4w9WgXcQ"},"tp":"LN"}],
"fmt":[{"len":22}],
"txt":"https://api.tinode.co/"
}`,
`{
"ent":[{"data":{"url":"https://api.tinode.co/"},"tp":"LN"}],
"fmt":[{"len":22}],
"txt":"https://api.tinode.co/"
}`,
`{
"ent":[{"data":{"url":"http://tinode.co"},"tp":"LN"}],
"fmt":[{"at":9,"len":3}, {"at":4,"len":3}],
"txt":"Url one, two"
}`,
`{
"ent":[{"data":{"height":213,"mime":"image/jpeg","name":"roses.jpg","val":"<38992, bytes: ...>","width":638},"tp":"IM"}],
"fmt":[{"len":1}],
"txt":" "
}`,
`{
"txt":"This text has staggered formats",
"fmt":[{"at":5,"len":8,"tp":"EM"},{"at":10,"len":13,"tp":"ST"}]
}`,
`{
"txt":"This text is formatted and deleted too",
"fmt":[{"at":5,"len":4,"tp":"ST"},{"at":13,"len":9,"tp":"EM"},{"at":35,"len":3,"tp":"ST"},{"at":27,"len":11,"tp":"DL"}]
}`,
`{
"txt":"мультибайтовый юникод",
"fmt":[{"len":14,"tp":"ST"},{"at":15,"len":6,"tp":"EM"}]
}`,
`{
"txt":"Alice Johnson This is a test",
"fmt":[{"at":13,"len":1,"tp":"BR"},{"at":15,"len":1},{"len":13,"key":1},{"len":16,"tp":"QQ"},{"at":16,"len":1,"tp":"BR"}],
"ent":[{"tp":"IM","data":{"mime":"image/jpeg","val":"<1292, bytes: /9j/4AAQSkZJ...rehH5o6D/9k=>","width":25,"height":14,"size":968}},{"tp":"MN","data":{"color":2}}]
}`,
`{
"txt": "Hello 😀, o😀k https://google.com",
"fmt":[{"at":9,"len":3,"tp":"ST"},{"at":13,"len":18}],
"ent":[{"tp":"LN","data":{"url":"https://google.com"}}]
}`,
`{
"txt": "Hi 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿",
"fmt":[{"at":3,"len":4,"tp":"ST"},{"at":8,"len":4,"tp":"ST"}]
}`,
}

Expand Down Expand Up @@ -113,7 +110,6 @@ func TestPlainText(t *testing.T) {
"This is a test",
"Hello 😀, *o😀k* https://google.com",
"Hi *🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿* *🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿* 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿",
"Hi 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿",
}

for i := range validInputs {
Expand Down Expand Up @@ -144,27 +140,26 @@ func TestPlainText(t *testing.T) {

func TestPreview(t *testing.T) {
expect := []string{
// `{"txt":"This is a plain"}`,
// `{"txt":"This is a strin","fmt":[{"tp":"BR","at":9}]}`,
// `{"fmt":[{"at":-1}],"ent":[{"tp":"EX","data":{"height":80,"mime":"image/jpeg","name":"hello.jpg","width":100}}]}`,
// `{"txt":"https://api.tin","fmt":[{"len":15}],"ent":[{"tp":"LN","data":{"url":"https://www.youtube.com/watch?v=dQw4w9WgXcQ"}}]}`,
// `{"txt":"https://api.tin","fmt":[{"len":15}],"ent":[{"tp":"LN","data":{"url":"https://api.tinode.co/"}}]}`,
// `{"txt":"Url one, two","fmt":[{"at":4,"len":3},{"at":9,"len":3}],"ent":[{"tp":"LN","data":{"url":"http://tinode.co"}}]}`,
// `{"txt":" ","fmt":[{"len":1}],"ent":[{"tp":"IM","data":{"height":213,"mime":"image/jpeg","name":"roses.jpg","width":638}}]}`,
// `{"txt":"This text has s","fmt":[{"tp":"EM","at":5,"len":8}]}`,
// `{"txt":"This text is fo","fmt":[{"tp":"ST","at":5,"len":4},{"tp":"EM","at":13,"len":2}]}`,
// `{"txt":"мультибайтовый ","fmt":[{"tp":"ST","len":14}]}`,
// `{"txt":"This is a test"}`,
// `{"txt":"Hello 😀, o😀k ht","fmt":[{"tp":"ST","at":9,"len":3},{"at":13,"len":2}],"ent":[{"tp":"LN","data":{"url":"https://google.com"}}]}`,
// `{"txt": "Hi 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿","fmt":[{"tp":"ST","at":3,"len":4},{"tp":"ST","at":8,"len":4}]}`,
`{"txt": "Hi 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿"}`,
`{"txt":"This is a plain"}`,
`{"txt":"This is a strin","fmt":[{"tp":"BR","at":9}]}`,
`{"fmt":[{"at":-1}],"ent":[{"tp":"EX","data":{"height":80,"mime":"image/jpeg","name":"hello.jpg","width":100}}]}`,
`{"txt":"https://api.tin","fmt":[{"len":15}],"ent":[{"tp":"LN","data":{"url":"https://www.youtube.com/watch?v=dQw4w9WgXcQ"}}]}`,
`{"txt":"https://api.tin","fmt":[{"len":15}],"ent":[{"tp":"LN","data":{"url":"https://api.tinode.co/"}}]}`,
`{"txt":"Url one, two","fmt":[{"at":4,"len":3},{"at":9,"len":3}],"ent":[{"tp":"LN","data":{"url":"http://tinode.co"}}]}`,
`{"txt":" ","fmt":[{"len":1}],"ent":[{"tp":"IM","data":{"height":213,"mime":"image/jpeg","name":"roses.jpg","width":638}}]}`,
`{"txt":"This text has s","fmt":[{"tp":"EM","at":5,"len":8}]}`,
`{"txt":"This text is fo","fmt":[{"tp":"ST","at":5,"len":4},{"tp":"EM","at":13,"len":2}]}`,
`{"txt":"мультибайтовый ","fmt":[{"tp":"ST","len":14}]}`,
`{"txt":"This is a test"}`,
`{"txt":"Hello 😀, o😀k ht","fmt":[{"tp":"ST","at":9,"len":3},{"at":13,"len":2}],"ent":[{"tp":"LN","data":{"url":"https://google.com"}}]}`,
`{"txt":"Hi 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿 🏴󠁧󠁢󠁳󠁣󠁴󠁿🏴󠁧󠁢󠁳󠁣󠁴󠁿","fmt":[{"tp":"ST","at":3,"len":4},{"tp":"ST","at":8,"len":4}]}`,
}
for i := range validInputs {
var val interface{}
if err := json.Unmarshal([]byte(validInputs[i]), &val); err != nil {
t.Errorf("Failed to parse input %d '%s': %s", i, validInputs[i], err)
}
res, err := Preview(val, 5)
res, err := Preview(val, 15)
if err != nil {
t.Errorf("%d failed with error: %s", i, err)
} else if res != expect[i] {
Expand Down

0 comments on commit 5181939

Please sign in to comment.