Verifies: SYS-REQ-014 (escape handling) reqproof:proptest:skip targeted witness/regression test; not a property-test subject
(t *testing.T)
| 339 | // Verifies: SYS-REQ-014 (escape handling) |
| 340 | // reqproof:proptest:skip targeted witness/regression test; not a property-test subject |
| 341 | func TestEscape(t *testing.T) { |
| 342 | tests := []struct { |
| 343 | name string |
| 344 | in string |
| 345 | want string |
| 346 | }{ |
| 347 | {name: "plain", in: "hello", want: `"hello"`}, |
| 348 | {name: "quotation mark", in: `"`, want: `"\""`}, |
| 349 | {name: "reverse solidus", in: `\`, want: `"\\"`}, |
| 350 | {name: "solidus", in: `/`, want: `"/"`}, |
| 351 | {name: "backspace", in: "\b", want: `"\b"`}, |
| 352 | {name: "form feed", in: "\f", want: `"\f"`}, |
| 353 | {name: "line feed", in: "\n", want: `"\n"`}, |
| 354 | {name: "carriage return", in: "\r", want: `"\r"`}, |
| 355 | {name: "tab", in: "\t", want: `"\t"`}, |
| 356 | {name: "unicode escape", in: "\x01", want: `"\u0001"`}, |
| 357 | } |
| 358 | |
| 359 | for _, test := range tests { |
| 360 | t.Run(test.name, func(t *testing.T) { |
| 361 | escaped := Escape(test.in) |
| 362 | if got := string(escaped); got != test.want { |
| 363 | t.Fatalf("Escape(%q) = %q; want %q", test.in, got, test.want) |
| 364 | } |
| 365 | |
| 366 | unescaped, err := Unescape(escaped[1:len(escaped)-1], nil) |
| 367 | if err != nil { |
| 368 | t.Fatalf("Unescape(Escape(%q)) returned error: %v", test.in, err) |
| 369 | } |
| 370 | if got := string(unescaped); got != test.in { |
| 371 | t.Fatalf("Unescape(Escape(%q)) = %q; want %q", test.in, got, test.in) |
| 372 | } |
| 373 | }) |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | // Verifies: SYS-REQ-014 (escape handling) |
| 378 | // reqproof:proptest:skip targeted witness/regression test; not a property-test subject |