StructuredSwiftTestHelpers.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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("Structued Swift")
  20. struct StructuedSwiftTests {}
  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. enum RPCKind: Hashable, Sendable, CaseIterable {
  37. case unary
  38. case clientStreaming
  39. case serverStreaming
  40. case bidirectionalStreaming
  41. var streamsInput: Bool {
  42. switch self {
  43. case .clientStreaming, .bidirectionalStreaming:
  44. return true
  45. case .unary, .serverStreaming:
  46. return false
  47. }
  48. }
  49. var streamsOutput: Bool {
  50. switch self {
  51. case .serverStreaming, .bidirectionalStreaming:
  52. return true
  53. case .unary, .clientStreaming:
  54. return false
  55. }
  56. }
  57. }