(t *testing.T)
| 7 | ) |
| 8 | |
| 9 | func TestBuildRequests(t *testing.T) { |
| 10 | requests, err := BuildRequests(Options{ |
| 11 | FontFamily: "Georgia", |
| 12 | FontSize: 14, |
| 13 | TextColor: "#3366cc", |
| 14 | Background: "#fff", |
| 15 | ClearBold: true, |
| 16 | Italic: true, |
| 17 | Alignment: "center", |
| 18 | LineSpacing: 150, |
| 19 | HeadingLevel: intPointer(2), |
| 20 | }, 3, 9, "t.second") |
| 21 | if err != nil { |
| 22 | t.Fatalf("BuildRequests: %v", err) |
| 23 | } |
| 24 | |
| 25 | if len(requests) != 2 { |
| 26 | t.Fatalf("requests = %d, want 2", len(requests)) |
| 27 | } |
| 28 | |
| 29 | text := requests[0].UpdateTextStyle |
| 30 | if text == nil || text.Fields != "weightedFontFamily,fontSize,foregroundColor,backgroundColor,bold,italic" { |
| 31 | t.Fatalf("unexpected text request: %#v", requests[0]) |
| 32 | } |
| 33 | |
| 34 | encoded, err := json.Marshal(text.TextStyle) |
| 35 | if err != nil { |
| 36 | t.Fatalf("marshal text style: %v", err) |
| 37 | } |
| 38 | |
| 39 | if !strings.Contains(string(encoded), `"bold":false`) { |
| 40 | t.Fatalf("clearing bold must force-send false: %s", encoded) |
| 41 | } |
| 42 | |
| 43 | paragraph := requests[1].UpdateParagraphStyle |
| 44 | if paragraph == nil || paragraph.ParagraphStyle.Alignment != "CENTER" || |
| 45 | paragraph.ParagraphStyle.LineSpacing != 150 || |
| 46 | paragraph.ParagraphStyle.NamedStyleType != "HEADING_2" { |
| 47 | t.Fatalf("unexpected paragraph request: %#v", requests[1]) |
| 48 | } |
| 49 | |
| 50 | if paragraph.Range.TabId != "t.second" { |
| 51 | t.Fatalf("tab id = %q, want t.second", paragraph.Range.TabId) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | func TestBuildRequestsValidation(t *testing.T) { |
| 56 | tests := []Options{ |
nothing calls this directly
no test coverage detected