docstring_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // +build 1.6,codegen
  2. package api
  3. import (
  4. "testing"
  5. )
  6. func TestNonHTMLDocGen(t *testing.T) {
  7. doc := "Testing 1 2 3"
  8. expected := "// Testing 1 2 3\n"
  9. doc = docstring(doc)
  10. if expected != doc {
  11. t.Errorf("Expected %s, but received %s", expected, doc)
  12. }
  13. }
  14. func TestListsHTMLDocGen(t *testing.T) {
  15. doc := "<ul><li>Testing 1 2 3</li> <li>FooBar</li></ul>"
  16. expected := "// * Testing 1 2 3\n// * FooBar\n"
  17. doc = docstring(doc)
  18. if expected != doc {
  19. t.Errorf("Expected %s, but received %s", expected, doc)
  20. }
  21. doc = "<ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>"
  22. expected = "// * Testing 1 2 3\n// * FooBar\n"
  23. doc = docstring(doc)
  24. if expected != doc {
  25. t.Errorf("Expected %s, but received %s", expected, doc)
  26. }
  27. // Test leading spaces
  28. doc = " <ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>"
  29. doc = docstring(doc)
  30. if expected != doc {
  31. t.Errorf("Expected %s, but received %s", expected, doc)
  32. }
  33. // Paragraph check
  34. doc = "<ul> <li> <p>Testing 1 2 3</p> </li><li> <p>FooBar</p></li></ul>"
  35. expected = "// * Testing 1 2 3\n// \n// * FooBar\n"
  36. doc = docstring(doc)
  37. if expected != doc {
  38. t.Errorf("Expected %s, but received %s", expected, doc)
  39. }
  40. }
  41. func TestInlineCodeHTMLDocGen(t *testing.T) {
  42. doc := "<ul> <li><code>Testing</code>: 1 2 3</li> <li>FooBar</li> </ul>"
  43. expected := "// * Testing: 1 2 3\n// * FooBar\n"
  44. doc = docstring(doc)
  45. if expected != doc {
  46. t.Errorf("Expected %s, but received %s", expected, doc)
  47. }
  48. }
  49. func TestInlineCodeInParagraphHTMLDocGen(t *testing.T) {
  50. doc := "<p><code>Testing</code>: 1 2 3</p>"
  51. expected := "// Testing: 1 2 3\n"
  52. doc = docstring(doc)
  53. if expected != doc {
  54. t.Errorf("Expected %s, but received %s", expected, doc)
  55. }
  56. }
  57. func TestEmptyPREInlineCodeHTMLDocGen(t *testing.T) {
  58. doc := "<pre><code>Testing</code></pre>"
  59. expected := "// Testing\n"
  60. doc = docstring(doc)
  61. if expected != doc {
  62. t.Errorf("Expected %s, but received %s", expected, doc)
  63. }
  64. }
  65. func TestParagraph(t *testing.T) {
  66. doc := "<p>Testing 1 2 3</p>"
  67. expected := "// Testing 1 2 3\n"
  68. doc = docstring(doc)
  69. if expected != doc {
  70. t.Errorf("Expected %s, but received %s", expected, doc)
  71. }
  72. }
  73. func TestComplexListParagraphCode(t *testing.T) {
  74. doc := "<ul> <li><p><code>FOO</code> Bar</p></li><li><p><code>Xyz</code> ABC</p></li></ul>"
  75. expected := "// * FOO Bar\n// \n// * Xyz ABC\n"
  76. doc = docstring(doc)
  77. if expected != doc {
  78. t.Errorf("Expected %s, but received %s", expected, doc)
  79. }
  80. }