@@ -3,6 +3,8 @@ package cmd
33import (
44 "strings"
55 "testing"
6+
7+ "google.golang.org/api/docs/v1"
68)
79
810func TestMarkdownToDocsRequests_BaseIndex (t * testing.T ) {
@@ -75,6 +77,103 @@ func TestMarkdownToDocsRequests_Strikethrough(t *testing.T) {
7577 }
7678}
7779
80+ func TestMarkdownToDocsRequests_NestedLists (t * testing.T ) {
81+ elements := ParseMarkdown ("- Parent\n - **Child**\n - Grandchild\n \n 1. One\n 1. Nested one" )
82+ requests , text , tables := MarkdownToDocsRequests (elements , 10 , "t.second" )
83+
84+ wantText := "Parent\n \t Child\n \t \t Grandchild\n \n One\n \t Nested one\n "
85+ if text != wantText {
86+ t .Fatalf ("text = %q, want %q" , text , wantText )
87+ }
88+ if len (tables ) != 0 {
89+ t .Fatalf ("unexpected tables: %d" , len (tables ))
90+ }
91+
92+ wantBullets := []struct {
93+ start int64
94+ end int64
95+ preset string
96+ }{
97+ {10 , 37 , bulletPresetDisc },
98+ {35 , 51 , bulletPresetNumbered },
99+ }
100+ var gotBullets []struct {
101+ start int64
102+ end int64
103+ preset string
104+ }
105+ var boldRange * docs.Range
106+ for _ , req := range requests {
107+ if req .CreateParagraphBullets != nil {
108+ got := req .CreateParagraphBullets
109+ gotBullets = append (gotBullets , struct {
110+ start int64
111+ end int64
112+ preset string
113+ }{got .Range .StartIndex , got .Range .EndIndex , got .BulletPreset })
114+ }
115+ if req .UpdateTextStyle != nil && req .UpdateTextStyle .TextStyle != nil && req .UpdateTextStyle .TextStyle .Bold {
116+ boldRange = req .UpdateTextStyle .Range
117+ }
118+ }
119+ if len (gotBullets ) != len (wantBullets ) {
120+ t .Fatalf ("bullet requests = %#v, want %#v" , gotBullets , wantBullets )
121+ }
122+ for i , want := range wantBullets {
123+ if got := gotBullets [i ]; got != want {
124+ t .Fatalf ("bullet %d = %#v, want %#v" , i , got , want )
125+ }
126+ }
127+ if boldRange == nil || boldRange .StartIndex != 17 || boldRange .EndIndex != 22 || boldRange .TabId != "t.second" {
128+ t .Fatalf ("unexpected bold range after nested bullet tab removal: %#v" , boldRange )
129+ }
130+ }
131+
132+ func TestMarkdownToDocsRequests_MixedListChildrenStayNested (t * testing.T ) {
133+ elements := ParseMarkdown ("1. Parent\n - Bullet child\n 1. Number child\n 2. Sibling" )
134+ requests , text , tables := MarkdownToDocsRequests (elements , 1 , "t.second" )
135+
136+ wantText := "Parent\n \t Bullet child\n \t Number child\n Sibling\n "
137+ if text != wantText {
138+ t .Fatalf ("text = %q, want %q" , text , wantText )
139+ }
140+ if len (tables ) != 0 {
141+ t .Fatalf ("unexpected tables: %d" , len (tables ))
142+ }
143+
144+ wantBullets := []struct {
145+ start int64
146+ end int64
147+ preset string
148+ }{
149+ {1 , 44 , bulletPresetNumbered },
150+ {8 , 21 , bulletPresetDisc },
151+ }
152+ var gotBullets []struct {
153+ start int64
154+ end int64
155+ preset string
156+ }
157+ for _ , req := range requests {
158+ if req .CreateParagraphBullets != nil {
159+ got := req .CreateParagraphBullets
160+ gotBullets = append (gotBullets , struct {
161+ start int64
162+ end int64
163+ preset string
164+ }{got .Range .StartIndex , got .Range .EndIndex , got .BulletPreset })
165+ }
166+ }
167+ if len (gotBullets ) != len (wantBullets ) {
168+ t .Fatalf ("bullet requests = %#v, want %#v" , gotBullets , wantBullets )
169+ }
170+ for i , want := range wantBullets {
171+ if got := gotBullets [i ]; got != want {
172+ t .Fatalf ("bullet %d = %#v, want %#v" , i , got , want )
173+ }
174+ }
175+ }
176+
78177// TestMarkdownToDocsRequests_AppendBulletsAndCode is a regression test for
79178// #594. The append path used to inline literal "• " glyphs for bullet lists
80179// (leaving paragraphs as NORMAL_TEXT) and split fenced code blocks into one
@@ -126,8 +225,7 @@ func TestMarkdownToDocsRequests_AppendBulletsAndCode(t *testing.T) {
126225 }
127226
128227 // We expect at least:
129- // - 2 CreateParagraphBullets requests for the two bullet items
130- // (NB: they may be one per item; we count >= 2)
228+ // - 1 CreateParagraphBullets request for the contiguous bullet block
131229 // - 1 CreateParagraphBullets for the numbered item
132230 // - 1 UpdateParagraphStyle with paragraph-level shading covering the
133231 // code block
@@ -165,8 +263,8 @@ func TestMarkdownToDocsRequests_AppendBulletsAndCode(t *testing.T) {
165263 }
166264 }
167265
168- if bulletDisc < 2 {
169- t .Errorf ("expected at least 2 BULLET_DISC_CIRCLE_SQUARE CreateParagraphBullets, got %d" , bulletDisc )
266+ if bulletDisc < 1 {
267+ t .Errorf ("expected at least 1 BULLET_DISC_CIRCLE_SQUARE CreateParagraphBullets, got %d" , bulletDisc )
170268 }
171269 if bulletNumbered < 1 {
172270 t .Errorf ("expected at least 1 %s CreateParagraphBullets, got %d" , bulletPresetNumbered , bulletNumbered )
0 commit comments