Skip to content

Instantly share code, notes, and snippets.

@goodside
Created November 19, 2010 03:27
Show Gist options
  • Save goodside/706088 to your computer and use it in GitHub Desktop.
Save goodside/706088 to your computer and use it in GitHub Desktop.
Apologetic comment example
1 #! /usr/bin/env ruby
2
3 $:.unshift(File.dirname(__FILE__) + '/../lib') unless
4 $:.include?(File.dirname(__FILE__) + '/../lib')
5
6 require 'parser'
7 require 'test/unit'
8
9
10 class ParserTest < Test::Unit::TestCase
11 def reformat_script(args, input)
12 # We have to escape backslashes and single quotes to get bash to
13 # pass our string to the script intact. Yes, there's three layers of
14 # escaping going on here. In a script that tests escaping. Sorry.
15 input.gsub!(/([\\'])/, '\\\\\\1')
16 `echo '#{input}' | python lib/reformat.py #{args}`
17 end
18
19 def test_reformat_script
20 assert_equal %q<\\\\test,\\\\test> + "\n",
21 reformat_script('5s5s', %q<\\test\\test>)
22
23 assert_equal "qwert,yuiop,asdfghjkl,zxcvbnm,1234567890\n",
24 reformat_script('5s5s9s7s10s', 'qwertyuiopasdfghjklzxcvbnm1234567890')
25
26 assert_equal(
27 "he,llo,54R,-,94,-549,11,1994,extra\n",
28 reformat_script('2s3s3z1m2y extra', 'hello54R-94')
29 )
30 assert_equal(
31 "6,06,{,40R,5,05,xxx,03,6,2006,0,-409,5,2005,2003\n",
32 reformat_script('1m2y1z3z1m2y3s2y', '606{40R505xxx03')
33 )
34 assert_equal(
35 %q<\"\,\,\",6,06,{,40R,5,05,6,2006,0,-409,5,2005> + "\n",
36 reformat_script('4s1m2y1z3z1m2y', %q<",,"606{40R505>)
37 )
38 end
39 end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment