1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 19:56:16 +00:00
mycorrhiza/markup/img_test.go

48 lines
1.6 KiB
Go
Raw Normal View History

2020-11-03 15:41:50 +00:00
package markup
import (
"fmt"
"testing"
)
func TestParseStartOfEntry(t *testing.T) {
img := ImgFromFirstLine("img {", "h")
tests := []struct {
line string
entry imgEntry
followedByDesc bool
}{
{"apple", imgEntry{"apple", "", "", ""}, false},
{"pear:", imgEntry{"pear", "", "", ""}, false},
{"яблоко: 30*60", imgEntry{"яблоко", "30", "60", ""}, false},
{"груша : 65 ", imgEntry{"груша", "65", "", ""}, false},
{"жеронимо : 30 { full desc }", imgEntry{"жеронимо", "30", "", " full desc "}, false},
{"жорно жованна : *5555 {partial description", imgEntry{орноованна", "", "5555", "partial description"}, true},
{"иноске : {full}", imgEntry{"иноске", "", "", "full"}, false},
{"j:{partial", imgEntry{"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])
}
}
}