init push

This commit is contained in:
2026-07-16 22:16:45 +07:00
commit 8b068bdb10
1021 changed files with 332816 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
package metricparse
import "testing"
func TestParseString(t *testing.T) {
cases := []struct {
in string
want float64
}{
{"GPC/N1 63.2", 63.2}, // the "1" in N1 must NOT win
{"PTC/N2 61.8", 61.8}, // the "2" in N2 must NOT win
{"GPC/NG/N1 105.3", 105.3},
{"63.2", 63.2},
{" 63.2 ", 63.2},
{"63", 63},
{"63,2", 63.2}, // decimal comma
{"GPC/N1: 63.2 %", 63.2}, // colon + trailing unit
{"GPC/N1 63.2 / N2 61.5", 63.2}, // first standalone decimal
{"-5", -5},
{"+7.5", 7.5},
{".5", 0.5},
{"N1", 0}, // label only, no value
{"N2", 0}, // label only
{"", 0},
{" ", 0},
{"no numbers here", 0},
}
for _, c := range cases {
if got := ParseString(c.in); got != c.want {
t.Errorf("ParseString(%q) = %v, want %v", c.in, got, c.want)
}
}
}
func TestParseNilAndPtr(t *testing.T) {
if got := Parse(nil); got != 0 {
t.Fatalf("Parse(nil) = %v, want 0", got)
}
s := "GPC/N1 63.2"
if got := Parse(&s); got != 63.2 {
t.Fatalf("Parse(&%q) = %v, want 63.2", s, got)
}
}