You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.5 KiB

  1. // Copyright 2012 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package present
  5. import "testing"
  6. func TestInlineParsing(t *testing.T) {
  7. var tests = []struct {
  8. in string
  9. link string
  10. text string
  11. length int
  12. }{
  13. {"[[http://golang.org]]", "http://golang.org", "golang.org", 21},
  14. {"[[http://golang.org][]]", "http://golang.org", "http://golang.org", 23},
  15. {"[[http://golang.org]] this is ignored", "http://golang.org", "golang.org", 21},
  16. {"[[http://golang.org][link]]", "http://golang.org", "link", 27},
  17. {"[[http://golang.org][two words]]", "http://golang.org", "two words", 32},
  18. {"[[http://golang.org][*link*]]", "http://golang.org", "<b>link</b>", 29},
  19. {"[[http://bad[url]]", "", "", 0},
  20. {"[[http://golang.org][a [[link]] ]]", "http://golang.org", "a [[link", 31},
  21. {"[[http:// *spaces* .com]]", "", "", 0},
  22. {"[[http://bad`char.com]]", "", "", 0},
  23. {" [[http://google.com]]", "", "", 0},
  24. {"[[mailto:gopher@golang.org][Gopher]]", "mailto:gopher@golang.org", "Gopher", 36},
  25. {"[[mailto:gopher@golang.org]]", "mailto:gopher@golang.org", "gopher@golang.org", 28},
  26. }
  27. for i, test := range tests {
  28. link, length := parseInlineLink(test.in)
  29. if length == 0 && test.length == 0 {
  30. continue
  31. }
  32. if a := renderLink(test.link, test.text); length != test.length || link != a {
  33. t.Errorf("#%d: parseInlineLink(%q):\ngot\t%q, %d\nwant\t%q, %d", i, test.in, link, length, a, test.length)
  34. }
  35. }
  36. }