Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: libc/tidy_ffi
base: 7f00c9702c
...
head fork: libc/tidy_ffi
compare: 94fc091aed
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 11, 2012
Eugene Pimenov Code cleanup.
Remove some trailing spaces and bad grammar.
acf0787
Eugene Pimenov Downcase enum values on validation
When trying to assign an enum value, downcase it. Tidy does not seem to
mind mixed-caseness of enum values. Who are we to enfore that in the
bindings?
94fc091
11 lib/tidy_ffi/interface.rb
View
@@ -111,7 +111,7 @@ def pick_list_for(opt)
pick_list
end
private :pick_list_for
-
+
# Loads default options.
def load_default_options
return if @default_options
@@ -171,11 +171,12 @@ def load_default_options
def self.default_options
@default_options ||= load_default_options
end
-
+
# Returns true if value is valid for +option+ and false otherwise.
def self.option_valid?(option, value)
- return false unless spec = default_options[option]
-
+ spec = default_options[option]
+ return false unless spec
+
case spec[:type]
when :boolean
true == value || false == value || value == 0 || value == 1 || %w(on off true false 0 1 yes no).include?(value.downcase)
@@ -185,7 +186,7 @@ def self.option_valid?(option, value)
if Integer === value
!!spec[:values][value]
else
- spec[:values].include?(value)
+ spec[:values].include?(value.downcase)
end
when :string
String === value || Symbol === value
14 lib/tidy_ffi/options_container.rb
View
@@ -48,12 +48,12 @@ def method_missing(method, *args)
# It's a kinda bad method: it uses TidyFFI::Interface.option_valid and TidyFFI::Tidy.validate_options?
# Also it do second lookup into default options
def validate_option(key, value)
- if TidyFFI::Tidy.validate_options? && !TidyFFI::Interface.option_valid?(key, value)
- if TidyFFI::Interface.default_options[key]
- raise TidyFFI::Tidy::InvalidOptionValue, "#{value} is not valid for #{key}"
- else
- raise TidyFFI::Tidy::InvalidOptionName, "#{key} is invalid option name"
- end
+ return if !TidyFFI::Tidy.validate_options? || TidyFFI::Interface.option_valid?(key, value)
+
+ if TidyFFI::Interface.default_options[key]
+ raise TidyFFI::Tidy::InvalidOptionValue, "#{value} is not a valid value for key #{key}"
+ else
+ raise TidyFFI::Tidy::InvalidOptionName, "#{key} is an invalid option name"
end
end
@@ -87,4 +87,4 @@ def method_missing(meth, *args)
@obj.send(meth, *args)
end
end
-end
+end
9 spec/simple_spec.rb
View
@@ -46,8 +46,13 @@
it "raises error on invalid option value" do
TidyFFI::Tidy.validate_options = true
lambda do
- TidyFFI::Tidy.default_options = {:force_output => "utter trash"}
+ TidyFFI::Tidy.default_options = {:force_output => "utter garbage"}
end.should raise_error(TidyFFI::Tidy::InvalidOptionValue)
end
+
+ it 'accepts UTF-8 writter in uppercase' do
+ TidyFFI::Tidy.validate_options = true
+ expect { TidyFFI::Tidy.default_options = {:char_encoding => "UTF8"} }.not_to raise_error
+ end
end
-end
+end

No commit comments for this range

Something went wrong with that request. Please try again.