Skip to content

Instantly share code, notes, and snippets.

@tompng
Created July 23, 2024 18:55
Show Gist options
  • Save tompng/67e8ff974c2b4d7ba00d10d2c454240c to your computer and use it in GitHub Desktop.
Save tompng/67e8ff974c2b4d7ba00d10d2c454240c to your computer and use it in GitHub Desktop.
# RDOC_USE_PRISM_PARSER=1 bundle exec rdoc --op foo/bar
path_a = 'prism'
path_b = 'legacy'
files_a = Dir.chdir(path_a){Dir.glob('**/*.html')}
files_b = Dir.chdir(path_b){Dir.glob('**/*.html')}
def red(s) = "\e[31m#{s}\e[m"
def green(s) = "\e[32m#{s}\e[m"
def yellow(s) = "\e[33m#{s}\e[m"
p added_files: files_a - files_b, removed_files: files_b - files_a
error_files = []
warns = []
files_a.sort.each do |file|
a = File.read("#{path_a}/#{file}")
b = File.read("#{path_b}/#{file}")
a, b = [a, b].map { _1.gsub("</span>\n</pre>", "</span></pre>") }
a2, b2 = [a, b].map { _1.gsub(/<a href="[^"]+">(<code>)?|(<\/code>)?<\/a>/, '') }
al, bl = [a, b].map { _1.scan(/<a href="[^"]+">(?:<code>)?/).tally }
link_keys = al.keys | bl.keys
if a == b
puts green(file)
elsif a2 == b2
puts yellow(file)
warns << yellow(file)
link_keys.each do |k|
ac = al[k] || 0
bc = bl[k] || 0
warns << "#{ac > bc ? green('+') : red('-')} #{k}: #{bc} => #{ac}" if ac != bc
end
warns << ''
else
puts "#{red(file)}: #{a.size}, #{b.size}, #{a2.size}, #{b2.size}"
error_files << [file, a2, b2]
# system 'diff', '-u', "#{path_b}/#{file}", "#{path_a}/#{file}"
end
end
puts warns
puts error_files.size
error_files.each do |file, a, b|
puts red(file); puts
# system 'diff', '-u', "#{path_b}/#{file}", "#{path_a}/#{file}"
puts (a.lines - b.lines).map { "#{green('+')} #{_1}"}
puts (b.lines - a.lines).map { "#{red('-')} #{_1}"}
4.times { puts }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment