Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/winter. a thoughtful static website generator for long-lasting content twos.dev/winter
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164package document
import ( "bytes" "errors" "io" "os" "path/filepath" "testing"
"github.com/rwcarlsen/goexif/exif" "gotest.tools/v3/assert")
const sampleJPGPath = "testdata/IMG_0385.JPG"const sampleWebpPath = "testdata/IMG_0385.webp"const sampleWinterYML = `production: url: twos.devgear: - make: Canon model: EOS Rebel T7 link: https://twos.dev exif: make: Canon model: Canon EOS Rebel T7`
func TestNewIMG(t *testing.T) { c, err := newConfigFromBytes([]byte(sampleWinterYML)) assert.NilError(t, err) c.Dist = filepath.Join(t.TempDir(), "dist")
im, err := NewIMG(sampleJPGPath, c) assert.NilError(t, err)
srcf, err := os.Open(im.SourcePath) assert.NilError(t, err) defer srcf.Close()
// Loading needs only the JPEG headers. The complete source is handed to // cwebp by path during Render instead of being retained as decoded pixels. assert.NilError(t, im.Load(io.LimitReader(srcf, 4096)))
var b bytes.Buffer assert.NilError(t, im.Render(&b))}
func TestNewIMGPurchaseURL(t *testing.T) { const purchaseURL = "https://example.com/prints/photo" c, err := newConfigFromBytes([]byte(`production: url: twos.devpurchase_urls: img/gallery/photo.JPG: ` + purchaseURL)) assert.NilError(t, err)
im, err := NewIMG("src/img/gallery/photo.JPG", c) assert.NilError(t, err) assert.Equal(t, purchaseURL, im.PurchaseURL)
unlisted, err := NewIMG("src/img/gallery/unlisted.JPG", c) assert.NilError(t, err) assert.Equal(t, "", unlisted.PurchaseURL)}
func TestFormatMissingGearError(t *testing.T) { configuredGear := []Gear{ { Make: "Fujifilm", Model: "X-T5", Link: "https://twos.dev/x-t5", EXIF: struct { Make string "yaml:\"make,omitempty\"" Model string "yaml:\"model,omitempty\"" }{ Make: "FUJIFILM", Model: "X-T5", }, }, { Make: "Fujifilm", Model: "16-50mm F2.8", Link: "https://twos.dev/16-50", EXIF: struct { Make string "yaml:\"make,omitempty\"" Model string "yaml:\"model,omitempty\"" }{ Make: "FUJIFILM", Model: "XF16-50mmF2.8-4.8 R LM WR", }, }, { Make: "Olympus", Model: "M.Zuiko 17mm F1.8", Link: "https://twos.dev/17mm", }, }
assert.Equal( t, formatMissingGearError( "src/img/photography/2026-japan/Japan 2026 - 9 of 54.jpeg", "FUJIFILM", "XF35mmF2 R WR", configuredGear, ), `no matching gear entry in winter.yml for photo "src/img/photography/2026-japan/Japan 2026 - 9 of 54.jpeg"wanted EXIF match: make: FUJIFILM model: XF35mmF2 R WRconfigured gear: - Fujifilm X-T5 (exif.make="FUJIFILM", exif.model="X-T5") - Fujifilm 16-50mm F2.8 (exif.make="FUJIFILM", exif.model="XF16-50mmF2.8-4.8 R LM WR") - Olympus M.Zuiko 17mm F1.8 (exif.make=<unset>, exif.model=<unset>)add a matching item under gear: in winter.yml`, )}
func TestWrapErrorfMultiline(t *testing.T) { root := errors.New("line one\nline two") err := wrapErrorf(wrapErrorf(root, "inner"), "outer")
assert.Equal(t, err.Error(), "outer:\n inner:\n line one\n line two") assert.Assert(t, errors.Is(err, root))}
func TestExifFractionStringToDecimal(t *testing.T) { tests := []struct { name string fraction string want float64 }{ { name: "rounds thirds to one decimal place", fraction: "1/3", want: 0.3, }, { name: "preserves one decimal place", fraction: "355/10", want: 35.5, }, { name: "rounds to nearest tenth", fraction: "11/8", want: 1.4, }, { name: "handles quoted fractions from exif tags", fraction: "\"40/10\"", want: 4, }, }
for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := exifFractionStringToDecimal(exif.FNumber, tt.fraction) assert.NilError(t, err) assert.Equal(t, tt.want, got) }) }}