test(ports): restore Theme wire flag coverage
- commit
- 0b10c36194efe0589e52af7a57c02c83998bd0ae
- author
- brice · · 2026-07-17 08:21 UTC
- parent
- 5c34841
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +65 -29
M internal/ports/wire_test.go +65 -29
| @@ -254,35 +254,71 @@ func TestThemeGoldenAndRoundTrip(t *testing.T) { | |||
| 254 | 254 | {R: 0x34, G: 0x35, B: 0x36}, {R: 0x37, G: 0x38, B: 0x39}, | |
| 255 | 255 | {R: 0x3a, G: 0x3b, B: 0x3c}, {R: 0x3d, G: 0x3e, B: 0x3f}, | |
| 256 | 256 | } | |
| 257 | - | msg := Theme{ | |
| 258 | - | HasForeground: true, | |
| 259 | - | Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 260 | - | HasBackground: true, | |
| 261 | - | Background: renderer.RGB{R: 4, G: 5, B: 6}, | |
| 262 | - | TrueColor: true, | |
| 263 | - | SchemeKnown: true, | |
| 264 | - | PaletteKnown: 0x8001, | |
| 265 | - | Palette: palette, | |
| 266 | - | } | |
| 267 | - | want := []byte{ | |
| 268 | - | 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x80, 0x01, | |
| 269 | - | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, | |
| 270 | - | 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, | |
| 271 | - | 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, | |
| 272 | - | 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, | |
| 273 | - | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, | |
| 274 | - | 0x3d, 0x3e, 0x3f, | |
| 275 | - | } | |
| 276 | - | ||
| 277 | - | got := MarshalTheme(msg) | |
| 278 | - | require.Len(t, got, 57) | |
| 279 | - | require.Equal(t, want, got) | |
| 280 | - | back, err := UnmarshalTheme(got) | |
| 281 | - | require.NoError(t, err) | |
| 282 | - | require.Equal(t, msg, back) | |
| 283 | - | ||
| 284 | - | assertAllPrefixesFail(t, got, UnmarshalTheme) | |
| 285 | - | assertTrailingGarbageFails(t, got, UnmarshalTheme) | |
| 257 | + | zeroes := make([]byte, 57) | |
| 258 | + | tests := []struct { | |
| 259 | + | name string | |
| 260 | + | msg Theme | |
| 261 | + | want []byte | |
| 262 | + | }{ | |
| 263 | + | { | |
| 264 | + | name: "empty", | |
| 265 | + | msg: Theme{}, | |
| 266 | + | want: zeroes, | |
| 267 | + | }, | |
| 268 | + | { | |
| 269 | + | name: "foreground only", | |
| 270 | + | msg: Theme{ | |
| 271 | + | HasForeground: true, | |
| 272 | + | Foreground: renderer.RGB{R: 10, G: 20, B: 30}, | |
| 273 | + | Background: renderer.RGB{R: 40, G: 50, B: 60}, | |
| 274 | + | }, | |
| 275 | + | want: append([]byte{0x01, 0x0a, 0x14, 0x1e, 0x28, 0x32, 0x3c}, zeroes[7:]...), | |
| 276 | + | }, | |
| 277 | + | { | |
| 278 | + | name: "light flag without known scheme", | |
| 279 | + | msg: Theme{ | |
| 280 | + | Light: true, | |
| 281 | + | }, | |
| 282 | + | want: append([]byte{0x10}, zeroes[1:]...), | |
| 283 | + | }, | |
| 284 | + | { | |
| 285 | + | name: "full palette", | |
| 286 | + | msg: Theme{ | |
| 287 | + | HasForeground: true, | |
| 288 | + | Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |
| 289 | + | HasBackground: true, | |
| 290 | + | Background: renderer.RGB{R: 4, G: 5, B: 6}, | |
| 291 | + | TrueColor: true, | |
| 292 | + | SchemeKnown: true, | |
| 293 | + | PaletteKnown: 0x8001, | |
| 294 | + | Palette: palette, | |
| 295 | + | }, | |
| 296 | + | want: []byte{ | |
| 297 | + | 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x80, 0x01, | |
| 298 | + | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, | |
| 299 | + | 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, | |
| 300 | + | 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, | |
| 301 | + | 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, | |
| 302 | + | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, | |
| 303 | + | 0x3d, 0x3e, 0x3f, | |
| 304 | + | }, | |
| 305 | + | }, | |
| 306 | + | } | |
| 307 | + | ||
| 308 | + | for _, tt := range tests { | |
| 309 | + | t.Run(tt.name, func(t *testing.T) { | |
| 310 | + | got := MarshalTheme(tt.msg) | |
| 311 | + | require.Len(t, got, 57) | |
| 312 | + | require.Equal(t, tt.want, got) | |
| 313 | + | back, err := UnmarshalTheme(got) | |
| 314 | + | require.NoError(t, err) | |
| 315 | + | require.Equal(t, tt.msg, back) | |
| 316 | + | }) | |
| 317 | + | } | |
| 318 | + | ||
| 319 | + | full := MarshalTheme(tests[len(tests)-1].msg) | |
| 320 | + | assertAllPrefixesFail(t, full, UnmarshalTheme) | |
| 321 | + | assertTrailingGarbageFails(t, full, UnmarshalTheme) | |
| 286 | 322 | } | |
| 287 | 323 | ||
| 288 | 324 | func TestResizeGoldenAndRoundTrip(t *testing.T) { | |
| @@ -254,35 +254,71 @@ func TestThemeGoldenAndRoundTrip(t *testing.T) { | |||||
| 254 | {R: 0x34, G: 0x35, B: 0x36}, {R: 0x37, G: 0x38, B: 0x39}, | 254 | {R: 0x34, G: 0x35, B: 0x36}, {R: 0x37, G: 0x38, B: 0x39}, | ||
| 255 | {R: 0x3a, G: 0x3b, B: 0x3c}, {R: 0x3d, G: 0x3e, B: 0x3f}, | 255 | {R: 0x3a, G: 0x3b, B: 0x3c}, {R: 0x3d, G: 0x3e, B: 0x3f}, | ||
| 256 | } | 256 | } | ||
| 257 | - | msg := Theme{ | 257 | + | zeroes := make([]byte, 57) |
| 258 | - | HasForeground: true, | 258 | + | tests := []struct { |
| 259 | - | Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | 259 | + | name string |
| 260 | - | HasBackground: true, | 260 | + | msg Theme |
| 261 | - | Background: renderer.RGB{R: 4, G: 5, B: 6}, | 261 | + | want []byte |
| 262 | - | TrueColor: true, | 262 | + | }{ |
| 263 | - | SchemeKnown: true, | 263 | + | { |
| 264 | - | PaletteKnown: 0x8001, | 264 | + | name: "empty", |
| 265 | - | Palette: palette, | 265 | + | msg: Theme{}, |
| 266 | - | } | 266 | + | want: zeroes, |
| 267 | - | want := []byte{ | 267 | + | }, |
| 268 | - | 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x80, 0x01, | 268 | + | { |
| 269 | - | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, | 269 | + | name: "foreground only", |
| 270 | - | 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, | 270 | + | msg: Theme{ |
| 271 | - | 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, | 271 | + | HasForeground: true, |
| 272 | - | 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, | 272 | + | Foreground: renderer.RGB{R: 10, G: 20, B: 30}, |
| 273 | - | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, | 273 | + | Background: renderer.RGB{R: 40, G: 50, B: 60}, |
| 274 | - | 0x3d, 0x3e, 0x3f, | 274 | + | }, |
| 275 | - | } | 275 | + | want: append([]byte{0x01, 0x0a, 0x14, 0x1e, 0x28, 0x32, 0x3c}, zeroes[7:]...), |
| 276 | - | 276 | + | }, | |
| 277 | - | got := MarshalTheme(msg) | 277 | + | { |
| 278 | - | require.Len(t, got, 57) | 278 | + | name: "light flag without known scheme", |
| 279 | - | require.Equal(t, want, got) | 279 | + | msg: Theme{ |
| 280 | - | back, err := UnmarshalTheme(got) | 280 | + | Light: true, |
| 281 | - | require.NoError(t, err) | 281 | + | }, |
| 282 | - | require.Equal(t, msg, back) | 282 | + | want: append([]byte{0x10}, zeroes[1:]...), |
| 283 | - | 283 | + | }, | |
| 284 | - | assertAllPrefixesFail(t, got, UnmarshalTheme) | 284 | + | { |
| 285 | - | assertTrailingGarbageFails(t, got, UnmarshalTheme) | 285 | + | name: "full palette", |
| 286 | + | msg: Theme{ | |||
| 287 | + | HasForeground: true, | |||
| 288 | + | Foreground: renderer.RGB{R: 1, G: 2, B: 3}, | |||
| 289 | + | HasBackground: true, | |||
| 290 | + | Background: renderer.RGB{R: 4, G: 5, B: 6}, | |||
| 291 | + | TrueColor: true, | |||
| 292 | + | SchemeKnown: true, | |||
| 293 | + | PaletteKnown: 0x8001, | |||
| 294 | + | Palette: palette, | |||
| 295 | + | }, | |||
| 296 | + | want: []byte{ | |||
| 297 | + | 0x0f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x80, 0x01, | |||
| 298 | + | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, | |||
| 299 | + | 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, | |||
| 300 | + | 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, | |||
| 301 | + | 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, | |||
| 302 | + | 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, | |||
| 303 | + | 0x3d, 0x3e, 0x3f, | |||
| 304 | + | }, | |||
| 305 | + | }, | |||
| 306 | + | } | |||
| 307 | + | ||||
| 308 | + | for _, tt := range tests { | |||
| 309 | + | t.Run(tt.name, func(t *testing.T) { | |||
| 310 | + | got := MarshalTheme(tt.msg) | |||
| 311 | + | require.Len(t, got, 57) | |||
| 312 | + | require.Equal(t, tt.want, got) | |||
| 313 | + | back, err := UnmarshalTheme(got) | |||
| 314 | + | require.NoError(t, err) | |||
| 315 | + | require.Equal(t, tt.msg, back) | |||
| 316 | + | }) | |||
| 317 | + | } | |||
| 318 | + | ||||
| 319 | + | full := MarshalTheme(tests[len(tests)-1].msg) | |||
| 320 | + | assertAllPrefixesFail(t, full, UnmarshalTheme) | |||
| 321 | + | assertTrailingGarbageFails(t, full, UnmarshalTheme) | |||
| 286 | } | 322 | } | ||
| 287 | 323 | ||||
| 288 | func TestResizeGoldenAndRoundTrip(t *testing.T) { | 324 | func TestResizeGoldenAndRoundTrip(t *testing.T) { | ||