MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / TestReplaceEntities

Function TestReplaceEntities

xmlparser/entities_test.go:36–75  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34}
35
36func TestReplaceEntities(t *testing.T) {
37 em := map[string][]byte{
38 "entity1": []byte("Value1"),
39 "entity2": []byte("Value2"),
40 "entity3": []byte("Value3"),
41 }
42
43 input1 := `
44 This is a test string with &entity1;, &entity2;, and &entity3; to be replaced.
45 Unknown entity &entity4; should remain unchanged.
46 Known entity &entity1; after unknown &entity4; should still replace.
47 Incomplete entity &entity1 should also remain unchanged.
48 `
49 expected1 := `
50 This is a test string with Value1, Value2, and Value3 to be replaced.
51 Unknown entity &entity4; should remain unchanged.
52 Known entity Value1 after unknown &entity4; should still replace.
53 Incomplete entity &entity1 should also remain unchanged.
54 `
55
56 // Corner case with entity at the very start and end
57 input2 := `&entity1;`
58 expected2 := `Value1`
59
60 t.Run("string", func(t *testing.T) {
61 result := xmlparser.ReplaceEntitiesString(input1, em)
62 require.Equal(t, expected1, result)
63
64 result = xmlparser.ReplaceEntitiesString(input2, em)
65 require.Equal(t, expected2, result)
66 })
67
68 t.Run("bytes", func(t *testing.T) {
69 result := xmlparser.ReplaceEntitiesBytes([]byte(input1), em)
70 require.Equal(t, expected1, string(result))
71
72 result = xmlparser.ReplaceEntitiesBytes([]byte(input2), em)
73 require.Equal(t, expected2, string(result))
74 })
75}
76
77func BenchmarkParseEntityMap(b *testing.B) {
78 directive := &xmlparser.Directive{

Callers

nothing calls this directly

Calls 3

ReplaceEntitiesStringFunction · 0.92
ReplaceEntitiesBytesFunction · 0.92
RunMethod · 0.80

Tested by

no test coverage detected