forked from gollum/gollum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_unicode.rb
106 lines (85 loc) · 2.98 KB
/
test_unicode.rb
1
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
def utf8(str)
str.respond_to?(:force_encoding) ? str.force_encoding('utf-8') : str
end
context "Unicode Support" do
setup do
@path = cloned_testpath("examples/revert.git")
@wiki = Gollum::Wiki.new(@path)
end
teardown do
FileUtils.rm_rf(@path)
end
test "uri encode" do
c = '한글'
assert_equal '%ED%95%9C%EA%B8%80', encodeURIComponent(c)
assert_equal '%ED%95%9C%EA%B8%80', CGI::escape(c)
end
end
context "Frontend Unicode support" do
include Rack::Test::Methods
setup do
@path = cloned_testpath("examples/revert.git")
@wiki = Gollum::Wiki.new(@path)
Precious::App.set(:gollum_path, @path)
Precious::App.set(:wiki_options, {})
end
teardown do
FileUtils.rm_rf(@path)
end
test "creates korean page which contains korean content" do
post "/create", :content => '한글 text', :page => "k",
:format => 'markdown', :message => 'def'
follow_redirect!
assert last_response.ok?
page = @wiki.page('k')
assert_equal '한글 text', utf8(page.raw_data)
assert_equal 'def', page.version.message
end
test "heavy use 1" do
post "/create", :content => '한글 text', :page => "PG",
:format => 'markdown', :message => 'def'
follow_redirect!
assert last_response.ok?
@wiki.update_page(@wiki.page('PG'), nil, nil, '다른 text', {})
page = @wiki.page('PG')
assert_equal '다른 text', utf8(page.raw_data)
post '/edit/PG', :page => 'PG', :content => '바뀐 text', :message => 'ghi'
follow_redirect!
assert last_response.ok?
@wiki = Gollum::Wiki.new(@path)
page = @wiki.page('PG')
assert_equal '바뀐 text', utf8(page.raw_data)
assert_equal 'ghi', page.version.message
end
test "heavy use 2" do
post "/create", :content => '한글 text', :page => "k",
:format => 'markdown', :message => 'def'
follow_redirect!
assert last_response.ok?
@wiki.update_page(@wiki.page('k'), nil, nil, '다른 text', {})
@wiki = Gollum::Wiki.new(@path)
page = @wiki.page('k')
assert_equal '다른 text', utf8(page.raw_data)
post '/edit/' + CGI.escape('한글'), :page => 'k', :content => '바뀐 text',
:format => 'markdown', :message => 'ghi'
follow_redirect!
assert last_response.ok?
@wiki = Gollum::Wiki.new(@path)
page = @wiki.page('k')
assert_equal '바뀐 text', utf8(page.raw_data)
assert_equal 'ghi', page.version.message
end
test 'transliteration' do
# we transliterate only when adapter is grit
return if defined?(Gollum::GIT_ADAPTER) && Gollum::GIT_ADAPTER != 'grit'
# TODO: Remove to_url once write_page changes are merged.
@wiki.write_page('ééééé'.to_url, :markdown, '한글 text', commit_details)
page = @wiki.page('eeeee')
assert_equal '한글 text', utf8(page.raw_data)
end
def app
Precious::App
end
end