Sha256: 85212346b5430db7d1c3e0dfc1e5fd89372755f42a76ae172e55f460f513f19f

Contents?: true

Size: 1.43 KB

Versions: 51

Compression:

Stored size: 1.43 KB

Contents

module Cucumber
  module Ast
    # Represents an inline argument in a step. Example:
    #
    #   Given the message
    #     """
    #     I like
    #     Cucumber sandwich
    #     """
    #
    # The text between the pair of <tt>"""</tt> is stored inside a PyString,
    # which is yielded to the StepDefinition block as the last argument.
    #
    # The StepDefinition can then access the String via the #to_s method. In the
    # example above, that would return: <tt>"I like\nCucumber sandwich"</tt>
    #
    # Note how the indentation from the source is stripped away.
    #
    class PyString

      def self.default_arg_name
        "string"
      end

      def initialize(start_line, end_line, string, quotes_indent)
        @start_line, @end_line = start_line, end_line
        @string, @quotes_indent = string.gsub(/\\"/, '"'), quotes_indent
      end

      def to_s
        @string.indent(-@quotes_indent)
      end

      def accept(visitor)
        visitor.visit_py_string(to_s)
      end
      
      def arguments_replaced(arguments) #:nodoc:
        string = @string
        arguments.each do |name, value|
          value ||= ''
          string = string.gsub(name, value)
        end
        PyString.new(@start_line, @end_line, string, @quotes_indent)
      end

      def has_text?(text)
        @string.index(text)
      end

      # For testing only
      def to_sexp #:nodoc:
        [:py_string, to_s]
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 6 rubygems

Version Path
aslakhellesoy-cucumber-0.3.7.2 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.3.7.3 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.3.7.4 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.3.7.5 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.3.7 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.3.8 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.3.9.1 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.3.9.2 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.3.9.3 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.3.9.4 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.3.9.5 lib/cucumber/ast/py_string.rb
aslakhellesoy-cucumber-0.3.9 lib/cucumber/ast/py_string.rb
jwilger-cucumber-0.3.11.200906161550 lib/cucumber/ast/py_string.rb
jwilger-cucumber-0.3.11.200907091518 lib/cucumber/ast/py_string.rb
kosmas58-cucumber-0.3.11.3 lib/cucumber/ast/py_string.rb
kosmas58-cucumber-0.3.11.6 lib/cucumber/ast/py_string.rb
kosmas58-cucumber-0.3.9.4 lib/cucumber/ast/py_string.rb
square-cucumber-0.3.12.2 lib/cucumber/ast/py_string.rb
squirrel-cucumber-0.3.12.1 lib/cucumber/ast/py_string.rb
squirrel-cucumber-0.3.12 lib/cucumber/ast/py_string.rb