TestDisplayString tests the DisplayString() method of ast.Constant. This method returns a string representation without escaping Unicode characters
(t *testing.T)
| 10 | // TestDisplayString tests the DisplayString() method of ast.Constant. |
| 11 | // This method returns a string representation without escaping Unicode characters |
| 12 | func TestDisplayString(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | constant ast.Constant |
| 16 | want string |
| 17 | }{ |
| 18 | { |
| 19 | name: "name constant", |
| 20 | constant: mustName("/foo"), |
| 21 | want: "/foo", |
| 22 | }, |
| 23 | { |
| 24 | name: "simple string constant", |
| 25 | constant: ast.String("hello"), |
| 26 | want: `"hello"`, |
| 27 | }, |
| 28 | { |
| 29 | name: "string with unicode characters", |
| 30 | constant: ast.String("hello世界"), |
| 31 | want: `"hello世界"`, |
| 32 | }, |
| 33 | { |
| 34 | name: "string with special characters", |
| 35 | constant: ast.String("hello\nworld\ttab"), |
| 36 | want: "\"hello\nworld\ttab\"", |
| 37 | }, |
| 38 | { |
| 39 | name: "string with quotes", |
| 40 | constant: ast.String(`say "hello"`), |
| 41 | want: `"say "hello""`, |
| 42 | }, |
| 43 | { |
| 44 | name: "bytes constant", |
| 45 | constant: ast.Bytes([]byte("hello")), |
| 46 | want: `b"hello"`, |
| 47 | }, |
| 48 | { |
| 49 | name: "bytes with unicode", |
| 50 | constant: ast.Bytes([]byte("hello世界")), |
| 51 | want: `b"hello世界"`, |
| 52 | }, |
| 53 | { |
| 54 | name: "number constant", |
| 55 | constant: ast.Number(42), |
| 56 | want: "42", |
| 57 | }, |
| 58 | { |
| 59 | name: "negative number constant", |
| 60 | constant: ast.Number(-123), |
| 61 | want: "-123", |
| 62 | }, |
| 63 | { |
| 64 | name: "float constant", |
| 65 | constant: ast.Float64(3.14159), |
| 66 | want: "3.14159", |
| 67 | }, |
| 68 | { |
| 69 | name: "negative float constant", |
nothing calls this directly
no test coverage detected