mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-19 22:55:29 +00:00
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
Go's min/max propagate NaN, so "nan" got past parse_opacity and failed later with an unclear json.Marshal error, while the Python parser silently clamped it to 0. Reject NaN in both, report a clear error message for invalid opacity values, and replace the regression test with a table test of parse_opacity covering clamping and invalid inputs.
27 lines
709 B
Go
27 lines
709 B
Go
// License: GPLv3 Copyright: 2026, kitty contributors
|
|
|
|
package at
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseOpacity(t *testing.T) {
|
|
valid := map[string]float64{
|
|
"0.5": 0.5, "0": 0, "1": 1, "2": 1, "-1": 0, "inf": 1, "-inf": 0,
|
|
}
|
|
for arg, expected := range valid {
|
|
actual, err := parse_opacity(arg)
|
|
if err != nil {
|
|
t.Fatalf("parse_opacity(%#v) failed with error: %s", arg, err)
|
|
}
|
|
if actual != expected {
|
|
t.Fatalf("parse_opacity(%#v) = %v != %v", arg, actual, expected)
|
|
}
|
|
}
|
|
for _, arg := range []string{"oops", "", "nan", "NaN", "0.5x"} {
|
|
if actual, err := parse_opacity(arg); err == nil {
|
|
t.Fatalf("parse_opacity(%#v) accepted an invalid number and returned: %v", arg, actual)
|
|
}
|
|
}
|
|
}
|