Rework modifiers to variables again
This commit is contained in:
75
toml_test.go
75
toml_test.go
@@ -69,8 +69,8 @@ func TestTOMLGlobalModifiers(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
// Create TOML content with global modifiers
|
||||
tomlContent := `[modifiers]
|
||||
// Create TOML content with global variables
|
||||
tomlContent := `[variables]
|
||||
multiplier = 3
|
||||
prefix = "TEST_"
|
||||
enabled = true
|
||||
@@ -94,15 +94,15 @@ files = ["test.txt"]
|
||||
os.Chdir(tmpDir)
|
||||
|
||||
// Test loading TOML commands
|
||||
commands, modifiers, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
commands, variables, 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")
|
||||
assert.Len(t, modifiers, 3, "Should load 3 modifiers")
|
||||
assert.Len(t, variables, 3, "Should load 3 variables")
|
||||
|
||||
// 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 variables
|
||||
assert.Equal(t, int64(3), variables["multiplier"], "Multiplier should be 3")
|
||||
assert.Equal(t, "TEST_", variables["prefix"], "Prefix should be TEST_")
|
||||
assert.Equal(t, true, variables["enabled"], "Enabled should be true")
|
||||
|
||||
// Verify regular command
|
||||
assert.Equal(t, "UseGlobalModifiers", commands[0].Name, "Regular command name should match")
|
||||
@@ -118,7 +118,7 @@ func TestTOMLMultilineRegex(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
// Create TOML content with multiline regex using literal strings
|
||||
tomlContent := `[modifiers]
|
||||
tomlContent := `[variables]
|
||||
factor = 2.5
|
||||
|
||||
[[commands]]
|
||||
@@ -164,10 +164,10 @@ isolate = true
|
||||
os.Chdir(tmpDir)
|
||||
|
||||
// Test loading TOML commands
|
||||
commands, modifiers, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
commands, variables, 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")
|
||||
assert.Len(t, modifiers, 1, "Should load 1 modifier")
|
||||
assert.Len(t, variables, 1, "Should load 1 variable")
|
||||
|
||||
// Verify the multiline regex command
|
||||
multilineCmd := commands[0]
|
||||
@@ -303,7 +303,7 @@ func TestTOMLEndToEndIntegration(t *testing.T) {
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
// Create comprehensive TOML content
|
||||
tomlContent := `[modifiers]
|
||||
tomlContent := `[variables]
|
||||
multiplier = 4
|
||||
base_value = 100
|
||||
|
||||
@@ -358,10 +358,10 @@ some_other_setting = enabled = true
|
||||
os.Chdir(tmpDir)
|
||||
|
||||
// Test the complete workflow using the main function
|
||||
commands, modifiers, err := utils.LoadCommands([]string{"test.toml"})
|
||||
commands, variables, err := utils.LoadCommands([]string{"test.toml"})
|
||||
assert.NoError(t, err, "Should load TOML commands without error")
|
||||
assert.Len(t, commands, 2, "Should load 2 commands")
|
||||
assert.Len(t, modifiers, 2, "Should load 2 modifiers")
|
||||
assert.Len(t, variables, 2, "Should load 2 variables")
|
||||
|
||||
// Associate files with commands
|
||||
files := []string{"test.txt"}
|
||||
@@ -441,21 +441,20 @@ func TestYAMLToTOMLConversion(t *testing.T) {
|
||||
os.Chdir(tmpDir)
|
||||
|
||||
// Create a test YAML file
|
||||
yamlContent := `- name: "ConversionTest"
|
||||
regex: "value = !num"
|
||||
lua: "v1 * 3"
|
||||
files: ["test.txt"]
|
||||
loglevel: DEBUG
|
||||
yamlContent := `variables:
|
||||
multiplier: 2.5
|
||||
prefix: "CONV_"
|
||||
|
||||
- name: "AnotherTest"
|
||||
regex: "enabled = (true|false)"
|
||||
lua: "= false"
|
||||
files: ["*.conf"]
|
||||
|
||||
- name: "GlobalModifiers"
|
||||
modifiers:
|
||||
multiplier: 2.5
|
||||
prefix: "CONV_"
|
||||
commands:
|
||||
- name: "ConversionTest"
|
||||
regex: "value = !num"
|
||||
lua: "v1 * 3"
|
||||
files: ["test.txt"]
|
||||
loglevel: DEBUG
|
||||
- name: "AnotherTest"
|
||||
regex: "enabled = (true|false)"
|
||||
lua: "= false"
|
||||
files: ["*.conf"]
|
||||
`
|
||||
|
||||
yamlFile := filepath.Join(tmpDir, "test.yml")
|
||||
@@ -478,27 +477,17 @@ func TestYAMLToTOMLConversion(t *testing.T) {
|
||||
tomlContent := string(tomlData)
|
||||
assert.Contains(t, tomlContent, `name = "ConversionTest"`, "TOML should contain first command name")
|
||||
assert.Contains(t, tomlContent, `name = "AnotherTest"`, "TOML should contain second command name")
|
||||
assert.Contains(t, tomlContent, `[modifiers]`, "TOML should contain modifiers section")
|
||||
assert.Contains(t, tomlContent, `[variables]`, "TOML should contain variables section")
|
||||
assert.Contains(t, tomlContent, `multiplier = 2.5`, "TOML should contain multiplier")
|
||||
assert.Contains(t, tomlContent, `prefix = "CONV_"`, "TOML should contain prefix")
|
||||
|
||||
// Test that converted TOML loads correctly
|
||||
commands, modifiers, err := utils.LoadCommandsFromTomlFiles("test.toml")
|
||||
commands, variables, 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, modifiers, 0, "Should have no top-level modifiers")
|
||||
assert.Len(t, commands, 2, "Should load 2 commands from converted TOML")
|
||||
assert.Len(t, variables, 2, "Should have 2 variables")
|
||||
|
||||
// Find the modifier command entry
|
||||
var modifierCmd *utils.ModifyCommand
|
||||
for i := range commands {
|
||||
if commands[i].Name == "GlobalModifiers" {
|
||||
modifierCmd = &commands[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.NotNil(t, modifierCmd, "Should find GlobalModifiers command")
|
||||
assert.Equal(t, 2.5, modifierCmd.Modifiers["multiplier"], "Should preserve multiplier value")
|
||||
assert.Equal(t, "CONV_", modifierCmd.Modifiers["prefix"], "Should preserve prefix value")
|
||||
// Variables are now loaded separately, not as part of commands
|
||||
|
||||
// Test skip functionality - run conversion again
|
||||
err = utils.ConvertYAMLToTOML("test.yml")
|
||||
|
||||
Reference in New Issue
Block a user