DocsTests.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. @available(gRPCSwift 2.0, *)
  22. func suffixWithAdditional() {
  23. let foo = """
  24. /// Foo
  25. """
  26. let additional = """
  27. /// Some additional pre-formatted docs
  28. /// split over multiple lines.
  29. """
  30. let expected = """
  31. /// Foo
  32. ///
  33. /// > Source IDL Documentation:
  34. /// >
  35. /// > Some additional pre-formatted docs
  36. /// > split over multiple lines.
  37. """
  38. #expect(Docs.suffix(foo, withDocs: additional) == expected)
  39. }
  40. @Test("Suffix with empty additional docs")
  41. @available(gRPCSwift 2.0, *)
  42. func suffixWithEmptyAdditional() {
  43. let foo = """
  44. /// Foo
  45. """
  46. let additional = ""
  47. #expect(Docs.suffix(foo, withDocs: additional) == foo)
  48. }
  49. @Test("Interpose additional docs")
  50. @available(gRPCSwift 2.0, *)
  51. func interposeDocs() {
  52. let header = """
  53. /// Header
  54. """
  55. let footer = """
  56. /// Footer
  57. """
  58. let additionalDocs = """
  59. /// Additional docs
  60. /// On multiple lines
  61. """
  62. let expected = """
  63. /// Header
  64. ///
  65. /// > Source IDL Documentation:
  66. /// >
  67. /// > Additional docs
  68. /// > On multiple lines
  69. ///
  70. /// Footer
  71. """
  72. #expect(Docs.interposeDocs(additionalDocs, between: header, and: footer) == expected)
  73. }
  74. @Test("Interpose empty additional docs")
  75. @available(gRPCSwift 2.0, *)
  76. func interposeEmpty() {
  77. let header = """
  78. /// Header
  79. """
  80. let footer = """
  81. /// Footer
  82. """
  83. let expected = """
  84. /// Header
  85. ///
  86. /// Footer
  87. """
  88. #expect(Docs.interposeDocs("", between: header, and: footer) == expected)
  89. }
  90. }