Fix some tests

This commit is contained in:
2025-03-29 17:27:46 +01:00
parent 14d64495b6
commit 162d0c758d

View File

@@ -158,21 +158,24 @@ func TestAssociateFilesWithCommands(t *testing.T) {
// The associations expected depends on the implementation // The associations expected depends on the implementation
// Let's check the actual associations and verify they make sense // Let's check the actual associations and verify they make sense
for file, cmds := range associations { for file, assoc := range associations {
t.Logf("File %s is associated with %d commands", file, len(cmds)) t.Logf("File %s is associated with %d commands and %d isolate commands", file, len(assoc.Commands), len(assoc.IsolateCommands))
for i, cmd := range cmds { for i, cmd := range assoc.Commands {
t.Logf(" Command %d: Pattern=%s, Files=%v", i, cmd.Regex, cmd.Files) t.Logf(" Command %d: Pattern=%s, Files=%v", i, cmd.Regex, cmd.Files)
} }
for i, cmd := range assoc.IsolateCommands {
t.Logf(" Isolate Command %d: Pattern=%s, Files=%v", i, cmd.Regex, cmd.Files)
}
// Specific validation based on our file types // Specific validation based on our file types
switch file { switch file {
case "file1.xml": case "file1.xml":
if len(cmds) < 1 { if len(assoc.Commands) < 1 {
t.Errorf("Expected at least 1 command for file1.xml, got %d", len(cmds)) t.Errorf("Expected at least 1 command for file1.xml, got %d", len(assoc.Commands))
} }
// Verify at least one command with *.xml pattern // Verify at least one command with *.xml pattern
hasXmlGlob := false hasXmlGlob := false
for _, cmd := range cmds { for _, cmd := range assoc.Commands {
for _, glob := range cmd.Files { for _, glob := range cmd.Files {
if glob == "*.xml" { if glob == "*.xml" {
hasXmlGlob = true hasXmlGlob = true
@@ -187,12 +190,12 @@ func TestAssociateFilesWithCommands(t *testing.T) {
t.Errorf("Expected command with *.xml glob for file1.xml") t.Errorf("Expected command with *.xml glob for file1.xml")
} }
case "file2.txt": case "file2.txt":
if len(cmds) < 1 { if len(assoc.Commands) < 1 {
t.Errorf("Expected at least 1 command for file2.txt, got %d", len(cmds)) t.Errorf("Expected at least 1 command for file2.txt, got %d", len(assoc.Commands))
} }
// Verify at least one command with *.txt pattern // Verify at least one command with *.txt pattern
hasTxtGlob := false hasTxtGlob := false
for _, cmd := range cmds { for _, cmd := range assoc.Commands {
for _, glob := range cmd.Files { for _, glob := range cmd.Files {
if glob == "*.txt" { if glob == "*.txt" {
hasTxtGlob = true hasTxtGlob = true
@@ -207,12 +210,12 @@ func TestAssociateFilesWithCommands(t *testing.T) {
t.Errorf("Expected command with *.txt glob for file2.txt") t.Errorf("Expected command with *.txt glob for file2.txt")
} }
case "subdir/file3.xml": case "subdir/file3.xml":
if len(cmds) < 1 { if len(assoc.Commands) < 1 {
t.Errorf("Expected at least 1 command for subdir/file3.xml, got %d", len(cmds)) t.Errorf("Expected at least 1 command for subdir/file3.xml, got %d", len(assoc.Commands))
} }
// Should match both *.xml and subdir/* patterns // Should match both *.xml and subdir/* patterns
matches := 0 matches := 0
for _, cmd := range cmds { for _, cmd := range assoc.Commands {
for _, glob := range cmd.Files { for _, glob := range cmd.Files {
if glob == "*.xml" || glob == "subdir/*" { if glob == "*.xml" || glob == "subdir/*" {
matches++ matches++
@@ -393,10 +396,10 @@ func TestLoadCommandsFromCookFileSuccess(t *testing.T) {
// Arrange // Arrange
yamlData := []byte(` yamlData := []byte(`
- name: command1 - name: command1
pattern: "*.txt" regex: "*.txt"
lua: replace lua: replace
- name: command2 - name: command2
pattern: "*.go" regex: "*.go"
lua: delete lua: delete
`) `)
@@ -420,11 +423,11 @@ func TestLoadCommandsFromCookFileWithComments(t *testing.T) {
yamlData := []byte(` yamlData := []byte(`
# This is a comment # This is a comment
- name: command1 - name: command1
pattern: "*.txt" regex: "*.txt"
lua: replace lua: replace
# Another comment # Another comment
- name: command2 - name: command2
pattern: "*.go" regex: "*.go"
lua: delete lua: delete
`) `)
@@ -445,7 +448,7 @@ func TestLoadCommandsFromCookFileWithComments(t *testing.T) {
// Handle different YAML formatting styles (flow vs block) // Handle different YAML formatting styles (flow vs block)
func TestLoadCommandsFromCookFileWithFlowStyle(t *testing.T) { func TestLoadCommandsFromCookFileWithFlowStyle(t *testing.T) {
// Arrange // Arrange
yamlData := []byte(`[ { name: command1, pattern: "*.txt", lua: replace }, { name: command2, pattern: "*.go", lua: delete } ]`) yamlData := []byte(`[ { name: command1, regex: "*.txt", lua: replace }, { name: command2, regex: "*.go", lua: delete } ]`)
// Act // Act
commands, err := LoadCommandsFromCookFile(yamlData) commands, err := LoadCommandsFromCookFile(yamlData)
@@ -496,13 +499,13 @@ func TestLoadCommandsFromCookFileWithMultipleEntries(t *testing.T) {
// Arrange // Arrange
yamlData := []byte(` yamlData := []byte(`
- name: command1 - name: command1
pattern: "*.txt" regex: "*.txt"
lua: replace lua: replace
- name: command2 - name: command2
pattern: "*.go" regex: "*.go"
lua: delete lua: delete
- name: command3 - name: command3
pattern: "*.md" regex: "*.md"
lua: append lua: append
`) `)