chore: simplify string using backticks

# Conflicts:
#	internal/extgen/classparser.go
#	internal/extgen/gofile_test.go
This commit is contained in:
Kévin Dunglas
2025-09-12 11:55:24 +02:00
parent e917ab7974
commit b749f52ae5
6 changed files with 13 additions and 13 deletions

View File

@@ -42,7 +42,7 @@ type FrankenPHPApp struct {
logger *slog.Logger
}
var iniError = errors.New("'php_ini' must be in the format: php_ini \"<key>\" \"<value>\"")
var iniError = errors.New(`"php_ini" must be in the format: php_ini "<key>" "<value>"`)
// CaddyModule returns the Caddy module information.
func (f FrankenPHPApp) CaddyModule() caddy.ModuleInfo {

View File

@@ -313,7 +313,7 @@ func TestCFileSpecialCharacters(t *testing.T) {
content, err := cGen.buildContent()
require.NoError(t, err)
expectedInclude := "#include \"" + tt.expected + ".h\""
expectedInclude := `#include "` + tt.expected + `.h"`
assert.Contains(t, content, expectedInclude, "Content should contain include: %s", expectedInclude)
})
}
@@ -424,8 +424,8 @@ func TestCFileConstants(t *testing.T) {
},
},
contains: []string{
"REGISTER_LONG_CONSTANT(\"GLOBAL_INT\", 42, CONST_CS | CONST_PERSISTENT);",
"REGISTER_STRING_CONSTANT(\"GLOBAL_STRING\", \"test\", CONST_CS | CONST_PERSISTENT);",
`REGISTER_LONG_CONSTANT("GLOBAL_INT", 42, CONST_CS | CONST_PERSISTENT);`,
`REGISTER_STRING_CONSTANT("GLOBAL_STRING", "test", CONST_CS | CONST_PERSISTENT);`,
},
},
}

View File

@@ -99,7 +99,7 @@ func (cp *ConstantParser) parse(filename string) (constants []phpConstant, err e
func determineConstantType(value string) phpType {
value = strings.TrimSpace(value)
if (strings.HasPrefix(value, "\"") && strings.HasSuffix(value, "\"")) ||
if (strings.HasPrefix(value, `"`) && strings.HasSuffix(value, `"`)) ||
(strings.HasPrefix(value, "`") && strings.HasSuffix(value, "`")) {
return phpString
}

View File

@@ -250,7 +250,7 @@ func TestConstantParserTypeDetection(t *testing.T) {
value string
expectedType phpType
}{
{"string with double quotes", "\"hello world\"", phpString},
{"string with double quotes", `"hello world"`, phpString},
{"string with backticks", "`hello world`", phpString},
{"boolean true", "true", phpBool},
{"boolean false", "false", phpBool},
@@ -443,13 +443,13 @@ func TestConstantParserDeclRegex(t *testing.T) {
name string
value string
}{
{"const MyConst = \"value\"", true, "MyConst", "\"value\""},
{`const MyConst = "value"`, true, "MyConst", `"value"`},
{"const IntConst = 42", true, "IntConst", "42"},
{"const BoolConst = true", true, "BoolConst", "true"},
{"const IotaConst = iota", true, "IotaConst", "iota"},
{"const ComplexValue = someFunction()", true, "ComplexValue", "someFunction()"},
{"const SpacedName = \"with spaces\"", true, "SpacedName", "\"with spaces\""},
{"var notAConst = \"value\"", false, "", ""},
{`const SpacedName = "with spaces"`, true, "SpacedName", `"with spaces"`},
{`var notAConst = "value"`, false, "", ""},
{"const", false, "", ""},
{"const =", false, "", ""},
}
@@ -518,10 +518,10 @@ func TestPHPConstantCValue(t *testing.T) {
name: "string constant",
constant: phpConstant{
Name: "StringConst",
Value: "\"hello\"",
Value: `"hello"`,
PhpType: phpString,
},
expected: "\"hello\"", // strings should remain unchanged
expected: `"hello"`, // strings should remain unchanged
},
{
name: "boolean constant",

View File

@@ -134,7 +134,7 @@ func TestStubGenerator_BuildContent(t *testing.T) {
contains: []string{
"<?php",
"/** @generate-class-entries */",
"const GLOBAL_CONST = \"test\";",
`const GLOBAL_CONST = "test";`,
},
},
{

View File

@@ -26,7 +26,7 @@ func NamespacedName(namespace, name string) string {
if namespace == "" {
return name
}
namespacePart := strings.ReplaceAll(namespace, "\\", "_")
namespacePart := strings.ReplaceAll(namespace, `\`, "_")
return namespacePart + "_" + name
}