MCPcopy
hub / github.com/google/mangle / TestDisplayString

Function TestDisplayString

interpreter/interpreter_test.go:12–146  ·  view source on GitHub ↗

TestDisplayString tests the DisplayString() method of ast.Constant. This method returns a string representation without escaping Unicode characters

(t *testing.T)

Source from the content-addressed store, hash-verified

10// TestDisplayString tests the DisplayString() method of ast.Constant.
11// This method returns a string representation without escaping Unicode characters
12func 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",

Callers

nothing calls this directly

Calls 10

StringFunction · 0.92
BytesFunction · 0.92
NumberFunction · 0.92
Float64Function · 0.92
ListFunction · 0.92
mustNameFunction · 0.85
makePairFunction · 0.85
makeMapFunction · 0.85
makeStructFunction · 0.85
DisplayStringMethod · 0.45

Tested by

no test coverage detected