Rework variables to not be commands...
This commit is contained in:
67
toml_test.go
67
toml_test.go
@@ -44,7 +44,7 @@ files = ["*.txt"]
|
||||
os.Chdir(tmpDir)
|
||||
|
||||
// Test loading TOML commands
|
||||
commands, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
commands, _, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
assert.NoError(t, err, "Should load TOML commands without error")
|
||||
assert.Len(t, commands, 2, "Should load 2 commands from TOML")
|
||||
|
||||
@@ -92,23 +92,19 @@ files = ["test.txt"]
|
||||
os.Chdir(tmpDir)
|
||||
|
||||
// Test loading TOML commands
|
||||
commands, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
commands, modifiers, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
assert.NoError(t, err, "Should load TOML commands without error")
|
||||
assert.Len(t, commands, 2, "Should load 2 commands from TOML")
|
||||
assert.Len(t, commands, 1, "Should load 1 command from TOML")
|
||||
assert.Len(t, modifiers, 3, "Should load 3 modifiers")
|
||||
|
||||
// Verify global modifiers command (first command should have only modifiers)
|
||||
assert.Empty(t, commands[0].Name, "Global modifiers command should have no name")
|
||||
assert.Empty(t, commands[0].Regex, "Global modifiers command should have no regex")
|
||||
assert.Empty(t, commands[0].Lua, "Global modifiers command should have no lua")
|
||||
assert.Empty(t, commands[0].Files, "Global modifiers command should have no files")
|
||||
assert.Len(t, commands[0].Modifiers, 3, "Global modifiers command should have 3 modifiers")
|
||||
assert.Equal(t, int64(3), commands[0].Modifiers["multiplier"], "Multiplier should be 3")
|
||||
assert.Equal(t, "TEST_", commands[0].Modifiers["prefix"], "Prefix should be TEST_")
|
||||
assert.Equal(t, true, commands[0].Modifiers["enabled"], "Enabled should be true")
|
||||
// Verify modifiers
|
||||
assert.Equal(t, int64(3), modifiers["multiplier"], "Multiplier should be 3")
|
||||
assert.Equal(t, "TEST_", modifiers["prefix"], "Prefix should be TEST_")
|
||||
assert.Equal(t, true, modifiers["enabled"], "Enabled should be true")
|
||||
|
||||
// Verify regular command
|
||||
assert.Equal(t, "UseGlobalModifiers", commands[1].Name, "Regular command name should match")
|
||||
assert.Equal(t, "value = !num", commands[1].Regex, "Regular command regex should match")
|
||||
assert.Equal(t, "UseGlobalModifiers", commands[0].Name, "Regular command name should match")
|
||||
assert.Equal(t, "value = !num", commands[0].Regex, "Regular command regex should match")
|
||||
}
|
||||
|
||||
func TestTOMLMultilineRegex(t *testing.T) {
|
||||
@@ -166,12 +162,13 @@ isolate = true
|
||||
os.Chdir(tmpDir)
|
||||
|
||||
// Test loading TOML commands
|
||||
commands, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
commands, modifiers, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
assert.NoError(t, err, "Should load TOML commands without error")
|
||||
assert.Len(t, commands, 2, "Should load 2 commands from TOML")
|
||||
assert.Len(t, commands, 1, "Should load 1 command from TOML")
|
||||
assert.Len(t, modifiers, 1, "Should load 1 modifier")
|
||||
|
||||
// Verify the multiline regex command
|
||||
multilineCmd := commands[1]
|
||||
multilineCmd := commands[0]
|
||||
assert.Equal(t, "MultilineTest", multilineCmd.Name, "Command name should match")
|
||||
assert.Contains(t, multilineCmd.Regex, "\\[config\\.settings\\]", "Regex should contain escaped brackets")
|
||||
assert.Contains(t, multilineCmd.Regex, "depth = !num", "Regex should contain depth pattern")
|
||||
@@ -225,7 +222,7 @@ files = ["*.conf", "*.ini"]
|
||||
os.Chdir(tmpDir)
|
||||
|
||||
// Test loading TOML commands
|
||||
commands, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
commands, _, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
assert.NoError(t, err, "Should load TOML commands without error")
|
||||
assert.Len(t, commands, 1, "Should load 1 command from TOML")
|
||||
|
||||
@@ -276,7 +273,7 @@ files = ["config.json"]
|
||||
os.Chdir(tmpDir)
|
||||
|
||||
// Test loading TOML commands
|
||||
commands, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
commands, _, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
assert.NoError(t, err, "Should load TOML commands without error")
|
||||
assert.Len(t, commands, 2, "Should load 2 commands from TOML")
|
||||
|
||||
@@ -358,9 +355,10 @@ some_other_setting = enabled = true
|
||||
os.Chdir(tmpDir)
|
||||
|
||||
// Test the complete workflow using the main function
|
||||
commands, err := utils.LoadCommands([]string{"test.toml"})
|
||||
commands, modifiers, err := utils.LoadCommands([]string{"test.toml"})
|
||||
assert.NoError(t, err, "Should load TOML commands without error")
|
||||
assert.Len(t, commands, 3, "Should load 3 commands total (including global modifiers)")
|
||||
assert.Len(t, commands, 2, "Should load 2 commands")
|
||||
assert.Len(t, modifiers, 2, "Should load 2 modifiers")
|
||||
|
||||
// Associate files with commands
|
||||
files := []string{"test.txt"}
|
||||
@@ -406,13 +404,13 @@ files = ["test.txt"
|
||||
err = os.WriteFile(invalidFile, []byte(invalidTOML), 0644)
|
||||
assert.NoError(t, err, "Should write invalid TOML file")
|
||||
|
||||
commands, err := utils.LoadCommandsFromTomlFiles("invalid.toml")
|
||||
commands, _, err := utils.LoadCommandsFromTomlFiles("invalid.toml")
|
||||
assert.Error(t, err, "Should return error for invalid TOML syntax")
|
||||
assert.Nil(t, commands, "Should return nil commands for invalid TOML")
|
||||
assert.Contains(t, err.Error(), "failed to unmarshal TOML file", "Error should mention TOML unmarshaling")
|
||||
|
||||
// Test 2: Non-existent file
|
||||
commands, err = utils.LoadCommandsFromTomlFiles("nonexistent.toml")
|
||||
commands, _, err = utils.LoadCommandsFromTomlFiles("nonexistent.toml")
|
||||
assert.NoError(t, err, "Should handle non-existent file without error")
|
||||
assert.Empty(t, commands, "Should return empty commands for non-existent file")
|
||||
|
||||
@@ -421,7 +419,7 @@ files = ["test.txt"
|
||||
err = os.WriteFile(emptyFile, []byte(""), 0644)
|
||||
assert.NoError(t, err, "Should write empty TOML file")
|
||||
|
||||
commands, err = utils.LoadCommandsFromTomlFiles("empty.toml")
|
||||
commands, _, err = utils.LoadCommandsFromTomlFiles("empty.toml")
|
||||
assert.Error(t, err, "Should return error for empty TOML file")
|
||||
assert.Nil(t, commands, "Should return nil commands for empty TOML")
|
||||
}
|
||||
@@ -482,23 +480,14 @@ func TestYAMLToTOMLConversion(t *testing.T) {
|
||||
assert.Contains(t, tomlContent, `prefix = "CONV_"`, "TOML should contain prefix")
|
||||
|
||||
// Test that converted TOML loads correctly
|
||||
commands, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
commands, modifiers, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
assert.NoError(t, err, "Should load converted TOML without error")
|
||||
assert.Len(t, commands, 3, "Should load 3 commands from converted TOML")
|
||||
assert.Len(t, commands, 2, "Should load 2 commands from converted TOML")
|
||||
assert.Len(t, modifiers, 2, "Should load 2 modifiers from converted TOML")
|
||||
|
||||
// Find global modifiers command (it might not be first)
|
||||
var globalCmd utils.ModifyCommand
|
||||
foundGlobal := false
|
||||
for _, cmd := range commands {
|
||||
if cmd.Name == "GlobalModifiers" {
|
||||
globalCmd = cmd
|
||||
foundGlobal = true
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.True(t, foundGlobal, "Should find global modifiers command")
|
||||
assert.Equal(t, 2.5, globalCmd.Modifiers["multiplier"], "Should preserve multiplier value")
|
||||
assert.Equal(t, "CONV_", globalCmd.Modifiers["prefix"], "Should preserve prefix value")
|
||||
// Verify modifiers
|
||||
assert.Equal(t, 2.5, modifiers["multiplier"], "Should preserve multiplier value")
|
||||
assert.Equal(t, "CONV_", modifiers["prefix"], "Should preserve prefix value")
|
||||
|
||||
// Test skip functionality - run conversion again
|
||||
err = utils.ConvertYAMLToTOML("test.yml")
|
||||
|
||||
Reference in New Issue
Block a user