tidy_ffi 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/CHANGELOG +2 -1
- data/Gemfile +6 -0
- data/Rakefile +4 -22
- data/lib/tidy_ffi.rb +3 -1
- data/lib/tidy_ffi/lib_tidy.rb +2 -2
- data/lib/tidy_ffi/tidy.rb +1 -1
- data/lib/tidy_ffi/tidy_ffi_extensions.rb +2 -16
- data/lib/tidy_ffi/version.rb +3 -0
- data/spec/lowlevel_spec.rb +84 -0
- data/{test/test_options.rb → spec/options_spec.rb} +8 -8
- data/spec/simple_spec.rb +53 -0
- data/spec/spec_helper.rb +6 -0
- data/tidy_ffi.gemspec +14 -26
- metadata +51 -73
- data/test/test_helper.rb +0 -13
- data/test/test_lowlevel.rb +0 -86
- data/test/test_simple.rb +0 -56
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
v0.1.4. Correct the way libtidy is located on the filesystem. Works if libtidy resides in /usr/lib64, instead of /usr/lib
|
1
2
|
v0.1.3. Fix recognition of date on weird environments
|
2
3
|
v0.1.2. Initialize buffer before use
|
3
4
|
v0.1.1. Fixes for new version of FFI gem
|
@@ -6,4 +7,4 @@ v0.0.4. Options validation
|
|
6
7
|
v0.0.3. Add method “errors” to return errors after cleanup
|
7
8
|
v0.0.2. Do not require matchy, rr and context as development dependencies. A user does not need them.
|
8
9
|
v0.0.1. Options support.
|
9
|
-
v0.0.0. Initial release.
|
10
|
+
v0.0.0. Initial release.
|
data/Gemfile
ADDED
data/Rakefile
CHANGED
@@ -1,24 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require 'echoe'
|
4
|
-
Echoe.new('tidy_ffi') do |p|
|
5
|
-
p.author = 'Eugene Pimenov'
|
6
|
-
p.summary = 'Tidy library interface via FFI'
|
7
|
-
p.url = 'http://github.com/libc/tidy_ffi'
|
8
|
-
p.runtime_dependencies = ['ffi >=0.3.5']
|
9
|
-
# p.development_dependencies = ['rr', 'matchy', 'context']
|
10
|
-
p.project = 'tidy-ffi'
|
11
|
-
p.email = 'libc@libc.st'
|
12
|
-
p.rdoc_pattern = /^(lib|bin|tasks|ext)|^README\.rdoc|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
|
13
|
-
p.retain_gemspec = true
|
14
|
-
end
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
15
3
|
|
16
|
-
|
17
|
-
task :rdoc => :doc do; end
|
18
|
-
rescue LoadError => boom
|
19
|
-
puts "You are missing a dependency required for meta-operations on this gem."
|
20
|
-
puts "#{boom.to_s.capitalize}."
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
21
5
|
|
22
|
-
|
23
|
-
task :default do; end
|
24
|
-
end
|
6
|
+
task :default => :spec
|
data/lib/tidy_ffi.rb
CHANGED
@@ -3,8 +3,10 @@ require 'ffi'
|
|
3
3
|
module TidyFFI
|
4
4
|
self.autoload :LibTidy, 'tidy_ffi/lib_tidy'
|
5
5
|
self.autoload :Interface, 'tidy_ffi/interface'
|
6
|
+
|
7
|
+
class LibTidyNotInstalled < StandardError; end
|
6
8
|
end
|
7
9
|
|
8
10
|
require 'tidy_ffi/options_container'
|
9
11
|
require 'tidy_ffi/tidy'
|
10
|
-
require 'tidy_ffi/tidy_ffi_extensions'
|
12
|
+
require 'tidy_ffi/tidy_ffi_extensions'
|
data/lib/tidy_ffi/lib_tidy.rb
CHANGED
@@ -37,7 +37,7 @@ class TidyFFI::LibTidy #:nodoc:
|
|
37
37
|
attach_function :tidyOptIsReadOnly, [:pointer], :int
|
38
38
|
attach_function :tidyOptGetPickList, [:pointer], :pointer
|
39
39
|
attach_function :tidyOptGetNextPick, [:pointer, :pointer], :string
|
40
|
-
|
40
|
+
|
41
41
|
#types
|
42
42
|
# /** Option data types
|
43
43
|
# */
|
@@ -48,7 +48,7 @@ class TidyFFI::LibTidy #:nodoc:
|
|
48
48
|
# TidyBoolean /**< Boolean flag */
|
49
49
|
# } TidyOptionType;
|
50
50
|
TIDY_OPTION_TYPE = [:string, :integer, :boolean].freeze
|
51
|
-
|
51
|
+
|
52
52
|
end
|
53
53
|
|
54
54
|
class TidyFFI::LibTidy::TidyBuf < FFI::Struct #:nodoc:
|
data/lib/tidy_ffi/tidy.rb
CHANGED
@@ -6,21 +6,7 @@ module TidyFFI::TidyFFIExtensions #:nodoc:
|
|
6
6
|
|
7
7
|
# Returns path to libtidy.{dylib,so}
|
8
8
|
def library_path
|
9
|
-
@libtidy_path ||=
|
9
|
+
@libtidy_path ||= 'tidy'
|
10
10
|
end
|
11
|
-
|
12
|
-
def find_tidy
|
13
|
-
fnames = ['libtidy.dylib', 'libtidy.so']
|
14
|
-
pathes = []
|
15
|
-
pathes += ENV['LD_LIBRARY_PATH'].split(':') if ENV['LD_LIBRARY_PATH']
|
16
|
-
pathes += ENV['DYLD_LIBRARY_PATH'].split(':') if ENV['DYLD_LIBRARY_PATH']
|
17
|
-
pathes += ENV['PATH'].split(':').reject { |a| a['sbin'] }.map { |a| a.sub('/bin', '/lib') } if ENV['PATH']
|
18
|
-
pathes = ['/usr/lib', '/usr/local/lib'] if pathes.size == 0
|
19
|
-
for path in pathes.uniq
|
20
|
-
fnames.each { |fname| return File.join(path, fname) if File.exists?(File.join(path, fname)) }
|
21
|
-
end
|
22
|
-
nil
|
23
|
-
end
|
24
|
-
private :find_tidy
|
25
11
|
end
|
26
|
-
TidyFFI.extend TidyFFI::TidyFFIExtensions
|
12
|
+
TidyFFI.extend TidyFFI::TidyFFIExtensions
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TidyFFI::Interface do
|
4
|
+
I = TidyFFI::Interface
|
5
|
+
|
6
|
+
describe "default_options" do
|
7
|
+
it "returns a hash" do
|
8
|
+
I.default_options.is_a?(Hash)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has show force_output option" do
|
12
|
+
I.default_options[:force_output][:name].should == :force_output
|
13
|
+
I.default_options[:force_output][:type].should == :boolean
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "option_valid" do
|
18
|
+
it "returns false when unknown options is specified" do
|
19
|
+
I.option_valid?(:gobbledygook, '1').should == false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "accepts yes, no, 1, 0, true, false as boolean values" do
|
23
|
+
stub(I).default_options { {:gobbledygook => {:type => :boolean}} }
|
24
|
+
|
25
|
+
%w{yes no 1 0 true false on off YeS}.each do |val|
|
26
|
+
I.option_valid?(:gobbledygook, val).should == true
|
27
|
+
end
|
28
|
+
I.option_valid?(:gobbledygook, 1).should == true
|
29
|
+
I.option_valid?(:gobbledygook, 0).should == true
|
30
|
+
I.option_valid?(:gobbledygook, true).should == true
|
31
|
+
I.option_valid?(:gobbledygook, false).should == true
|
32
|
+
|
33
|
+
I.option_valid?(:gobbledygook, "gobbledygook").should == false
|
34
|
+
end
|
35
|
+
|
36
|
+
it "accepts a number as a valid integer value" do
|
37
|
+
stub(I).default_options { {:gobbledygook => {:type => :integer}} }
|
38
|
+
|
39
|
+
I.option_valid?(:gobbledygook, 1).should == true
|
40
|
+
I.option_valid?(:gobbledygook, 0).should == true
|
41
|
+
I.option_valid?(:gobbledygook, "0").should == true
|
42
|
+
I.option_valid?(:gobbledygook, "1").should == true
|
43
|
+
I.option_valid?(:gobbledygook, "42").should == true
|
44
|
+
|
45
|
+
I.option_valid?(:gobbledygook, "gobbledygook").should == false
|
46
|
+
I.option_valid?(:gobbledygook, "true").should == false
|
47
|
+
end
|
48
|
+
|
49
|
+
it "accepts any string as a valid string value" do
|
50
|
+
stub(I).default_options { {:gobbledygook => {:type => :string}} }
|
51
|
+
|
52
|
+
I.option_valid?(:gobbledygook, 1).should == false
|
53
|
+
I.option_valid?(:gobbledygook, 0).should == false
|
54
|
+
|
55
|
+
I.option_valid?(:gobbledygook, "0").should == true
|
56
|
+
I.option_valid?(:gobbledygook, "1").should == true
|
57
|
+
I.option_valid?(:gobbledygook, "42").should == true
|
58
|
+
I.option_valid?(:gobbledygook, "gobbledygook").should == true
|
59
|
+
I.option_valid?(:gobbledygook, "true").should == true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "accepts a symbols as a valid string value" do
|
63
|
+
stub(I).default_options { {:gobbledygook => {:type => :string}} }
|
64
|
+
|
65
|
+
I.option_valid?(:gobbledygook, :test).should == true
|
66
|
+
end
|
67
|
+
|
68
|
+
it "accepts number in range as a valid enum value" do
|
69
|
+
stub(I).default_options { {:gobbledygook => {:type => :enum, :values => ["one", "two"]}} }
|
70
|
+
|
71
|
+
I.option_valid?(:gobbledygook, 1).should == true
|
72
|
+
I.option_valid?(:gobbledygook, 0).should == true
|
73
|
+
I.option_valid?(:gobbledygook, 3).should == false
|
74
|
+
end
|
75
|
+
|
76
|
+
it "accepts string representation of enum value" do
|
77
|
+
stub(I).default_options { {:gobbledygook => {:type => :enum, :values => ["one", "two"]}} }
|
78
|
+
|
79
|
+
I.option_valid?(:gobbledygook, "one").should == true
|
80
|
+
I.option_valid?(:gobbledygook, "two").should == true
|
81
|
+
I.option_valid?(:gobbledygook, "three").should == false
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
describe TidyFFI::Tidy, 'options' do
|
4
4
|
T = TidyFFI::Tidy
|
5
|
-
|
5
|
+
describe "public interface" do
|
6
6
|
[:default_options, :default_options=, :with_options, :validate_options].each do |method|
|
7
7
|
it "responds to #{method}" do
|
8
8
|
T.respond_to?(method)
|
@@ -10,7 +10,7 @@ class TestOptions < Test::Unit::TestCase
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
describe "#default_options" do
|
14
14
|
before :each do
|
15
15
|
T.default_options.clear!
|
16
16
|
T.validate_options = false
|
@@ -47,7 +47,7 @@ class TestOptions < Test::Unit::TestCase
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
describe "#options" do
|
51
51
|
before :each do
|
52
52
|
T.validate_options = false
|
53
53
|
T.default_options.clear!
|
@@ -71,7 +71,7 @@ class TestOptions < Test::Unit::TestCase
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
|
74
|
+
describe "#clear!" do
|
75
75
|
it "clears options' options" do
|
76
76
|
@t.options.test = 1
|
77
77
|
@t.options.clear!
|
@@ -107,7 +107,7 @@ class TestOptions < Test::Unit::TestCase
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
-
|
110
|
+
describe "with_options proxy class" do
|
111
111
|
before :each do
|
112
112
|
T.validate_options = false
|
113
113
|
end
|
@@ -130,4 +130,4 @@ class TestOptions < Test::Unit::TestCase
|
|
130
130
|
T.with_options(:test => 1).new('test').options.test.should == 1
|
131
131
|
end
|
132
132
|
end
|
133
|
-
end
|
133
|
+
end
|
data/spec/simple_spec.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe TidyFFI::Tidy do
|
4
|
+
T = TidyFFI::Tidy
|
5
|
+
context "public interface" do
|
6
|
+
[[:initialize, -2],
|
7
|
+
[:clean, 0],
|
8
|
+
[:errors, 0]].each do |method, arity|
|
9
|
+
it "method #{method} has arity #{arity}" do
|
10
|
+
T.instance_method(method).arity.should == arity
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "simple cleanup" do
|
16
|
+
it "clean up text" do
|
17
|
+
T.new("test").clean.should =~ %r{<body>\s+test\s+</body>}
|
18
|
+
T.new("test").clean.should =~ %r{<meta name="generator" content=.+?Tidy.+?>}m
|
19
|
+
|
20
|
+
T.clean("test").should =~ %r{<body>\s+test\s+</body>}
|
21
|
+
T.clean("test").should =~ %r{<meta name="generator" content=.+?Tidy.+?>}m
|
22
|
+
end
|
23
|
+
|
24
|
+
it "doesn't die if called twice (bug #27200)" do
|
25
|
+
2.times { T.with_options(:show_warnings => false).new("test").clean }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "should have method for errors" do
|
30
|
+
it "have method for errors" do
|
31
|
+
t = T.new("test")
|
32
|
+
t.clean
|
33
|
+
t.errors.should =~ /Warning/
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
context "options validation" do
|
39
|
+
it "raises error on invalid option name" do
|
40
|
+
TidyFFI::Tidy.validate_options = true
|
41
|
+
lambda do
|
42
|
+
TidyFFI::Tidy.default_options = {:complete_garbage => true}
|
43
|
+
end.should raise_error(TidyFFI::Tidy::InvalidOptionName)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "raises error on invalid option value" do
|
47
|
+
TidyFFI::Tidy.validate_options = true
|
48
|
+
lambda do
|
49
|
+
TidyFFI::Tidy.default_options = {:force_output => "utter trash"}
|
50
|
+
end.should raise_error(TidyFFI::Tidy::InvalidOptionValue)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tidy_ffi.gemspec
CHANGED
@@ -1,34 +1,22 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tidy_ffi/version"
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
4
|
-
s.name
|
5
|
-
s.version
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["Eugene Pimenov"]
|
9
|
-
s.date = %q{2010-06-13}
|
6
|
+
s.name = %q{tidy_ffi}
|
7
|
+
s.version = TidyFFI::VERSION
|
8
|
+
s.authors = ["Eugene Pimenov"]
|
10
9
|
s.description = %q{Tidy library interface via FFI}
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
|
15
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tidy_ffi", "--main", "README.rdoc"]
|
16
|
-
s.require_paths = ["lib"]
|
10
|
+
s.summary = %q{Tidy library interface via FFI}
|
11
|
+
s.email = %q{libc@libc.st}
|
12
|
+
s.homepage = %q{http://github.com/libc/tidy_ffi}
|
13
|
+
|
17
14
|
s.rubyforge_project = %q{tidy-ffi}
|
18
|
-
s.rubygems_version = %q{1.3.6}
|
19
|
-
s.summary = %q{Tidy library interface via FFI}
|
20
|
-
s.test_files = ["test/test_helper.rb", "test/test_lowlevel.rb", "test/test_options.rb", "test/test_simple.rb"]
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
25
20
|
|
26
|
-
|
27
|
-
s.add_runtime_dependency(%q<ffi>, [">= 0.3.5"])
|
28
|
-
else
|
29
|
-
s.add_dependency(%q<ffi>, [">= 0.3.5"])
|
30
|
-
end
|
31
|
-
else
|
32
|
-
s.add_dependency(%q<ffi>, [">= 0.3.5"])
|
33
|
-
end
|
21
|
+
s.add_dependency 'ffi', ">= 0.3.5"
|
34
22
|
end
|
metadata
CHANGED
@@ -1,107 +1,85 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: tidy_ffi
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 3
|
9
|
-
version: 0.1.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Eugene Pimenov
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-02-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: ffi
|
22
|
-
|
23
|
-
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 3
|
30
|
-
- 5
|
16
|
+
requirement: &70164966260060 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
31
21
|
version: 0.3.5
|
32
22
|
type: :runtime
|
33
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70164966260060
|
34
25
|
description: Tidy library interface via FFI
|
35
26
|
email: libc@libc.st
|
36
27
|
executables: []
|
37
|
-
|
38
28
|
extensions: []
|
39
|
-
|
40
|
-
|
41
|
-
-
|
42
|
-
-
|
43
|
-
- README.rdoc
|
44
|
-
- lib/tidy_ffi/interface.rb
|
45
|
-
- lib/tidy_ffi/lib_tidy.rb
|
46
|
-
- lib/tidy_ffi/options_container.rb
|
47
|
-
- lib/tidy_ffi/tidy.rb
|
48
|
-
- lib/tidy_ffi/tidy_ffi_extensions.rb
|
49
|
-
- lib/tidy_ffi.rb
|
50
|
-
files:
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- .rspec
|
51
33
|
- CHANGELOG
|
34
|
+
- Gemfile
|
52
35
|
- LICENSE
|
53
36
|
- Manifest
|
54
37
|
- README.rdoc
|
55
38
|
- Rakefile
|
39
|
+
- lib/tidy_ffi.rb
|
56
40
|
- lib/tidy_ffi/interface.rb
|
57
41
|
- lib/tidy_ffi/lib_tidy.rb
|
58
42
|
- lib/tidy_ffi/options_container.rb
|
59
43
|
- lib/tidy_ffi/tidy.rb
|
60
44
|
- lib/tidy_ffi/tidy_ffi_extensions.rb
|
61
|
-
- lib/tidy_ffi.rb
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
45
|
+
- lib/tidy_ffi/version.rb
|
46
|
+
- spec/lowlevel_spec.rb
|
47
|
+
- spec/options_spec.rb
|
48
|
+
- spec/simple_spec.rb
|
49
|
+
- spec/spec_helper.rb
|
66
50
|
- tidy_ffi.gemspec
|
67
|
-
has_rdoc: true
|
68
51
|
homepage: http://github.com/libc/tidy_ffi
|
69
52
|
licenses: []
|
70
|
-
|
71
53
|
post_install_message:
|
72
|
-
rdoc_options:
|
73
|
-
|
74
|
-
- --inline-source
|
75
|
-
- --title
|
76
|
-
- Tidy_ffi
|
77
|
-
- --main
|
78
|
-
- README.rdoc
|
79
|
-
require_paths:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
80
56
|
- lib
|
81
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
hash: 4149357649508067802
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
segments:
|
86
73
|
- 0
|
87
|
-
|
88
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
-
requirements:
|
90
|
-
- - ">="
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
segments:
|
93
|
-
- 1
|
94
|
-
- 2
|
95
|
-
version: "1.2"
|
74
|
+
hash: 4149357649508067802
|
96
75
|
requirements: []
|
97
|
-
|
98
76
|
rubyforge_project: tidy-ffi
|
99
|
-
rubygems_version: 1.
|
77
|
+
rubygems_version: 1.8.10
|
100
78
|
signing_key:
|
101
79
|
specification_version: 3
|
102
80
|
summary: Tidy library interface via FFI
|
103
|
-
test_files:
|
104
|
-
-
|
105
|
-
-
|
106
|
-
-
|
107
|
-
-
|
81
|
+
test_files:
|
82
|
+
- spec/lowlevel_spec.rb
|
83
|
+
- spec/options_spec.rb
|
84
|
+
- spec/simple_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
data/test/test_helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'tidy_ffi'
|
5
|
-
|
6
|
-
require 'rr'
|
7
|
-
require 'matchy'
|
8
|
-
require 'context'
|
9
|
-
|
10
|
-
class Test::Unit::TestCase
|
11
|
-
alias method_name name unless instance_methods.include?('method_name')
|
12
|
-
include RR::Adapters::TestUnit unless instance_methods.include?('stub') || instance_methods.include?(:stub)
|
13
|
-
end
|
data/test/test_lowlevel.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class TestSimple < Test::Unit::TestCase
|
4
|
-
I = TidyFFI::Interface
|
5
|
-
context "TidyFFI::Interface" do
|
6
|
-
context "default_options" do
|
7
|
-
it "returns a hash" do
|
8
|
-
I.default_options.is_a?(Hash)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "has show force_output option" do
|
12
|
-
I.default_options[:force_output][:name].should == :force_output
|
13
|
-
I.default_options[:force_output][:type].should == :boolean
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "option_valid" do
|
18
|
-
it "returns false when unknown options is specified" do
|
19
|
-
I.option_valid?(:gobbledygook, '1').should == false
|
20
|
-
end
|
21
|
-
|
22
|
-
it "accepts yes, no, 1, 0, true, false as boolean values" do
|
23
|
-
stub(I).default_options { {:gobbledygook => {:type => :boolean}} }
|
24
|
-
|
25
|
-
%w{yes no 1 0 true false on off YeS}.each do |val|
|
26
|
-
I.option_valid?(:gobbledygook, val).should == true
|
27
|
-
end
|
28
|
-
I.option_valid?(:gobbledygook, 1).should == true
|
29
|
-
I.option_valid?(:gobbledygook, 0).should == true
|
30
|
-
I.option_valid?(:gobbledygook, true).should == true
|
31
|
-
I.option_valid?(:gobbledygook, false).should == true
|
32
|
-
|
33
|
-
I.option_valid?(:gobbledygook, "gobbledygook").should == false
|
34
|
-
end
|
35
|
-
|
36
|
-
it "accepts a number as a valid integer value" do
|
37
|
-
stub(I).default_options { {:gobbledygook => {:type => :integer}} }
|
38
|
-
|
39
|
-
I.option_valid?(:gobbledygook, 1).should == true
|
40
|
-
I.option_valid?(:gobbledygook, 0).should == true
|
41
|
-
I.option_valid?(:gobbledygook, "0").should == true
|
42
|
-
I.option_valid?(:gobbledygook, "1").should == true
|
43
|
-
I.option_valid?(:gobbledygook, "42").should == true
|
44
|
-
|
45
|
-
I.option_valid?(:gobbledygook, "gobbledygook").should == false
|
46
|
-
I.option_valid?(:gobbledygook, "true").should == false
|
47
|
-
end
|
48
|
-
|
49
|
-
it "accepts any string as a valid string value" do
|
50
|
-
stub(I).default_options { {:gobbledygook => {:type => :string}} }
|
51
|
-
|
52
|
-
I.option_valid?(:gobbledygook, 1).should == false
|
53
|
-
I.option_valid?(:gobbledygook, 0).should == false
|
54
|
-
|
55
|
-
I.option_valid?(:gobbledygook, "0").should == true
|
56
|
-
I.option_valid?(:gobbledygook, "1").should == true
|
57
|
-
I.option_valid?(:gobbledygook, "42").should == true
|
58
|
-
I.option_valid?(:gobbledygook, "gobbledygook").should == true
|
59
|
-
I.option_valid?(:gobbledygook, "true").should == true
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
it "accepts a symbols as a valid string value" do
|
64
|
-
stub(I).default_options { {:gobbledygook => {:type => :string}} }
|
65
|
-
|
66
|
-
I.option_valid?(:gobbledygook, :test).should == true
|
67
|
-
end
|
68
|
-
|
69
|
-
it "accepts number in range as a valid enum value" do
|
70
|
-
stub(I).default_options { {:gobbledygook => {:type => :enum, :values => ["one", "two"]}} }
|
71
|
-
|
72
|
-
I.option_valid?(:gobbledygook, 1).should == true
|
73
|
-
I.option_valid?(:gobbledygook, 0).should == true
|
74
|
-
I.option_valid?(:gobbledygook, 3).should == false
|
75
|
-
end
|
76
|
-
|
77
|
-
it "accepts string representation of enum value" do
|
78
|
-
stub(I).default_options { {:gobbledygook => {:type => :enum, :values => ["one", "two"]}} }
|
79
|
-
|
80
|
-
I.option_valid?(:gobbledygook, "one").should == true
|
81
|
-
I.option_valid?(:gobbledygook, "two").should == true
|
82
|
-
I.option_valid?(:gobbledygook, "three").should == false
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
data/test/test_simple.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class TestSimple < Test::Unit::TestCase
|
4
|
-
T = TidyFFI::Tidy
|
5
|
-
context "TidyFFI::Tidy" do
|
6
|
-
context "public interface" do
|
7
|
-
[[:initialize, -2],
|
8
|
-
[:clean, 0],
|
9
|
-
[:errors, 0]].each do |method, arity|
|
10
|
-
it "method #{method} has arity #{arity}" do
|
11
|
-
T.instance_method(method).arity.should == arity
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context "simple cleanup" do
|
17
|
-
it "clean up text" do
|
18
|
-
T.new("test").clean.should =~ %r{<body>\s+test\s+</body>}
|
19
|
-
T.new("test").clean.should =~ %r{<meta name="generator" content=.+?Tidy.+?>}m
|
20
|
-
|
21
|
-
T.clean("test").should =~ %r{<body>\s+test\s+</body>}
|
22
|
-
T.clean("test").should =~ %r{<meta name="generator" content=.+?Tidy.+?>}m
|
23
|
-
end
|
24
|
-
|
25
|
-
it "doesn't die if called twice (bug #27200)" do
|
26
|
-
2.times { T.with_options(:show_warnings => false).new("test").clean }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "should have method for errors" do
|
31
|
-
it "have method for errors" do
|
32
|
-
t = T.new("test")
|
33
|
-
t.clean
|
34
|
-
t.errors.should =~ /Warning/
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
|
39
|
-
# Commented out, because of broken upstream matchy gem :(
|
40
|
-
# context "options validation" do
|
41
|
-
# it "raises error on invalid option name" do
|
42
|
-
# TidyFFI::Tidy.validate_options = true
|
43
|
-
# lambda do
|
44
|
-
# TidyFFI::Tidy.default_options = {:complete_garbage => true}
|
45
|
-
# end.should raise_error(TidyFFI::Tidy::InvalidOptionName)
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# it "raises error on invalid option value" do
|
49
|
-
# TidyFFI::Tidy.validate_options = true
|
50
|
-
# lambda do
|
51
|
-
# TidyFFI::Tidy.default_options = {:force_output => "utter trash"}
|
52
|
-
# end.should raise_error(TidyFFI::Tidy::InvalidOptionValue)
|
53
|
-
# end
|
54
|
-
# end
|
55
|
-
end
|
56
|
-
end
|