tidy_ffi 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
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
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+ gemspec
3
+
4
+ gem 'rspec', '~> 2.0'
5
+ gem 'rake'
6
+ gem 'rr'
data/Rakefile CHANGED
@@ -1,24 +1,6 @@
1
- require 'rubygems'
2
- begin
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
- # My common error
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
- desc 'No effect.'
23
- task :default do; end
24
- end
6
+ task :default => :spec
@@ -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'
@@ -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:
@@ -80,4 +80,4 @@ class TidyFFI::Tidy
80
80
  end
81
81
  attr_writer :validate_options
82
82
  end
83
- end
83
+ end
@@ -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 ||= find_tidy
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,3 @@
1
+ module TidyFFI
2
+ VERSION = "0.1.4"
3
+ end
@@ -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 File.join(File.dirname(__FILE__), 'test_helper')
1
+ require 'spec_helper'
2
2
 
3
- class TestOptions < Test::Unit::TestCase
3
+ describe TidyFFI::Tidy, 'options' do
4
4
  T = TidyFFI::Tidy
5
- context "public interface" do
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
- context "default_options method" do
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
- context "options method" do
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
- context "clear! method" do
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
- context "with_options proxy class" do
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
@@ -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
@@ -0,0 +1,6 @@
1
+ require 'tidy_ffi'
2
+ require 'rspec'
3
+
4
+ RSpec.configure do |config|
5
+ config.mock_with :rr
6
+ end
@@ -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 = %q{tidy_ffi}
5
- s.version = "0.1.3"
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.email = %q{libc@libc.st}
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/tidy_ffi/interface.rb", "lib/tidy_ffi/lib_tidy.rb", "lib/tidy_ffi/options_container.rb", "lib/tidy_ffi/tidy.rb", "lib/tidy_ffi/tidy_ffi_extensions.rb", "lib/tidy_ffi.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "lib/tidy_ffi/interface.rb", "lib/tidy_ffi/lib_tidy.rb", "lib/tidy_ffi/options_container.rb", "lib/tidy_ffi/tidy.rb", "lib/tidy_ffi/tidy_ffi_extensions.rb", "lib/tidy_ffi.rb", "test/test_helper.rb", "test/test_lowlevel.rb", "test/test_options.rb", "test/test_simple.rb", "tidy_ffi.gemspec"]
14
- s.homepage = %q{http://github.com/libc/tidy_ffi}
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
- if s.respond_to? :specification_version then
23
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
- s.specification_version = 3
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
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
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
- prerelease: false
5
- segments:
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
- date: 2010-06-13 00:00:00 +04:00
18
- default_executable:
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
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
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
- version_requirements: *id001
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
- extra_rdoc_files:
41
- - CHANGELOG
42
- - LICENSE
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
- - test/test_helper.rb
63
- - test/test_lowlevel.rb
64
- - test/test_options.rb
65
- - test/test_simple.rb
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
- - --line-numbers
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
- requirements:
83
- - - ">="
84
- - !ruby/object:Gem::Version
85
- segments:
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
- version: "0"
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.3.6
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
- - test/test_helper.rb
105
- - test/test_lowlevel.rb
106
- - test/test_options.rb
107
- - test/test_simple.rb
81
+ test_files:
82
+ - spec/lowlevel_spec.rb
83
+ - spec/options_spec.rb
84
+ - spec/simple_spec.rb
85
+ - spec/spec_helper.rb
@@ -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
@@ -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
@@ -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