StructuredSwiftTestHelpers.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Testing
  17. @testable import GRPCCodeGen
  18. // Used as a namespace for organising other structured swift tests.
  19. @Suite("Structured Swift")
  20. struct StructuredSwiftTests {}
  21. @available(gRPCSwift 2.0, *)
  22. func render(_ declaration: Declaration) -> String {
  23. let renderer = TextBasedRenderer(indentation: 2)
  24. renderer.renderDeclaration(declaration)
  25. return renderer.renderedContents()
  26. }
  27. @available(gRPCSwift 2.0, *)
  28. func render(_ expression: Expression) -> String {
  29. let renderer = TextBasedRenderer(indentation: 2)
  30. renderer.renderExpression(expression)
  31. return renderer.renderedContents()
  32. }
  33. @available(gRPCSwift 2.0, *)
  34. func render(_ blocks: [CodeBlock]) -> String {
  35. let renderer = TextBasedRenderer(indentation: 2)
  36. renderer.renderCodeBlocks(blocks)
  37. return renderer.renderedContents()
  38. }
  39. @available(gRPCSwift 2.0, *)
  40. func render(_ imports: [ImportDescription]) -> String {
  41. let renderer = TextBasedRenderer(indentation: 2)
  42. renderer.renderImports(imports)
  43. return renderer.renderedContents()
  44. }
  45. enum RPCKind: Hashable, Sendable, CaseIterable {
  46. case unary
  47. case clientStreaming
  48. case serverStreaming
  49. case bidirectionalStreaming
  50. var streamsInput: Bool {
  51. switch self {
  52. case .clientStreaming, .bidirectionalStreaming:
  53. return true
  54. case .unary, .serverStreaming:
  55. return false
  56. }
  57. }
  58. var streamsOutput: Bool {
  59. switch self {
  60. case .serverStreaming, .bidirectionalStreaming:
  61. return true
  62. case .unary, .clientStreaming:
  63. return false
  64. }
  65. }
  66. }