DocsTests.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2024, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import GRPCCodeGen
  17. import Testing
  18. @Suite("Docs tests")
  19. struct DocsTests {
  20. @Test("Suffix with additional docs")
  21. func suffixWithAdditional() {
  22. let foo = """
  23. /// Foo
  24. """
  25. let additional = """
  26. /// Some additional pre-formatted docs
  27. /// split over multiple lines.
  28. """
  29. let expected = """
  30. /// Foo
  31. ///
  32. /// > Source IDL Documentation:
  33. /// >
  34. /// > Some additional pre-formatted docs
  35. /// > split over multiple lines.
  36. """
  37. #expect(Docs.suffix(foo, withDocs: additional) == expected)
  38. }
  39. @Test("Suffix with empty additional docs")
  40. func suffixWithEmptyAdditional() {
  41. let foo = """
  42. /// Foo
  43. """
  44. let additional = ""
  45. #expect(Docs.suffix(foo, withDocs: additional) == foo)
  46. }
  47. @Test("Interpose additional docs")
  48. func interposeDocs() {
  49. let header = """
  50. /// Header
  51. """
  52. let footer = """
  53. /// Footer
  54. """
  55. let additionalDocs = """
  56. /// Additional docs
  57. /// On multiple lines
  58. """
  59. let expected = """
  60. /// Header
  61. ///
  62. /// > Source IDL Documentation:
  63. /// >
  64. /// > Additional docs
  65. /// > On multiple lines
  66. ///
  67. /// Footer
  68. """
  69. #expect(Docs.interposeDocs(additionalDocs, between: header, and: footer) == expected)
  70. }
  71. @Test("Interpose empty additional docs")
  72. func interposeEmpty() {
  73. let header = """
  74. /// Header
  75. """
  76. let footer = """
  77. /// Footer
  78. """
  79. let expected = """
  80. /// Header
  81. ///
  82. /// Footer
  83. """
  84. #expect(Docs.interposeDocs("", between: header, and: footer) == expected)
  85. }
  86. }