Contents

Pretty-print with source location

Kernel#qql works just like Kernel#pp from the built-in pp library, except that it writes to $stderr and it labels the output with the source location.

If the filename is long, then the source location is printed on a line of its own.

Scenario: One argument

  • Given a file named "example.rb" with:
    ruby
    require "cute_print"
    a = [
      "Once upon a time there were four little Rabbits, ",
      "and their names were",
      "Flopsy,",
      "Mopsy,",
      "Cotton-tail, and",
      "Peter.",
    ]
    qql a
  • Then stderr should be
    example.rb:10: ["Once upon a time there were four little Rabbits, ",
                    "and their names were",
                    "Flopsy,",
                    "Mopsy,",
                    "Cotton-tail, and",
                    "Peter."]
    

Scenario: Two arguments

  • Given a file named "example.rb" with:
    ruby
    require "cute_print"
    qql 1, "foo"
  • Then stderr should be
    example.rb:2: 1
    example.rb:2: "foo"
    

Scenario: Very long label

  • Given a file named "long____________________________filename.rb" with:
    ruby
    require "cute_print"
    a = [
      "Once upon a time there were four little Rabbits, ",
      "and their names were",
      "Flopsy,",
      "Mopsy,",
      "Cotton-tail, and",
      "Peter.",
    ]
    qql a
  • Then stderr should be
    long____________________________filename.rb:10:
      ["Once upon a time there were four little Rabbits, ",
       "and their names were",
       "Flopsy,",
       "Mopsy,",
       "Cotton-tail, and",
       "Peter."]
    

Source: features/pretty_print/pretty_print_with_location.feature at commit e8ebd2a4, Cute Print (MIT license).