2
0

StructuredSwiftTestHelpers.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. func render(_ declaration: Declaration) -> String {
  22. let renderer = TextBasedRenderer(indentation: 2)
  23. renderer.renderDeclaration(declaration)
  24. return renderer.renderedContents()
  25. }
  26. func render(_ expression: Expression) -> String {
  27. let renderer = TextBasedRenderer(indentation: 2)
  28. renderer.renderExpression(expression)
  29. return renderer.renderedContents()
  30. }
  31. func render(_ blocks: [CodeBlock]) -> String {
  32. let renderer = TextBasedRenderer(indentation: 2)
  33. renderer.renderCodeBlocks(blocks)
  34. return renderer.renderedContents()
  35. }
  36. func render(_ imports: [ImportDescription]) -> String {
  37. let renderer = TextBasedRenderer(indentation: 2)
  38. renderer.renderImports(imports)
  39. return renderer.renderedContents()
  40. }
  41. enum RPCKind: Hashable, Sendable, CaseIterable {
  42. case unary
  43. case clientStreaming
  44. case serverStreaming
  45. case bidirectionalStreaming
  46. var streamsInput: Bool {
  47. switch self {
  48. case .clientStreaming, .bidirectionalStreaming:
  49. return true
  50. case .unary, .serverStreaming:
  51. return false
  52. }
  53. }
  54. var streamsOutput: Bool {
  55. switch self {
  56. case .serverStreaming, .bidirectionalStreaming:
  57. return true
  58. case .unary, .clientStreaming:
  59. return false
  60. }
  61. }
  62. }