Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faker::Lorem.multibyte for multibyte chars #817

Merged
merged 6 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/lorem.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Faker::Lorem.words #=> ["dolores", "adipisci", "nesciunt"]
Faker::Lorem.words(4) #=> ["culpa", "recusandae", "aut", "omnis"]
Faker::Lorem.words(4, true) #=> ["colloco", "qui", "vergo", "deporto"]

Faker::Lorem.multibyte #=> 😀

# Optional arguments: char_count=255
Faker::Lorem.characters #=> "uw1ep04lhs0c4d931n1jmrspprf5wrj85fefue0y7y6m56b6omquh7br7dhqijwlawejpl765nb1716idmp3xnfo85v349pzy2o9rir23y2qhflwr71c1585fnynguiphkjm8p0vktwitcsm16lny7jzp9t4drwav3qmhz4yjq4k04x14gl6p148hulyqioo72tf8nwrxxcclfypz2lc58lsibgfe5w5p0xv95peafjjmm2frkhdc6duoky0aha"
Faker::Lorem.characters(10) #=> "ang9cbhoa8"
Expand Down
4 changes: 4 additions & 0 deletions lib/faker/lorem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def characters(char_count = 255)
Array.new(char_count) { sample(CHARACTERS) }.join
end

def multibyte
sample('faker.multibyte')
end

def sentence(word_count = 4, supplemental = false, random_words_to_add = 6)
words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + locale_period
end
Expand Down
2 changes: 1 addition & 1 deletion lib/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ en:
us: "%m/%d/%Y %I:%M %p"
am: "AM"
pm: "PM"

multibyte: ['😀', "\xF0\x9F\x98\xA1", "\xE2\x9D\xA4"]
faker:
separator: ' & '
4 changes: 4 additions & 0 deletions test/test_faker_lorem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def test_words_with_large_count_params
assert(array.length == 250 || array.length == 500)
end

def test_multibyte
assert @tester.multibyte.is_a? String
end

def test_paragraph_char_count
paragraph = @tester.paragraph_by_chars(256)
assert(paragraph.length == 256)
Expand Down
2 changes: 1 addition & 1 deletion test/test_faker_markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_sandwich
test_array = []
test_trigger.each_line { |substr| test_array << substr }

# assert(test_array.length == 3)
assert(test_array.length >= 3)

assert(test_array[0].split(' ').length == 2)
assert(test_array[0].split(' ').first.include?('#'))
Expand Down