From 4d7ce5f7037580a127ae26d36f49ac5cdf49000d Mon Sep 17 00:00:00 2001 From: murphy Date: Wed, 18 Oct 2006 08:33:33 +0000 Subject: Fixed functional test. Fixed Ruby scanner (/= was scanned as regexp!) Made bench.rb run from any folder. Made scanner test diff function work via EDITOR instead of gvimdiff. --- test/functional/basic.rb | 2 +- test/scanners/coderay_suite.rb | 4 +- test/scanners/ruby/pleac.expected.raydebug | 380 ++++++++++++++--------------- 3 files changed, 194 insertions(+), 192 deletions(-) (limited to 'test') diff --git a/test/functional/basic.rb b/test/functional/basic.rb index d793f5f..a00e4ae 100755 --- a/test/functional/basic.rb +++ b/test/functional/basic.rb @@ -38,7 +38,7 @@ class Basic < Test::Unit::TestCase SCANNERS_LIST = %w( c delphi html nitro_xhtml plaintext rhtml ruby xml ) - def test_list_of_encoders + def test_list_of_scanners assert_equal(SCANNERS_LIST, CodeRay::Scanners.list.sort) end end \ No newline at end of file diff --git a/test/scanners/coderay_suite.rb b/test/scanners/coderay_suite.rb index c498f2e..4f415a1 100644 --- a/test/scanners/coderay_suite.rb +++ b/test/scanners/coderay_suite.rb @@ -151,7 +151,9 @@ module CodeRay unless ok File.open(actual_filename, 'wb') { |f| f.write result } if ENV['diff'] - print `gvimdiff #{expected_filename} #{actual_filename}` + diff = expected_filename.sub(/\.expected\..*/, '.diff') + system "diff #{expected_filename} #{actual_filename} > #{diff}" + system "EDITOR #{diff}" end end unless ENV['diff'] or ENV['noassert'] diff --git a/test/scanners/ruby/pleac.expected.raydebug b/test/scanners/ruby/pleac.expected.raydebug index c6fcd8c..a738eaa 100644 --- a/test/scanners/ruby/pleac.expected.raydebug +++ b/test/scanners/ruby/pleac.expected.raydebug @@ -652,87 +652,87 @@ reserved(def) method(factorize)operator(()ident(orig)operator(\)) ident(sqi) operator(=) integer(4) comment(# square of i) reserved(while) ident(sqi) operator(<=) ident(n) reserved(do) reserved(while) ident(n)operator(.)ident(modulo)operator(()ident(i)operator(\)) operator(==) integer(0) reserved(do) - ident(n) regexpcontent(" - end - # we take advantage of the fact that (i +1\)**2 = i**2 + 2*i +1 - sqi += 2 * i + 1 - i += 1 - end + ident(n) operator(/=) ident(i) + ident(factors)operator([)ident(i)operator(]) operator(+=) integer(1) + comment(# puts "Found factor #{i}") + reserved(end) + comment(# we take advantage of the fact that (i +1\)**2 = i**2 + 2*i +1) + ident(sqi) operator(+=) integer(2) operator(*) ident(i) operator(+) integer(1) + ident(i) operator(+=) integer(1) + reserved(end) - if (n != 1\) && (n != orig\) - factors[n] += 1 - end - factors -end + reserved(if) operator(()ident(n) operator(!=) integer(1)operator(\)) operator(&&) operator(()ident(n) operator(!=) ident(orig)operator(\)) + ident(factors)operator([)ident(n)operator(]) operator(+=) integer(1) + reserved(end) + ident(factors) +reserved(end) -def printfactorhash(orig, factorcount\) - print format("%-10d ", orig\) - if factorcount.length == 0 - print "PRIME" - else - # sorts after number, because the hash keys are numbers - factorcount.sort.each { |factor,exponent| - print factor - if exponent > 1 - print "**", exponent - end - print " " - } - end - puts -end +reserved(def) method(printfactorhash)operator(()ident(orig)operator(,) ident(factorcount)operator(\)) + ident(print) ident(format)operator(()stringoperator(,) ident(orig)operator(\)) + reserved(if) ident(factorcount)operator(.)ident(length) operator(==) integer(0) + ident(print) string + reserved(else) + comment(# sorts after number, because the hash keys are numbers) + ident(factorcount)operator(.)ident(sort)operator(.)ident(each) operator({) operator(|)ident(factor)operator(,)ident(exponent)operator(|) + ident(print) ident(factor) + reserved(if) ident(exponent) operator(>) integer(1) + ident(print) stringoperator(,) ident(exponent) + reserved(end) + ident(print) string + operator(}) + reserved(end) + ident(puts) +reserved(end) -for arg in ARGV - n = arg.to_i - mfactors = factorize(n\) - printfactorhash(n, mfactors\) -end -#----------------------------- +reserved(for) ident(arg) reserved(in) pre_constant(ARGV) + ident(n) operator(=) ident(arg)operator(.)ident(to_i) + ident(mfactors) operator(=) ident(factorize)operator(()ident(n)operator(\)) + ident(printfactorhash)operator(()ident(n)operator(,) ident(mfactors)operator(\)) +reserved(end) +comment(#-----------------------------) -# @@PLEAC@@_3.0 -puts Time.now +comment(# @@PLEAC@@_3.0) +ident(puts) constant(Time)operator(.)ident(now) -print "Today is day ", Time.now.yday, " of the current year.)char(\\n)content(" -print "Today is day ", Time.now.day, " of the current month.)char(\\n)content(" +ident(print) stringoperator(,) constant(Time)operator(.)ident(now)operator(.)ident(yday)operator(,) string +ident(print) stringoperator(,) constant(Time)operator(.)ident(now)operator(.)ident(day)operator(,) string -# @@PLEAC@@_3.1 -day, month, year = Time.now.day, Time.now.month, Time.now.year -# or -day, month, year = Time.now.to_a[3..5] +comment(# @@PLEAC@@_3.1) +ident(day)operator(,) ident(month)operator(,) ident(year) operator(=) constant(Time)operator(.)ident(now)operator(.)ident(day)operator(,) constant(Time)operator(.)ident(now)operator(.)ident(month)operator(,) constant(Time)operator(.)ident(now)operator(.)ident(year) +comment(# or) +ident(day)operator(,) ident(month)operator(,) ident(year) operator(=) constant(Time)operator(.)ident(now)operator(.)ident(to_a)operator([)integer(3)operator(..)integer(5)operator(]) -tl = Time.now.localtime -printf("The current date is %04d %02d %02d)char(\\n)content(", tl.year, tl.month, tl.day\) +ident(tl) operator(=) constant(Time)operator(.)ident(now)operator(.)ident(localtime) +ident(printf)operator(()stringoperator(,) ident(tl)operator(.)ident(year)operator(,) ident(tl)operator(.)ident(month)operator(,) ident(tl)operator(.)ident(day)operator(\)) -Time.now.localtime.strftime("%Y-%m-%d"\) +constant(Time)operator(.)ident(now)operator(.)ident(localtime)operator(.)ident(strftime)operator(()stringoperator(\)) -# @@PLEAC@@_3.2 -Time.local(year, month, day, hour, minute, second\).tv_sec -Time.gm(year, month, day, hour, minute, second\).tv_sec +comment(# @@PLEAC@@_3.2) +constant(Time)operator(.)ident(local)operator(()ident(year)operator(,) ident(month)operator(,) ident(day)operator(,) ident(hour)operator(,) ident(minute)operator(,) ident(second)operator(\))operator(.)ident(tv_sec) +constant(Time)operator(.)ident(gm)operator(()ident(year)operator(,) ident(month)operator(,) ident(day)operator(,) ident(hour)operator(,) ident(minute)operator(,) ident(second)operator(\))operator(.)ident(tv_sec) -# @@PLEAC@@_3.3 -sec, min, hour, day, month, year, wday, yday, isdst, zone = Time.at(epoch_secs\).to_a +comment(# @@PLEAC@@_3.3) +ident(sec)operator(,) ident(min)operator(,) ident(hour)operator(,) ident(day)operator(,) ident(month)operator(,) ident(year)operator(,) ident(wday)operator(,) ident(yday)operator(,) ident(isdst)operator(,) ident(zone) operator(=) constant(Time)operator(.)ident(at)operator(()ident(epoch_secs)operator(\))operator(.)ident(to_a) -# @@PLEAC@@_3.4 -when_ = now + difference # now -> Time ; difference -> Numeric (delta in seconds\) -then_ = now - difference +comment(# @@PLEAC@@_3.4) +ident(when_) operator(=) ident(now) operator(+) ident(difference) comment(# now -> Time ; difference -> Numeric (delta in seconds\)) +ident(then_) operator(=) ident(now) operator(-) ident(difference) -# @@PLEAC@@_3.5 -bree = 361535725 -nat = 96201950 +comment(# @@PLEAC@@_3.5) +ident(bree) operator(=) integer(361535725) +ident(nat) operator(=) integer(96201950) -difference = bree - nat -puts "There were )inlinecontent( seconds between Nat and Bree" +ident(difference) operator(=) ident(bree) operator(-) ident(nat) +ident(puts) stringcontent( seconds between Nat and Bree)delimiter(")> -seconds = difference % 60 -difference = (difference - seconds\) )delimiter(/)> integer(60) +ident(seconds) operator(=) ident(difference) operator(%) integer(60) +ident(difference) operator(=) operator(()ident(difference) operator(-) ident(seconds)operator(\)) operator(/) integer(60) ident(minutes) operator(=) ident(difference) operator(%) integer(60) ident(difference) operator(=) operator(()ident(difference) operator(-) ident(minutes)operator(\)) operator(/) integer(60) ident(hours) operator(=) ident(difference) operator(%) integer(24) @@ -1353,135 +1353,135 @@ reserved(def) method(n2pat)operator(()ident(n)operator(,) ident(length)operator( ident(i) operator(=) integer(1) reserved(while) ident(i) operator(<=) ident(length) ident(pat)operator(.)ident(push)operator(()ident(n) operator(%) ident(i)operator(\)) - ident(n) regexp 0 - perm -end - -def n2perm(n, len\) - pat2perm(n2pat(n,len\)\) -end - -# In ruby the main program must be after all definitions -while gets - data = split - # the perl solution has used $#data, which is length-1 - num_permutations = Factorial.compute(data.length(\)\) - 0.upto(num_permutations - 1\) do |i| - # in ruby we can not use an array as selector for an array - # but by exchanging the two arrays, we can use the collect method - # which returns an array with the result of all block invocations - permutation = n2perm(i, data.length\).collect { - |j| data[j] - } - puts permutation.join(" "\) - end -end - - -# @@PLEAC@@_5.0 -age = { "Nat", 24, - "Jules", 25, - "Josh", 17 } - -age["Nat"] = 24 -age["Jules"] = 25 -age["Josh"] = 17 - -food_color = { - "Apple" => "red", - "Banana" => "yellow", - "Lemon" => "yellow", - "Carrot" => "orange" - } - -# In Ruby, you cannot avoid the double or simple quoting -# while manipulatin hashes - - -# @@PLEAC@@_5.1 -hash[key] = value - -food_color["Raspberry"] = "pink" -puts "Known foods:", food_color.keys - - -# @@PLEAC@@_5.2 -# does hash have a value for key ? -if (hash.has_key?(key\)\) - # it exists -else - # it doesn't -end - -[ "Banana", "Martini" ].each { |name| - print name, " is a ", food_color.has_key?(name\) ? "food" : "drink", ")char(\\n)content(" -} - -age = {} -age['Toddler'] = 3 -age['Unborn'] = 0 -age['Phantasm'] = nil - -for thing in ['Toddler', 'Unborn', 'Phantasm', 'Relic'] - print ")inlinecontent(: " - print "Has-key " if age.has_key?(thing\) - print "True " if age[thing] - print "Nonzero " if age[thing] && age[thing].nonzero? - print ")char(\\n)content(" -end - -#=> -# Toddler: Has-key True Nonzero -# Unborn: Has-key True -# Phantasm: Has-key -# Relic: - -# You use Hash#has_key? when you use Perl's exists -> it checks -# for existence of a key in a hash. -# All Numeric are "True" in ruby, so the test doesn't have the -# same semantics as in Perl; you would use Numeric#nonzero? to -# achieve the same semantics (false if 0, true otherwise\). - - -# @@PLEAC@@_5.3 -food_color.delete("Banana"\) - - -# @@PLEAC@@_5.4 -hash.each { |key, value| - # do something with key and value -} - -hash.each_key { |key| - # do something with key -} - -food_color.each { |food, color| - puts ")inlinecontent( is )inlinecontent(" -} - -food_color.each_key { |food| - puts ")inlinecontent( is )inlinecontent(" -} - -# IMO this demonstrates that OO style is by far more readable -food_color.keys.sort.each { |food| - puts ")inlinecontent( is )inlinecontent(." -} - -#----------------------------- -#!)delimiter(/)modifier(us)>ident(r)operator(/)ident(bin)operator(/)ident(ruby) + ident(n) operator(/=) ident(i) + ident(i) operator(+=) integer(1) + reserved(end) + ident(pat) +reserved(end) + +comment(# pat2perm(pat\): turn pattern returned by n2pat(\) into) +comment(# permutation of integers.) +reserved(def) method(pat2perm)operator(()ident(pat)operator(\)) + ident(source) operator(=) operator(()integer(0) operator(..) ident(pat)operator(.)ident(length) operator(-) integer(1)operator(\))operator(.)ident(to_a) + ident(perm) operator(=) operator([)operator(]) + ident(perm)operator(.)ident(push)operator(()ident(source)operator(.)ident(slice!)operator(()ident(pat)operator(.)ident(pop)operator(\))operator(\)) reserved(while) ident(pat)operator(.)ident(length) operator(>) integer(0) + ident(perm) +reserved(end) + +reserved(def) method(n2perm)operator(()ident(n)operator(,) ident(len)operator(\)) + ident(pat2perm)operator(()ident(n2pat)operator(()ident(n)operator(,)ident(len)operator(\))operator(\)) +reserved(end) + +comment(# In ruby the main program must be after all definitions) +reserved(while) ident(gets) + ident(data) operator(=) ident(split) + comment(# the perl solution has used $#data, which is length-1) + ident(num_permutations) operator(=) constant(Factorial)operator(.)ident(compute)operator(()ident(data)operator(.)ident(length)operator(()operator(\))operator(\)) + integer(0)operator(.)ident(upto)operator(()ident(num_permutations) operator(-) integer(1)operator(\)) reserved(do) operator(|)ident(i)operator(|) + comment(# in ruby we can not use an array as selector for an array) + comment(# but by exchanging the two arrays, we can use the collect method) + comment(# which returns an array with the result of all block invocations) + ident(permutation) operator(=) ident(n2perm)operator(()ident(i)operator(,) ident(data)operator(.)ident(length)operator(\))operator(.)ident(collect) operator({) + operator(|)ident(j)operator(|) ident(data)operator([)ident(j)operator(]) + operator(}) + ident(puts) ident(permutation)operator(.)ident(join)operator(()stringoperator(\)) + reserved(end) +reserved(end) + + +comment(# @@PLEAC@@_5.0) +ident(age) operator(=) operator({) stringoperator(,) integer(24)operator(,) + stringoperator(,) integer(25)operator(,) + stringoperator(,) integer(17) operator(}) + +ident(age)operator([)stringoperator(]) operator(=) integer(24) +ident(age)operator([)stringoperator(]) operator(=) integer(25) +ident(age)operator([)stringoperator(]) operator(=) integer(17) + +ident(food_color) operator(=) operator({) + string operator(=)operator(>) stringoperator(,) + string operator(=)operator(>) stringoperator(,) + string operator(=)operator(>) stringoperator(,) + string operator(=)operator(>) string + operator(}) + +comment(# In Ruby, you cannot avoid the double or simple quoting) +comment(# while manipulatin hashes) + + +comment(# @@PLEAC@@_5.1) +ident(hash)operator([)ident(key)operator(]) operator(=) ident(value) + +ident(food_color)operator([)stringoperator(]) operator(=) string +ident(puts) stringoperator(,) ident(food_color)operator(.)ident(keys) + + +comment(# @@PLEAC@@_5.2) +comment(# does hash have a value for key ?) +reserved(if) operator(()ident(hash)operator(.)ident(has_key?)operator(()ident(key)operator(\))operator(\)) + comment(# it exists) +reserved(else) + comment(# it doesn't) +reserved(end) + +operator([) stringoperator(,) string operator(])operator(.)ident(each) operator({) operator(|)ident(name)operator(|) + ident(print) ident(name)operator(,) stringoperator(,) ident(food_color)operator(.)ident(has_key?)operator(()ident(name)operator(\)) operator(?) string operator(:) stringoperator(,) string +operator(}) + +ident(age) operator(=) operator({)operator(}) +ident(age)operator([)stringoperator(]) operator(=) integer(3) +ident(age)operator([)stringoperator(]) operator(=) integer(0) +ident(age)operator([)stringoperator(]) operator(=) pre_constant(nil) + +reserved(for) ident(thing) reserved(in) operator([)stringoperator(,) stringoperator(,) stringoperator(,) stringoperator(]) + ident(print) stringcontent(: )delimiter(")> + ident(print) string reserved(if) ident(age)operator(.)ident(has_key?)operator(()ident(thing)operator(\)) + ident(print) string reserved(if) ident(age)operator([)ident(thing)operator(]) + ident(print) string reserved(if) ident(age)operator([)ident(thing)operator(]) operator(&&) ident(age)operator([)ident(thing)operator(])operator(.)ident(nonzero?) + ident(print) string +reserved(end) + +comment(#=>) +comment(# Toddler: Has-key True Nonzero ) +comment(# Unborn: Has-key True ) +comment(# Phantasm: Has-key ) +comment(# Relic: ) + +comment(# You use Hash#has_key? when you use Perl's exists -> it checks) +comment(# for existence of a key in a hash.) +comment(# All Numeric are "True" in ruby, so the test doesn't have the) +comment(# same semantics as in Perl; you would use Numeric#nonzero? to) +comment(# achieve the same semantics (false if 0, true otherwise\).) + + +comment(# @@PLEAC@@_5.3) +ident(food_color)operator(.)ident(delete)operator(()stringoperator(\)) + + +comment(# @@PLEAC@@_5.4) +ident(hash)operator(.)ident(each) operator({) operator(|)ident(key)operator(,) ident(value)operator(|) + comment(# do something with key and value) +operator(}) + +ident(hash)operator(.)ident(each_key) operator({) operator(|)ident(key)operator(|) + comment(# do something with key) +operator(}) + +ident(food_color)operator(.)ident(each) operator({) operator(|)ident(food)operator(,) ident(color)operator(|) + ident(puts) stringcontent( is )inlinedelimiter(")> +operator(}) + +ident(food_color)operator(.)ident(each_key) operator({) operator(|)ident(food)operator(|) + ident(puts) stringcontent( is )inlinedelimiter(")> +operator(}) + +comment(# IMO this demonstrates that OO style is by far more readable) +ident(food_color)operator(.)ident(keys)operator(.)ident(sort)operator(.)ident(each) operator({) operator(|)ident(food)operator(|) + ident(puts) stringcontent( is )inlinecontent(.)delimiter(")> +operator(}) + +comment(#-----------------------------) +comment(#!/usr/bin/ruby) comment(# countfrom - count number of messages from each sender) comment(# Default value is 0) -- cgit v1.2.1