MCPcopy
hub / github.com/apache/casbin / TestEscapeStringLiterals

Function TestEscapeStringLiterals

util/util_test.go:242–271  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

240}
241
242func TestEscapeStringLiterals(t *testing.T) {
243 // Test single-quoted strings
244 testEscapeStringLiterals(t, `'\1\2'`, `'\\1\\2'`)
245 testEscapeStringLiterals(t, `'\n\t'`, `'\\n\\t'`)
246 testEscapeStringLiterals(t, `'\\already\\escaped'`, `'\\\\already\\\\escaped'`)
247
248 // Test double-quoted strings
249 testEscapeStringLiterals(t, `"\1\2"`, `"\\1\\2"`)
250 testEscapeStringLiterals(t, `"\n\t"`, `"\\n\\t"`)
251
252 // Test expressions with string literals
253 testEscapeStringLiterals(t, `regexMatch('\1\2', p.obj)`, `regexMatch('\\1\\2', p.obj)`)
254 testEscapeStringLiterals(t, `regexMatch("\1\2", p.obj)`, `regexMatch("\\1\\2", p.obj)`)
255 testEscapeStringLiterals(t, `r.sub == '\test'`, `r.sub == '\\test'`)
256
257 // Test expressions without string literals
258 testEscapeStringLiterals(t, `r.sub == p.sub`, `r.sub == p.sub`)
259 testEscapeStringLiterals(t, `keyMatch(r.obj, p.obj)`, `keyMatch(r.obj, p.obj)`)
260
261 // Test multiple strings in one expression
262 testEscapeStringLiterals(t, `regexMatch('\1', '\2')`, `regexMatch('\\1', '\\2')`)
263
264 // Test empty strings
265 testEscapeStringLiterals(t, `''`, `''`)
266 testEscapeStringLiterals(t, `""`, `""`)
267
268 // Test strings with no backslashes
269 testEscapeStringLiterals(t, `'hello'`, `'hello'`)
270 testEscapeStringLiterals(t, `"world"`, `"world"`)
271}

Callers

nothing calls this directly

Calls 1

testEscapeStringLiteralsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…