-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathemphasis_test.go
More file actions
112 lines (104 loc) · 3.19 KB
/
Copy pathemphasis_test.go
File metadata and controls
112 lines (104 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package menuet
import (
"encoding/json"
"strings"
"testing"
)
func TestUnderlineRunSerializes(t *testing.T) {
r := TextRun{Text: "winner", Underline: true}
b, _ := json.Marshal(r)
if !strings.Contains(string(b), `"Underline":true`) {
t.Errorf("Underline missing: %s", b)
}
}
func TestStrikethroughRunSerializes(t *testing.T) {
r := TextRun{Text: "eliminated", Strikethrough: true}
b, _ := json.Marshal(r)
if !strings.Contains(string(b), `"Strikethrough":true`) {
t.Errorf("Strikethrough missing: %s", b)
}
}
func TestBackgroundRunSerializes(t *testing.T) {
r := TextRun{Text: "highlight", Background: Yellow}
b, _ := json.Marshal(r)
got := string(b)
// Background is its own Color key in the JSON, not Color.
if !strings.Contains(got, `"Background":{`) {
t.Errorf("Background missing: %s", got)
}
if !strings.Contains(got, `"R":200`) {
t.Errorf("Background RGBA missing: %s", got)
}
}
func TestShadowRunSerializes(t *testing.T) {
r := TextRun{
Text: "trophy",
Shadow: &Shadow{
Color: Yellow,
Blur: 8,
},
}
b, _ := json.Marshal(r)
got := string(b)
if !strings.Contains(got, `"Shadow":{`) {
t.Errorf("Shadow missing: %s", got)
}
if !strings.Contains(got, `"Blur":8`) {
t.Errorf("Blur missing: %s", got)
}
if !strings.Contains(got, `"Semantic":"systemYellowColor"`) && !strings.Contains(got, `"R":200,"G":160`) {
t.Errorf("Shadow Color missing: %s", got)
}
}
func TestUnderlineColorIndependent(t *testing.T) {
// Spell-checker style: gray text, red underline.
r := TextRun{
Text: "misspelled",
Color: Gray,
Underline: true,
UnderlineColor: SystemRed,
}
b, _ := json.Marshal(r)
got := string(b)
if !strings.Contains(got, `"Underline":true`) {
t.Errorf("Underline missing: %s", got)
}
// UnderlineColor must serialize as its own Color object (not merged
// with the run's foreground) so the ObjC bridge sees it separately.
if !strings.Contains(got, `"UnderlineColor":`) ||
!strings.Contains(got, `"Semantic":"systemRedColor"`) {
t.Errorf("UnderlineColor missing or wrong shape: %s", got)
}
}
func TestStrikethroughColorIndependent(t *testing.T) {
r := TextRun{
Text: "outdated",
Color: LabelSecondary,
Strikethrough: true,
StrikethroughColor: SystemRed,
}
b, _ := json.Marshal(r)
got := string(b)
if !strings.Contains(got, `"Strikethrough":true`) {
t.Errorf("Strikethrough missing: %s", got)
}
if !strings.Contains(got, `"StrikethroughColor":`) ||
!strings.Contains(got, `"Semantic":"systemRedColor"`) {
t.Errorf("StrikethroughColor missing or wrong shape: %s", got)
}
}
func TestPlainRunOmitsEmphasisFields(t *testing.T) {
// Without using the omitempty pattern in this PR (kept additive for
// schema stability), a plain run still serializes its boolean zeros.
// What matters is the deserialized side ignores them — verify a plain
// run round-trips with no emphasis flags set.
r := TextRun{Text: "hi"}
b, _ := json.Marshal(r)
var got TextRun
if err := json.Unmarshal(b, &got); err != nil {
t.Fatalf("unmarshal: %v", err)
}
if got.Underline || got.Strikethrough || got.Shadow != nil || !got.Background.IsZero() {
t.Errorf("plain run should have no emphasis fields set, got %+v", got)
}
}