Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions pkg/database/tags/normalization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ package tags

import (
"testing"

"github.com/ZaparooProject/go-zapscript"
)

func TestNormalizeTag(t *testing.T) {
Expand Down Expand Up @@ -87,54 +85,3 @@ func TestNormalizeTag(t *testing.T) {
})
}
}

func TestNormalizeTagFilter(t *testing.T) {
tests := []struct {
name string
input zapscript.TagFilter
expected zapscript.TagFilter
}{
{
name: "basic normalization",
input: zapscript.TagFilter{
Type: "Genre",
Value: "RPG",
},
expected: zapscript.TagFilter{
Type: "genre",
Value: "rpg",
},
},
{
name: "complex normalization",
input: zapscript.TagFilter{
Type: " Year ",
Value: " 1.991 ",
},
expected: zapscript.TagFilter{
Type: "year",
Value: "1-991",
},
},
{
name: "keep colon and dash in value",
input: zapscript.TagFilter{
Type: "Disc",
Value: "1-2",
},
expected: zapscript.TagFilter{
Type: "disc",
Value: "1-2",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := NormalizeTagFilter(tt.input)
if result.Type != tt.expected.Type || result.Value != tt.expected.Value {
t.Errorf("NormalizeTagFilter(%+v) = %+v, want %+v", tt.input, result, tt.expected)
}
})
}
}
47 changes: 2 additions & 45 deletions pkg/database/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,12 @@
package tags

import (
"regexp"
"strings"

"github.com/ZaparooProject/go-zapscript"
)

// This tag system is inspired by the GameDataBase project's hierarchical
// tag taxonomy. Reference: https://github.com/PigSaint/GameDataBase/blob/main/tags.yml

// Package-level compiled regexes for tag normalization.
// These are compiled once at initialization for optimal performance.
var (
reColonSpacing = regexp.MustCompile(`\s*:\s*`)
reSpecialChars = regexp.MustCompile(`[^a-z0-9:,+\-]`)
)

// TagType represents a top-level tag category
type TagType string

Expand Down Expand Up @@ -134,41 +124,8 @@ const (
// for simplicity, but the taxonomy and tag values are directly inspired by their work.

// NormalizeTag normalizes a tag string for consistent querying and storage.
// Applied to BOTH type and value parts separately.
// Rules: trim whitespace, normalize colon spacing, lowercase, spaces→dashes,
// periods→dashes, and remove special chars (except colon, dash, and comma)
func NormalizeTag(s string) string {
// 1. Trim whitespace
s = strings.TrimSpace(s)

// 2. Normalize colon spacing - remove spaces around colons first
s = reColonSpacing.ReplaceAllString(s, ":")

// 3. Convert to lowercase
s = strings.ToLower(s)

// 4. Replace remaining spaces with dashes
s = strings.ReplaceAll(s, " ", "-")

// 5. Convert periods to dashes (for version numbers like "1.2.3" → "1-2-3")
s = strings.ReplaceAll(s, ".", "-")

// 6. Remove other special chars (except colon, dash, and comma)
// Keep: a-z, 0-9, dash, colon, comma
s = reSpecialChars.ReplaceAllString(s, "")

return s
}

// NormalizeTagFilter normalizes a TagFilter for consistent querying.
// Applies normalization to both Type and Value fields.
func NormalizeTagFilter(filter zapscript.TagFilter) zapscript.TagFilter {
return zapscript.TagFilter{
Type: NormalizeTag(filter.Type),
Value: NormalizeTag(filter.Value),
Operator: filter.Operator,
}
}
// Delegates to go-zapscript's implementation.
var NormalizeTag = zapscript.NormalizeTag

var CanonicalTagDefinitions = map[TagType][]TagValue{
TagTypeInput: {
Expand Down
28 changes: 0 additions & 28 deletions pkg/zapscript/advargs/advargs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,6 @@ func TestParse_GlobalArgs(t *testing.T) {
}
}

func TestGlobalArgs_ShouldRun(t *testing.T) {
t.Parallel()

tests := []struct {
name string
when string
want bool
}{
{name: "empty when", when: "", want: true},
{name: "true", when: "true", want: true},
{name: "yes", when: "yes", want: true},
{name: "false", when: "false", want: false},
{name: "no", when: "no", want: false},
// IsTruthy only accepts "true" and "yes", all other values are falsey
{name: "1 is falsey", when: "1", want: false},
{name: "0 is falsey", when: "0", want: false},
{name: "random string is falsey", when: "random", want: false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
args := zapscript.GlobalArgs{When: tt.when}
assert.Equal(t, tt.want, ShouldRun(args))
})
}
}

func TestParse_LaunchRandomArgs(t *testing.T) {
t.Parallel()

Expand Down
39 changes: 0 additions & 39 deletions pkg/zapscript/advargs/helpers.go

This file was deleted.

113 changes: 0 additions & 113 deletions pkg/zapscript/advargs/helpers_test.go

This file was deleted.

9 changes: 0 additions & 9 deletions pkg/zapscript/advargs/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/ZaparooProject/go-zapscript"
"github.com/ZaparooProject/zaparoo-core/v2/pkg/database/filters"
"github.com/ZaparooProject/zaparoo-core/v2/pkg/database/systemdefs"
"github.com/ZaparooProject/zaparoo-core/v2/pkg/helpers"
"github.com/go-playground/validator/v10"
"github.com/go-viper/mapstructure/v2"
)
Expand Down Expand Up @@ -155,14 +154,6 @@ func stringToTagFiltersHook() mapstructure.DecodeHookFunc {
}
}

// ShouldRun returns true if the command should execute based on the When condition.
func ShouldRun(g zapscript.GlobalArgs) bool {
if g.When == "" {
return true
}
return helpers.IsTruthy(g.When)
}

// validateLauncher checks if a launcher ID exists in the available launchers.
// Comparison is case-insensitive since launcher IDs are user-facing identifiers.
func validateLauncher(ctx context.Context, fl validator.FieldLevel) bool {
Expand Down
Loading