| 10 | ) |
| 11 | |
| 12 | func TestBreadcrumbsToJSON(t *testing.T) { |
| 13 | const breadcrumbsJSON = `{"@context":"http://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@type":"Thing","@id":"/contents-jessie.html","name":"jessie"}},{"@type":"ListItem","position":2,"item":{"@type":"Thing","@id":"/jessie/i3-wm/index.html","name":"i3-wm"}},{"@type":"ListItem","position":3,"item":{"@type":"Thing","@id":"","name":"i3(1)"}}]}` |
| 14 | |
| 15 | const Suite = "jessie" |
| 16 | const Binarypkg = "i3-wm" |
| 17 | b := breadcrumbs{ |
| 18 | {fmt.Sprintf("/contents-%s.html", Suite), Suite}, |
| 19 | {fmt.Sprintf("/%s/%s/index.html", Suite, Binarypkg), Binarypkg}, |
| 20 | {"", "i3(1)"}, |
| 21 | } |
| 22 | if got, want := string(b.ToJSON()), breadcrumbsJSON; got != want { |
| 23 | fmt.Printf("%s\n", got) |
| 24 | t.Fatalf("unexpected breadcrumbs JSON: got %q, want %q", got, want) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | // Ensure that the JSON-LD breadcrumbs are emitted as a JSON object and |
| 29 | // not, due to html/template's contextual escaping inside <script>, as a |