Make file parsing concurrent
This commit is contained in:
10
main.go
10
main.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
lua "github.com/yuin/gopher-lua"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@@ -10,8 +11,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
lua "github.com/yuin/gopher-lua"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var Error *log.Logger
|
var Error *log.Logger
|
||||||
@@ -127,8 +127,12 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
// Process each file
|
// Process each file
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(file string) {
|
||||||
|
defer wg.Done()
|
||||||
Info.Printf("🔄 Processing file: %s", file)
|
Info.Printf("🔄 Processing file: %s", file)
|
||||||
err := processFile(file, pattern, luaExpr, originalLuaExpr)
|
err := processFile(file, pattern, luaExpr, originalLuaExpr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -138,7 +142,9 @@ func main() {
|
|||||||
Info.Printf("✅ Successfully processed file: %s", file)
|
Info.Printf("✅ Successfully processed file: %s", file)
|
||||||
stats.ProcessedFiles++
|
stats.ProcessedFiles++
|
||||||
}
|
}
|
||||||
|
}(file)
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
// Print summary of all modifications
|
// Print summary of all modifications
|
||||||
printSummary(originalLuaExpr)
|
printSummary(originalLuaExpr)
|
||||||
|
32
main_test.go
32
main_test.go
@@ -80,6 +80,38 @@ func TestShorthandNotation(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestShorthandNotationFloats(t *testing.T) {
|
||||||
|
fileContents := `
|
||||||
|
<config>
|
||||||
|
<item>
|
||||||
|
<value>132.671327</value>
|
||||||
|
</item>
|
||||||
|
</config>
|
||||||
|
`
|
||||||
|
expected := `
|
||||||
|
<config>
|
||||||
|
<item>
|
||||||
|
<value>176.01681007940928</value>
|
||||||
|
</item>
|
||||||
|
</config>
|
||||||
|
`
|
||||||
|
|
||||||
|
regex := regexp.MustCompile(`(?s)<value>(\d*\.?\d+)</value>`)
|
||||||
|
luaExpr := `v1 * 1.32671327` // Use direct assignment syntax
|
||||||
|
luaScript := buildLuaScript(luaExpr)
|
||||||
|
|
||||||
|
modifiedContent, _, _, err := process(fileContents, regex, luaScript, "test.xml", luaExpr )
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Error processing file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
normalizedModified := normalizeWhitespace(modifiedContent)
|
||||||
|
normalizedExpected := normalizeWhitespace(expected)
|
||||||
|
if normalizedModified != normalizedExpected {
|
||||||
|
t.Fatalf("Expected modified content to be %q, but got %q", normalizedExpected, normalizedModified)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestArrayNotation(t *testing.T) {
|
func TestArrayNotation(t *testing.T) {
|
||||||
fileContents := `
|
fileContents := `
|
||||||
<config>
|
<config>
|
||||||
|
Reference in New Issue
Block a user