summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-14 11:14:53 +0300
committerPaul Buetow <paul@buetow.org>2026-04-14 11:14:53 +0300
commita58a6cf092338e0dac45608efa9f2c7b81cbe01f (patch)
treec233b3cf0e8af3992f7cd78f0ea97448bc41776c
parentd5ddf5e7d984351425402064b0e9cb77263dfe03 (diff)
y3: case-insensitive ParseCategory, ParseMetric, ParseOutputFormat
Use strings.ToLower for POLA (CLI/HTTP). Extend parse tests with mixed-case and lowercase inputs. Made-with: Cursor
-rw-r--r--internal/goprecords/parse_test.go11
-rw-r--r--internal/goprecords/types.go32
2 files changed, 24 insertions, 19 deletions
diff --git a/internal/goprecords/parse_test.go b/internal/goprecords/parse_test.go
index a38012e..7847e06 100644
--- a/internal/goprecords/parse_test.go
+++ b/internal/goprecords/parse_test.go
@@ -14,8 +14,10 @@ func TestParseCategory(t *testing.T) {
{"Kernel", CategoryKernel, true},
{"KernelMajor", CategoryKernelMajor, true},
{"KernelName", CategoryKernelName, true},
+ {"host", CategoryHost, true},
+ {"HoSt", CategoryHost, true},
+ {"kernelMAJOR", CategoryKernelMajor, true},
{"", 0, false},
- {"host", 0, false},
{"Bad", 0, false},
}
for _, tt := range tests {
@@ -38,8 +40,9 @@ func TestParseMetric(t *testing.T) {
{"Score", MetricScore, true},
{"Downtime", MetricDowntime, true},
{"Lifespan", MetricLifespan, true},
+ {"uptime", MetricUptime, true},
+ {"sCoRe", MetricScore, true},
{"", 0, false},
- {"uptime", 0, false},
{"Nope", 0, false},
}
for _, tt := range tests {
@@ -61,8 +64,10 @@ func TestParseOutputFormat(t *testing.T) {
{"Markdown", FormatMarkdown, true},
{"Gemtext", FormatGemtext, true},
{"HTML", FormatHTML, true},
+ {"html", FormatHTML, true},
+ {"GemTEXT", FormatGemtext, true},
+ {"PlainText", FormatPlaintext, true},
{"", 0, false},
- {"html", 0, false},
}
for _, tt := range tests {
got, err := ParseOutputFormat(tt.in)
diff --git a/internal/goprecords/types.go b/internal/goprecords/types.go
index 0f9c3a3..343f7e0 100644
--- a/internal/goprecords/types.go
+++ b/internal/goprecords/types.go
@@ -218,14 +218,14 @@ func MetricDescription(m Metric) string {
// ParseCategory parses a category string.
func ParseCategory(s string) (Category, error) {
- switch s {
- case "Host":
+ switch strings.ToLower(s) {
+ case "host":
return CategoryHost, nil
- case "Kernel":
+ case "kernel":
return CategoryKernel, nil
- case "KernelMajor":
+ case "kernelmajor":
return CategoryKernelMajor, nil
- case "KernelName":
+ case "kernelname":
return CategoryKernelName, nil
default:
return 0, fmt.Errorf("invalid category %q", s)
@@ -234,16 +234,16 @@ func ParseCategory(s string) (Category, error) {
// ParseMetric parses a metric string.
func ParseMetric(s string) (Metric, error) {
- switch s {
- case "Boots":
+ switch strings.ToLower(s) {
+ case "boots":
return MetricBoots, nil
- case "Uptime":
+ case "uptime":
return MetricUptime, nil
- case "Score":
+ case "score":
return MetricScore, nil
- case "Downtime":
+ case "downtime":
return MetricDowntime, nil
- case "Lifespan":
+ case "lifespan":
return MetricLifespan, nil
default:
return 0, fmt.Errorf("invalid metric %q", s)
@@ -252,14 +252,14 @@ func ParseMetric(s string) (Metric, error) {
// ParseOutputFormat parses an output format string.
func ParseOutputFormat(s string) (OutputFormat, error) {
- switch s {
- case "Plaintext":
+ switch strings.ToLower(s) {
+ case "plaintext":
return FormatPlaintext, nil
- case "Markdown":
+ case "markdown":
return FormatMarkdown, nil
- case "Gemtext":
+ case "gemtext":
return FormatGemtext, nil
- case "HTML":
+ case "html":
return FormatHTML, nil
default:
return 0, fmt.Errorf("invalid output-format %q", s)