File: mosaic_test.go

package info (click to toggle)
golang-github-charmbracelet-x 0.0~git20251028.0cf22f8%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,940 kB
  • sloc: sh: 124; makefile: 5
file content (63 lines) | stat: -rw-r--r-- 27,547 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package mosaic

import (
	"image"
	"image/png"
	"os"
	"reflect"
	"testing"
)

func TestRender(t *testing.T) {
	t.Skip("Skip failing test for now, the provided image seems to be corrupt.")
	raw, err := loadImage("./fixtures/charm-wish.png")
	if err != nil {
		t.Errorf("unexpected error: %v", err)
		os.Exit(1)
	}

	// Create options
	mosaic := New().Width(80).Height(40)

	result := mosaic.Render(raw)

	// TODO: Use a smaller image, it is almost impossible seeing the diff by now
	expected := `              ▄███▄                     
              █████▀             ▄▄▄    
              ▀████▀           ▄████▀   
            ▄▄▄▄     ▄▄▄▄      ▀████▀   
           ▄████▄  ▄███████▄▄   ▀▀▀▀▄▄▄▄
        ▄▄▄██████▄███████████▄      ▀██▀
      ▄███████████████████████▄         
     ▄███████████████████████████████▄  
    ▄██████████████████████████████████▄
▄██████████████████████████████████████▄
▀█████▀███████ ████████████████████████▀
 ▀███▀▄███████ ███████████████████████▀ 
  ▀███▄████████████████████████████▀▀   
   ▀██████████████████████████████▀     
    █████████████████████████████▀      
    ████████████████████████████▀ ▄███▄ 
    ████████████████████▀▀▀█▀▀▀   ▀███▀ 
    ████████████████████           ▀▀▀  
    █████▀▀    ▀▀███████                
    ▀▀▀            ▀▀██▀                
`

	if !reflect.DeepEqual(result, expected) {
		a := os.WriteFile("/tmp/dat1", []byte(result), 0o644)
		t.Log(a)
		t.Errorf("Result and expected does not match = %v, want %v", result, expected)
	}

	// used for quick testing
	// t.Log(result)
}

func loadImage(path string) (image.Image, error) {
	f, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	return png.Decode(f)
}