1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-15 14:30:26 +00:00
mycorrhiza/markup/img_test.go
2020-11-04 22:42:02 +05:00

48 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package markup
import (
"fmt"
"testing"
)
func TestParseStartOfEntry(t *testing.T) {
img := ImgFromFirstLine("img {", "h")
tests := []struct {
line string
entry imgEntry
followedByDesc bool
}{
{"apple", imgEntry{"/binary/apple", "", "", ""}, false},
{"pear|", imgEntry{"/binary/pear", "", "", ""}, false},
{"яблоко| 30*60", imgEntry{"/binary/яблоко", "30", "60", ""}, false},
{"груша | 65 ", imgEntry{"/binary/груша", "65", "", ""}, false},
{"жеронимо | 30 { full desc }", imgEntry{"/binary/жеронимо", "30", "", " full desc "}, false},
{"жорно жованна | *5555 {partial description", imgEntry{"/binary/жорноованна", "", "5555", "partial description"}, true},
{"иноске | {full}", imgEntry{"/binary/иноске", "", "", "full"}, false},
{"j|{partial", imgEntry{"/binary/j", "", "", "partial"}, true},
}
for _, triplet := range tests {
entry, followedByDesc := img.parseStartOfEntry(triplet.line)
if entry != triplet.entry || followedByDesc != triplet.followedByDesc {
t.Error(fmt.Sprintf("%q:%q != %q; %v != %v", triplet.line, entry, triplet.entry, followedByDesc, triplet.followedByDesc))
}
}
}
func TestParseDimensions(t *testing.T) {
tests := [][]string{
{"500", "500", ""},
{"3em", "3em", ""},
{"500*", "500", ""},
{"*500", "", "500"},
{"800*520", "800", "520"},
{"17%*5rem", "17%", "5rem"},
}
for _, triplet := range tests {
sizeH, sizeV := parseDimensions(triplet[0])
if sizeH != triplet[1] || sizeV != triplet[2] {
t.Error(sizeH, "*", sizeV, " != ", triplet[1], "*", triplet[2])
}
}
}