docstring_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // +build codegen
  2. package api
  3. import (
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestNonHTMLDocGen(t *testing.T) {
  8. doc := "Testing 1 2 3"
  9. expected := "// Testing 1 2 3\n"
  10. doc = docstring(doc)
  11. assert.Equal(t, expected, doc)
  12. }
  13. func TestListsHTMLDocGen(t *testing.T) {
  14. doc := "<ul><li>Testing 1 2 3</li> <li>FooBar</li></ul>"
  15. expected := "// * Testing 1 2 3\n// * FooBar\n"
  16. doc = docstring(doc)
  17. assert.Equal(t, expected, doc)
  18. doc = "<ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>"
  19. expected = "// * Testing 1 2 3\n// * FooBar\n"
  20. doc = docstring(doc)
  21. assert.Equal(t, expected, doc)
  22. // Test leading spaces
  23. doc = " <ul> <li>Testing 1 2 3</li> <li>FooBar</li> </ul>"
  24. doc = docstring(doc)
  25. assert.Equal(t, expected, doc)
  26. // Paragraph check
  27. doc = "<ul> <li> <p>Testing 1 2 3</p> </li><li> <p>FooBar</p></li></ul>"
  28. expected = "// * Testing 1 2 3\n// \n// * FooBar\n"
  29. doc = docstring(doc)
  30. assert.Equal(t, expected, doc)
  31. }
  32. func TestInlineCodeHTMLDocGen(t *testing.T) {
  33. doc := "<ul> <li><code>Testing</code>: 1 2 3</li> <li>FooBar</li> </ul>"
  34. expected := "// * Testing: 1 2 3\n// * FooBar\n"
  35. doc = docstring(doc)
  36. assert.Equal(t, expected, doc)
  37. }
  38. func TestInlineCodeInParagraphHTMLDocGen(t *testing.T) {
  39. doc := "<p><code>Testing</code>: 1 2 3</p>"
  40. expected := "// Testing: 1 2 3\n"
  41. doc = docstring(doc)
  42. assert.Equal(t, expected, doc)
  43. }
  44. func TestEmptyPREInlineCodeHTMLDocGen(t *testing.T) {
  45. doc := "<pre><code>Testing</code></pre>"
  46. expected := "// Testing\n"
  47. doc = docstring(doc)
  48. assert.Equal(t, expected, doc)
  49. }
  50. func TestParagraph(t *testing.T) {
  51. doc := "<p>Testing 1 2 3</p>"
  52. expected := "// Testing 1 2 3\n"
  53. doc = docstring(doc)
  54. assert.Equal(t, expected, doc)
  55. }
  56. func TestComplexListParagraphCode(t *testing.T) {
  57. doc := "<ul> <li><p><code>FOO</code> Bar</p></li><li><p><code>Xyz</code> ABC</p></li></ul>"
  58. expected := "// * FOO Bar\n// \n// * Xyz ABC\n"
  59. doc = docstring(doc)
  60. assert.Equal(t, expected, doc)
  61. }