You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

multiline_argument.rb 1.4 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # frozen_string_literal: true
  2. require 'delegate'
  3. require 'cucumber/multiline_argument/data_table'
  4. require 'cucumber/multiline_argument/doc_string'
  5. module Cucumber
  6. module MultilineArgument
  7. class << self
  8. def from_core(node)
  9. builder.wrap(node)
  10. end
  11. def from(argument, location = nil, content_type = nil)
  12. location ||= Core::Test::Location.of_caller
  13. case argument
  14. when String
  15. builder.doc_string(Core::Test::DocString.new(argument, content_type))
  16. when Array
  17. location = location.on_line(argument.first.line..argument.last.line)
  18. builder.data_table(argument.map(&:cells), location)
  19. when DataTable, DocString, None
  20. argument
  21. when nil
  22. None.new
  23. else
  24. raise ArgumentError, "Don't know how to convert #{argument.class} #{argument.inspect} into a MultilineArgument"
  25. end
  26. end
  27. private
  28. def builder
  29. @builder ||= Builder.new
  30. end
  31. class Builder
  32. def wrap(node)
  33. @result = None.new
  34. node.describe_to(self)
  35. @result
  36. end
  37. def doc_string(node, *_args)
  38. @result = DocString.new(node)
  39. end
  40. def data_table(node, *_args)
  41. @result = DataTable.new(node)
  42. end
  43. end
  44. end
  45. class None
  46. def append_to(array); end
  47. def describe_to(visitor); end
  48. end
  49. end
  50. end

No Description

Contributors (1)