From e127b7d57b06554e708752bbbc2a85e833633c26 Mon Sep 17 00:00:00 2001 From: murphy Date: Mon, 7 Jan 2008 14:42:47 +0000 Subject: Lib: - Encoder: removed a warning - Encoders::HTML: don't shadow outer variable - Plugin: move require_plugin into class namespace - Ruby Scanner: - "alias" keyword recognition - better regexp/division distinction - recognize ~, !, !=, and !~ as method names (partly Ruby 1.9 only) - reordered states for speed Tests: - updated coderay-suite to use gem instead of require_gem - general improvements (more colors!, new parameter: new, new syntax lang.test for only and new) - fixed ruby suite - adjusted a lot of Ruby tests (alias uses methods now) - new tests: ruby/operators, ruby/regexp Samples: - fixed/updated ('bout time) Rake tasks: - updated to use new rubygems API --- test/scanners/ruby/evil.expected.raydebug | 10 ++--- test/scanners/ruby/example.expected.raydebug | 18 ++++----- test/scanners/ruby/operators.expected.raydebug | 51 ++++++++++++++++++++++++++ test/scanners/ruby/operators.in.rb | 51 ++++++++++++++++++++++++++ test/scanners/ruby/pleac.expected.raydebug | 2 +- test/scanners/ruby/regexp.expected.raydebug | 5 +++ test/scanners/ruby/regexp.in.rb | 5 +++ test/scanners/ruby/suite.rb | 2 +- 8 files changed, 128 insertions(+), 16 deletions(-) create mode 100644 test/scanners/ruby/operators.expected.raydebug create mode 100644 test/scanners/ruby/operators.in.rb create mode 100644 test/scanners/ruby/regexp.expected.raydebug create mode 100644 test/scanners/ruby/regexp.in.rb (limited to 'test/scanners/ruby') diff --git a/test/scanners/ruby/evil.expected.raydebug b/test/scanners/ruby/evil.expected.raydebug index cca15dd..84ac855 100644 --- a/test/scanners/ruby/evil.expected.raydebug +++ b/test/scanners/ruby/evil.expected.raydebug @@ -44,10 +44,10 @@ ident(p)operator(()pre_constant(false) operator(::) ident(to_s)operator(\)) reserved(class) class(C2) reserved(class) operator(<<)class(self) reserved(def) pre_constant(self)operator(.)ident(p8)operator(;) ident(p) integer(8) reserved(end) - reserved(alias) ident(p?) ident(p) - reserved(alias) ident(P?) ident(p) - reserved(alias) operator([)operator(]) ident(p) - reserved(alias) operator(<=>) ident(p) + reserved(alias) method(p?) method(p) + reserved(alias) method(P?) method(p) + reserved(alias) method([]) method(p) + reserved(alias) method(<=>) method(p) reserved(end) ident(q)operator(=)integer(9) @@ -881,7 +881,7 @@ reserved(class) operator(<<)class(a) reserved(def) method(foobar) pre_constant(self)operator(*)integer(101) reserved(end) - reserved(alias) ident(eql?) operator(==) + reserved(alias) method(eql?) method(==) reserved(end) ident(p) ident(a)operator(.)ident(foobar) diff --git a/test/scanners/ruby/example.expected.raydebug b/test/scanners/ruby/example.expected.raydebug index 492a67a..5a684e6 100644 --- a/test/scanners/ruby/example.expected.raydebug +++ b/test/scanners/ruby/example.expected.raydebug @@ -217,7 +217,7 @@ reserved(class) class(Set) reserved(def) method(size) instance_variable(@hash)operator(.)ident(size) reserved(end) - reserved(alias) ident(length) ident(size) + reserved(alias) method(length) method(size) comment(# Returns true if the set contains no elements.) reserved(def) method(empty?) @@ -288,7 +288,7 @@ reserved(class) class(Set) reserved(def) method(include?)operator(()ident(o)operator(\)) instance_variable(@hash)operator(.)ident(include?)operator(()ident(o)operator(\)) reserved(end) - reserved(alias) ident(member?) ident(include?) + reserved(alias) method(member?) method(include?) comment(# Returns true if the set is a superset of the given set.) reserved(def) method(superset?)operator(()ident(set)operator(\)) @@ -331,7 +331,7 @@ reserved(class) class(Set) instance_variable(@hash)operator([)ident(o)operator(]) operator(=) pre_constant(true) pre_constant(self) reserved(end) - reserved(alias) operator(<<) ident(add) + reserved(alias) method(<<) method(add) comment(# Adds the given object to the set and returns self. If the) comment(# object is already in the set, returns nil.) @@ -373,7 +373,7 @@ reserved(class) class(Set) ident(each) operator({) operator(|)ident(o)operator(|) ident(set) operator(<<) reserved(yield)operator(()ident(o)operator(\)) operator(}) ident(replace)operator(()ident(set)operator(\)) reserved(end) - reserved(alias) ident(map!) ident(collect!) + reserved(alias) method(map!) method(collect!) comment(# Equivalent to Set#delete_if, but returns nil if no changes were) comment(# made.) @@ -410,8 +410,8 @@ reserved(class) class(Set) ident(enum)operator(.)ident(is_a?)operator(()constant(Enumerable)operator(\)) reserved(or) ident(raise) constant(ArgumentError)operator(,) string ident(dup)operator(.)ident(merge)operator(()ident(enum)operator(\)) reserved(end) - reserved(alias) operator(+) operator(|) comment(##) - reserved(alias) ident(union) operator(|) comment(##) + reserved(alias) method(+) method(|) comment(##) + reserved(alias) method(union) method(|) comment(##) comment(# Returns a new set built by duplicating the set, removing every) comment(# element that appears in the given enumerable object.) @@ -419,7 +419,7 @@ reserved(class) class(Set) ident(enum)operator(.)ident(is_a?)operator(()constant(Enumerable)operator(\)) reserved(or) ident(raise) constant(ArgumentError)operator(,) string ident(dup)operator(.)ident(subtract)operator(()ident(enum)operator(\)) reserved(end) - reserved(alias) ident(difference) operator(-) comment(##) + reserved(alias) method(difference) method(-) comment(##) comment(# Returns a new array containing elements common to the set and the) comment(# given enumerable object.) @@ -429,7 +429,7 @@ reserved(class) class(Set) ident(enum)operator(.)ident(each) operator({) operator(|)ident(o)operator(|) ident(n)operator(.)ident(add)operator(()ident(o)operator(\)) reserved(if) ident(include?)operator(()ident(o)operator(\)) operator(}) ident(n) reserved(end) - reserved(alias) ident(intersection) operator(&) comment(##) + reserved(alias) method(intersection) method(&) comment(##) comment(# Returns a new array containing elements exclusive between the set) comment(# and the given enumerable object. (set ^ enum\) is equivalent to) @@ -508,7 +508,7 @@ reserved(class) class(Set) reserved(class) operator(<<) class(dig) operator(=) operator({)operator(}) comment(# :nodoc:) ident(include) constant(TSort) - reserved(alias) ident(tsort_each_node) ident(each_key) + reserved(alias) method(tsort_each_node) method(each_key) reserved(def) method(tsort_each_child)operator(()ident(node)operator(,) operator(&)ident(block)operator(\)) ident(fetch)operator(()ident(node)operator(\))operator(.)ident(each)operator(()operator(&)ident(block)operator(\)) reserved(end) diff --git a/test/scanners/ruby/operators.expected.raydebug b/test/scanners/ruby/operators.expected.raydebug new file mode 100644 index 0000000..56d9ac3 --- /dev/null +++ b/test/scanners/ruby/operators.expected.raydebug @@ -0,0 +1,51 @@ +reserved(class) class(Feeling) + + reserved(def) method(~) + ident(p) symbol(:drunk) + reserved(end) + + reserved(def) method(!) + ident(p) symbol(:alert) + reserved(end) + + reserved(alias) method(not) method(!@) + reserved(alias) method(tilde) method(~@) + + reserved(def) method(-@) + ident(p) symbol(:bad) + reserved(end) + + reserved(def) method(+@) + ident(p) symbol(:good) + reserved(end) + +reserved(end) + +ident(feeling) operator(=) constant(Feeling)operator(.)ident(new) + +operator(-)ident(feeling) comment(# => :bad) +operator(+)ident(feeling) comment(# => :good) +operator(!)ident(feeling) comment(# => :alert) +operator(~)ident(feeling) comment(# => :drunk) + +reserved(def) method(=~) ident(other) + ident(bla) +reserved(end) + +ident(feeling)operator(.)ident(!) comment(# => :alert) +ident(feeling)operator(.)ident(~) comment(# => :drunk) +ident(feeling)operator(.)ident(!@) comment(# => :alert) +ident(feeling)operator(.)ident(~@) comment(# => :drunk) +ident(feeling)operator(.)ident(-@)operator(()operator(\)) comment(# => :bad) +ident(feeling)operator(.)ident(+@)operator(()operator(\)) comment(# => :good) + +comment(# >> :bad) +comment(# >> :good) +comment(# >> :alert) +comment(# >> :drunk) +comment(# >> :alert) +comment(# >> :drunk) +comment(# >> :alert) +comment(# >> :drunk) +comment(# >> :bad) +comment(# >> :good) diff --git a/test/scanners/ruby/operators.in.rb b/test/scanners/ruby/operators.in.rb new file mode 100644 index 0000000..8fa7090 --- /dev/null +++ b/test/scanners/ruby/operators.in.rb @@ -0,0 +1,51 @@ +class Feeling + + def ~ + p :drunk + end + + def ! + p :alert + end + + alias not !@ + alias tilde ~@ + + def -@ + p :bad + end + + def +@ + p :good + end + +end + +feeling = Feeling.new + +-feeling # => :bad ++feeling # => :good +!feeling # => :alert +~feeling # => :drunk + +def =~ other + bla +end + +feeling.! # => :alert +feeling.~ # => :drunk +feeling.!@ # => :alert +feeling.~@ # => :drunk +feeling.-@() # => :bad +feeling.+@() # => :good + +# >> :bad +# >> :good +# >> :alert +# >> :drunk +# >> :alert +# >> :drunk +# >> :alert +# >> :drunk +# >> :bad +# >> :good diff --git a/test/scanners/ruby/pleac.expected.raydebug b/test/scanners/ruby/pleac.expected.raydebug index b1e7762..0a9a6ac 100644 --- a/test/scanners/ruby/pleac.expected.raydebug +++ b/test/scanners/ruby/pleac.expected.raydebug @@ -4021,7 +4021,7 @@ comment(#=> bar) comment(# You can also take a reference to an existing method before) comment(# redefining a new one, using the `alias' keyword) reserved(def) method(foo)operator(;) ident(puts) stringoperator(;) reserved(end) -reserved(alias) ident(foo_orig) ident(foo) +reserved(alias) method(foo_orig) method(foo) reserved(def) method(foo)operator(;) ident(puts) stringoperator(;) reserved(end) ident(foo_orig) ident(foo) diff --git a/test/scanners/ruby/regexp.expected.raydebug b/test/scanners/ruby/regexp.expected.raydebug new file mode 100644 index 0000000..43f1d91 --- /dev/null +++ b/test/scanners/ruby/regexp.expected.raydebug @@ -0,0 +1,5 @@ +comment(# Regexp or division?) +ident(some_string)operator(.)ident(to_i) regexp +ident(some_string)operator(.)ident(split) operator(/) operator(+)regexp +ident(some_string)operator(.)ident(split) operator(/) operator(+) regexp +ident(some_string)operator(.)ident(split) regexp comment(# and this one is a regexp without division) \ No newline at end of file diff --git a/test/scanners/ruby/regexp.in.rb b/test/scanners/ruby/regexp.in.rb new file mode 100644 index 0000000..956e6b8 --- /dev/null +++ b/test/scanners/ruby/regexp.in.rb @@ -0,0 +1,5 @@ +# Regexp or division? +some_string.to_i /\s+/ +some_string.split / +/ this is a regexp after a division / +some_string.split / + / this one, too / +some_string.split /- / # and this one is a regexp without division \ No newline at end of file diff --git a/test/scanners/ruby/suite.rb b/test/scanners/ruby/suite.rb index ca390f5..bcc5702 100644 --- a/test/scanners/ruby/suite.rb +++ b/test/scanners/ruby/suite.rb @@ -1,2 +1,2 @@ -class Scheme < CodeRay::TestCase +class Ruby < CodeRay::TestCase end -- cgit v1.2.1