Newer
Older
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe String do
let(:english) { "Hello World" }
let(:chinese) { "你好世界" }
let(:arabic) { "مرحبا العالم" }
let(:hebrew) { "שלום העולם" }
let(:english_chinese) { "#{english} #{chinese}" }
let(:english_arabic) { "#{english} #{chinese}" }
let(:english_hebrew) { "#{english} #{chinese}" }
let(:chinese_english) { "#{chinese} #{english}" }
let(:chinese_arabic) { "#{chinese} #{arabic}" }
let(:chinese_hebrew) { "#{chinese} #{hebrew}" }
let(:arabic_english) { "#{arabic} #{english}" }
let(:arabic_chinese) { "#{arabic} #{chinese}" }
let(:arabic_hebrew) { "#{arabic} #{hebrew}" }
let(:hebrew_english) { "#{hebrew} #{english}" }
let(:hebrew_chinese) { "#{hebrew} #{chinese}" }
let(:hebrew_arabic) { "#{hebrew} #{arabic}" }
describe "#stats_with_rtl_char?" do
it 'returns true or false correctly' do
english.starts_with_rtl_char?.should be_false
chinese.starts_with_rtl_char?.should be_false
arabic.starts_with_rtl_char?.should be_true
hebrew.starts_with_rtl_char?.should be_true
hebrew_arabic.starts_with_rtl_char?.should be_true
end
it 'only looks at the first char' do
english_chinese.starts_with_rtl_char?.should be_false
chinese_english.starts_with_rtl_char?.should be_false
english_arabic.starts_with_rtl_char?.should be_false
hebrew_english.starts_with_rtl_char?.should be_true
arabic_chinese.starts_with_rtl_char?.should be_true
end
it 'ignores whitespaces' do
" \n \r \t".starts_with_rtl_char?.should be_false
" #{arabic} ".starts_with_rtl_char?.should be_true
end
end
describe "#is_rtl?" do
it 'returns true or false correctly' do
english.is_rtl?.should be_false
chinese.is_rtl?.should be_false
arabic.is_rtl?.should be_true
hebrew.is_rtl?.should be_true
end
it 'respects all words' do
chinese_arabic.is_rtl?.should be_true
chinese_hebrew.is_rtl?.should be_true
english_hebrew.is_rtl?.should be_false
hebrew_arabic.is_rtl?.should be_true
"#{english} #{arabic} #{chinese}".is_rtl?.should be_false
"Translated to arabic, Hello World means: #{arabic}".is_rtl?.should be_false
"#{english} #{arabic} #{arabic}".is_rtl?.should be_true
end
it "fallbacks to the first word if there's no majority" do
hebrew_english.is_rtl?.should be_true
english_hebrew.is_rtl?.should be_false
arabic_english.is_rtl?.should be_true
english_arabic.is_rtl?.should be_false
end
it 'ignores whitespaces' do
" \n \r \t".is_rtl?.should be_false
" #{arabic} ".is_rtl?.should be_true
end
end
describe '#cleaned_is_rtl?' do
it 'should clean the string' do
"RT: #{arabic}".cleaned_is_rtl?.should be_true
"#{hebrew} RT: #{arabic}".cleaned_is_rtl?.should be_true
"@foo #{arabic}".cleaned_is_rtl?.should be_true
"#{hebrew} #example".cleaned_is_rtl?.should be_true
"♺: #{arabic} ♻: #{hebrew}".cleaned_is_rtl?.should be_true
end
end
end