Skip to content

Instantly share code, notes, and snippets.

@seebq
Created September 16, 2008 13:44
Show Gist options
  • Save seebq/11037 to your computer and use it in GitHub Desktop.
Save seebq/11037 to your computer and use it in GitHub Desktop.
require File.dirname(__FILE__) + '/../test_helper'
class HebrewReversalTest < Test::Unit::TestCase
def setup
@single_line_string = "I should be reversed."
@multi_line_string = "I should be reversed. \nAnd I should too. \nAlong with me!"
end
# helper to reverse strings if the language is rtl
def reverse_rtl(str)
# if Locale.language.direction == "rtl"
reversed_lines = []
reversed_string = ""
lines = str.split("\n").reverse.join("\n")
lines.each do |line|
line.each_char do |x|
reversed_string.insert(0, x)
end
end
return reversed_string
# else
# return str
# end
end
def test_reverse_single_line
assert_equal ".desrever eb dluohs I", reverse_rtl(@single_line_string)
end
def test_reverse_multi_line
assert_equal " .desrever eb dluohs I\n .oot dluohs I dnA\n!em htiw gnolA", reverse_rtl(@multi_line_string)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment