class RandTest::UnicodeGenerator

Constants

BLOCK_ENDS
BLOCK_STARTS

Public Class Methods

random_unicode_of_length(min, max, options={}) click to toggle source
# File lib/rand-rspec/strings/unicode_generator.rb, line 59
def random_unicode_of_length(min, max, options={})
  length = random_number_between(min, max)
  spaces = options[:spaces] || false
  block  = rand(BLOCK_STARTS.count)
  (0...length).inject("") do |acc, obj|
    if (spaces && rand(2) > 0)
      acc << " "
    else
      code_point = random_number_between(BLOCK_STARTS[block], BLOCK_ENDS[block])
      acc << code_point.chr(Encoding::UTF_8)
    end
  end
end