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