aslakhellesoy-bcat 0.6.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,68 @@
1
+ require "test/unit"
2
+
3
+ # Test::Unit loads a default test if the suite is empty, whose purpose is to
4
+ # fail. Since having empty contexts is a common practice, we decided to
5
+ # overwrite TestSuite#empty? in order to allow them. Having a failure when no
6
+ # tests have been defined seems counter-intuitive.
7
+ class Test::Unit::TestSuite
8
+ def empty?
9
+ false
10
+ end
11
+ end
12
+
13
+ # Contest adds +teardown+, +test+ and +context+ as class methods, and the
14
+ # instance methods +setup+ and +teardown+ now iterate on the corresponding
15
+ # blocks. Note that all setup and teardown blocks must be defined with the
16
+ # block syntax. Adding setup or teardown instance methods defeats the purpose
17
+ # of this library.
18
+ class Test::Unit::TestCase
19
+ def self.setup(&block)
20
+ define_method :setup do
21
+ super(&block)
22
+ instance_eval(&block)
23
+ end
24
+ end
25
+
26
+ def self.teardown(&block)
27
+ define_method :teardown do
28
+ instance_eval(&block)
29
+ super(&block)
30
+ end
31
+ end
32
+
33
+ def self.context(name, &block)
34
+ subclass = Class.new(self)
35
+ remove_tests(subclass)
36
+ subclass.class_eval(&block) if block_given?
37
+ const_set(context_name(name), subclass)
38
+ end
39
+
40
+ def self.test(name, &block)
41
+ define_method(test_name(name), &block)
42
+ end
43
+
44
+ class << self
45
+ alias_method :should, :test
46
+ alias_method :describe, :context
47
+ end
48
+
49
+ private
50
+
51
+ def self.context_name(name)
52
+ "Test#{sanitize_name(name).gsub(/(^| )(\w)/) { $2.upcase }}".to_sym
53
+ end
54
+
55
+ def self.test_name(name)
56
+ "test_#{sanitize_name(name).gsub(/\s+/,'_')}".to_sym
57
+ end
58
+
59
+ def self.sanitize_name(name)
60
+ name.gsub(/\W+/, ' ').strip
61
+ end
62
+
63
+ def self.remove_tests(subclass)
64
+ subclass.public_instance_methods.grep(/^test_/).each do |meth|
65
+ subclass.send(:undef_method, meth.to_sym)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,19 @@
1
+ require 'contest'
2
+
3
+ ENV['PATH'] = [File.expand_path('../../bin'), ENV['PATH']].join(':')
4
+
5
+ class ANSI2HTMLCommandTest < Test::Unit::TestCase
6
+ test "piping stuff through a2h" do
7
+ IO.popen("a2h", 'w+') do |io|
8
+ io.sync = true
9
+ io.puts "hello there"
10
+ io.flush
11
+ assert_equal "hello there\n", io.read("hello there\n".size)
12
+ io.puts "and \x1b[1mhere's some bold"
13
+ assert_equal "and <b>here's some bold\n", io.read(24)
14
+ io.close_write
15
+ assert_equal "</b>", io.read(4)
16
+ io.close
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,121 @@
1
+ require 'contest'
2
+ require 'bcat/ansi'
3
+
4
+ class ANSITest < Test::Unit::TestCase
5
+ test 'should not modify input string' do
6
+ text = "some text"
7
+ Bcat::ANSI.new(text).to_html
8
+ assert_equal "some text", text
9
+ end
10
+
11
+ test 'passing through text with no escapes' do
12
+ text = "hello\nthis is bcat\n"
13
+ ansi = Bcat::ANSI.new(text)
14
+ assert_equal text, ansi.to_html
15
+ end
16
+
17
+ test "removing backspace characters" do
18
+ text = "like this"
19
+ ansi = Bcat::ANSI.new(text)
20
+ assert_equal "like this", ansi.to_html
21
+ end
22
+
23
+ test "foreground colors" do
24
+ text = "colors: \x1b[30mblack\x1b[37mwhite"
25
+ expect = "colors: " +
26
+ "<span style='color:#000'>black" +
27
+ "<span style='color:#AAA'>white" +
28
+ "</span></span>"
29
+ assert_equal expect, Bcat::ANSI.new(text).to_html
30
+ end
31
+
32
+ test "light foreground colors" do
33
+ text = "colors: \x1b[90mblack\x1b[97mwhite"
34
+ expect = "colors: " +
35
+ "<span style='color:#555'>black" +
36
+ "<span style='color:#FFF'>white" +
37
+ "</span></span>"
38
+ assert_equal expect, Bcat::ANSI.new(text).to_html
39
+ end
40
+
41
+ test "background colors" do
42
+ text = "colors: \x1b[40mblack\x1b[47mwhite"
43
+ expect = "colors: " +
44
+ "<span style='background-color:#000'>black" +
45
+ "<span style='background-color:#AAA'>white" +
46
+ "</span></span>"
47
+ assert_equal expect, Bcat::ANSI.new(text).to_html
48
+ end
49
+
50
+ test "light background colors" do
51
+ text = "colors: \x1b[100mblack\x1b[107mwhite"
52
+ expect = "colors: " +
53
+ "<span style='background-color:#555'>black" +
54
+ "<span style='background-color:#FFF'>white" +
55
+ "</span></span>"
56
+ assert_equal expect, Bcat::ANSI.new(text).to_html
57
+ end
58
+
59
+ test "strikethrough" do
60
+ text = "strike: \x1b[9mthat"
61
+ expect = "strike: <strike>that</strike>"
62
+ assert_equal expect, Bcat::ANSI.new(text).to_html
63
+ end
64
+
65
+ test "blink!" do
66
+ text = "blink: \x1b[5mwhat"
67
+ expect = "blink: <blink>what</blink>"
68
+ assert_equal expect, Bcat::ANSI.new(text).to_html
69
+ end
70
+
71
+ test "underline" do
72
+ text = "underline: \x1b[3mstuff"
73
+ expect = "underline: <u>stuff</u>"
74
+ assert_equal expect, Bcat::ANSI.new(text).to_html
75
+ end
76
+
77
+ test "bold" do
78
+ text = "bold: \x1b[1mstuff"
79
+ expect = "bold: <b>stuff</b>"
80
+ assert_equal expect, Bcat::ANSI.new(text).to_html
81
+ end
82
+
83
+ test "resetting a single sequence" do
84
+ text = "\x1b[1mthis is bold\x1b[0m, but this isn't"
85
+ expect = "<b>this is bold</b>, but this isn't"
86
+ assert_equal expect, Bcat::ANSI.new(text).to_html
87
+ end
88
+
89
+ test "resetting many sequences" do
90
+ text = "normal, \x1b[1mbold, \x1b[3munderline, \x1b[31mred\x1b[0m, normal"
91
+ expect = "normal, <b>bold, <u>underline, " +
92
+ "<span style='color:#A00'>red</span></u></b>, normal"
93
+ assert_equal expect, Bcat::ANSI.new(text).to_html
94
+ end
95
+
96
+ test "resetting without an implicit 0 argument" do
97
+ text = "\x1b[1mthis is bold\x1b[m, but this isn't"
98
+ expect = "<b>this is bold</b>, but this isn't"
99
+ assert_equal expect, Bcat::ANSI.new(text).to_html
100
+ end
101
+
102
+ test "multi-attribute sequences" do
103
+ text = "normal, \x1b[1;3;31mbold, underline, and red\x1b[0m, normal"
104
+ expect = "normal, <b><u><span style='color:#A00'>" +
105
+ "bold, underline, and red</span></u></b>, normal"
106
+ assert_equal expect, Bcat::ANSI.new(text).to_html
107
+ end
108
+
109
+ test "multi-attribute sequences with a trailing semi-colon" do
110
+ text = "normal, \x1b[1;3;31;mbold, underline, and red\x1b[0m, normal"
111
+ expect = "normal, <b><u><span style='color:#A00'>" +
112
+ "bold, underline, and red</span></u></b>, normal"
113
+ assert_equal expect, Bcat::ANSI.new(text).to_html
114
+ end
115
+
116
+ test "eating malformed sequences" do
117
+ text = "\x1b[25oops forgot the 'm'"
118
+ expect = "oops forgot the 'm'"
119
+ assert_equal expect, Bcat::ANSI.new(text).to_html
120
+ end
121
+ end
@@ -0,0 +1,12 @@
1
+ require 'contest'
2
+ require 'bcat/browser'
3
+
4
+ class BrowserTest < Test::Unit::TestCase
5
+
6
+ setup { @browser = Bcat::Browser.new('default', nil) }
7
+
8
+ test 'shell quotes double-quotes, backticks, and parameter expansion' do
9
+ assert_equal "\"http://example.com/\\\"/\\$(echo oops)/\\`echo howdy\\`\"",
10
+ @browser.shell_quote("http://example.com/\"/$(echo oops)/`echo howdy`")
11
+ end
12
+ end
@@ -0,0 +1,56 @@
1
+ require 'contest'
2
+ require 'bcat/html'
3
+
4
+ class HeadParserTest < Test::Unit::TestCase
5
+
6
+ setup { @parser = Bcat::HeadParser.new }
7
+
8
+ test 'starts in an unknown state' do
9
+ assert @parser.html?.nil?
10
+ assert @parser.buf.empty?
11
+ end
12
+
13
+ test 'detects non-HTML input' do
14
+ @parser.feed("HOWDY <h1>")
15
+ assert_equal false, @parser.html?
16
+ assert_equal '', @parser.head
17
+ end
18
+
19
+ test 'separates head elements from body' do
20
+ @parser.feed("<style>h1{ font-size:500% }</style>")
21
+ @parser.feed("<h1>HOLLA</h1>")
22
+ assert_equal "<style>h1{ font-size:500% }</style>", @parser.head.strip
23
+ assert_equal "<body>\n<h1>HOLLA</h1>", @parser.body
24
+ end
25
+
26
+ test 'handles multiple head elements' do
27
+ stuff = [
28
+ "<style>h1{ font-size:500% }</style>",
29
+ "<link rel=alternate>",
30
+ "<script type='text/javascript'>{};</script>"
31
+ ]
32
+ stuff.each { |html| @parser.feed(html) }
33
+ @parser.feed("\n \n\n\n<h1>HOLLA</h1>")
34
+
35
+ assert_equal stuff.join, @parser.head.strip
36
+ end
37
+
38
+ test 'handles full documents' do
39
+ @parser.feed("<!DOCTYPE html>\n")
40
+ @parser.feed("<html><head><title>YO</title></head>")
41
+ @parser.feed("<body id=oyy><h1>OY</h1></body></html>")
42
+ assert_equal "<title>YO</title>", @parser.head.strip
43
+ assert_equal "<body id=oyy>\n<h1>OY</h1></body></html>", @parser.body
44
+ end
45
+
46
+ test 'knows when the head is fully parsed' do
47
+ @parser.feed("<!DOCTYPE html>\n")
48
+ assert !@parser.complete?
49
+
50
+ @parser.feed("<html><head><title>YO</title></head>")
51
+ assert !@parser.complete?
52
+
53
+ @parser.feed("<body id=oyy><h1>OY</h1></body></html>")
54
+ assert @parser.complete?
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aslakhellesoy-bcat
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.6.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Tomayko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-22 00:00:00 +01:00
14
+ default_executable: bcat
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rack
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.2.2
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: pipe to browser utility
28
+ email: rtomayko@gmail.com
29
+ executables:
30
+ - a2h
31
+ - bcat
32
+ - btee
33
+ extensions: []
34
+
35
+ extra_rdoc_files:
36
+ - COPYING
37
+ files:
38
+ - CONTRIBUTING
39
+ - COPYING
40
+ - INSTALLING
41
+ - README
42
+ - RELEASING
43
+ - Rakefile
44
+ - bcat.gemspec
45
+ - bin/a2h
46
+ - bin/bcat
47
+ - bin/btee
48
+ - contrib/bman
49
+ - lib/bcat.rb
50
+ - lib/bcat/ansi.rb
51
+ - lib/bcat/browser.rb
52
+ - lib/bcat/html.rb
53
+ - lib/bcat/reader.rb
54
+ - lib/bcat/server.rb
55
+ - man/a2h.1
56
+ - man/a2h.1.ronn
57
+ - man/bcat.1
58
+ - man/bcat.1.ronn
59
+ - man/btee.1
60
+ - man/btee.1.ronn
61
+ - man/index.html
62
+ - test/contest.rb
63
+ - test/test_bcat_a2h.rb
64
+ - test/test_bcat_ansi.rb
65
+ - test/test_bcat_browser.rb
66
+ - test/test_bcat_head_parser.rb
67
+ has_rdoc: true
68
+ homepage: http://rtomayko.github.com/bcat/
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --line-numbers
74
+ - --inline-source
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.6.2
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Concatenate input from standard input, or one or more files, and write progressive output to a browser.
96
+ test_files: []
97
+