twitter_cldr 1.8.1 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -2
- data/History.txt +7 -1
- data/README.md +55 -0
- data/lib/twitter_cldr/core_ext.rb +1 -1
- data/lib/twitter_cldr/formatters/list_formatter.rb +64 -0
- data/lib/twitter_cldr/formatters.rb +4 -2
- data/lib/twitter_cldr/localized/localized_array.rb +19 -1
- data/lib/twitter_cldr/localized/localized_hash.rb +20 -0
- data/lib/twitter_cldr/localized/localized_string.rb +46 -1
- data/lib/twitter_cldr/localized/localized_symbol.rb +4 -0
- data/lib/twitter_cldr/localized.rb +1 -0
- data/lib/twitter_cldr/resources/bidi_test_importer.rb +118 -0
- data/lib/twitter_cldr/resources/locales_resources_importer.rb +1 -1
- data/lib/twitter_cldr/resources.rb +1 -0
- data/lib/twitter_cldr/shared/bidi.rb +526 -0
- data/lib/twitter_cldr/shared/languages.rb +5 -0
- data/lib/twitter_cldr/shared.rb +1 -0
- data/lib/twitter_cldr/utils/code_points.rb +1 -1
- data/lib/twitter_cldr/utils/yaml.rb +390 -0
- data/lib/twitter_cldr/utils.rb +1 -0
- data/lib/twitter_cldr/version.rb +1 -1
- data/lib/twitter_cldr.rb +2 -0
- data/resources/custom/locales/en/units.yml +19 -18
- data/resources/locales/af/calendars.yml +67 -66
- data/resources/locales/af/languages.yml +22 -22
- data/resources/locales/af/layout.yml +5 -0
- data/resources/locales/af/lists.yml +7 -0
- data/resources/locales/af/numbers.yml +36 -36
- data/resources/locales/af/plurals.yml +2 -3
- data/resources/locales/af/units.yml +75 -75
- data/resources/locales/ar/calendars.yml +149 -148
- data/resources/locales/ar/languages.yml +501 -501
- data/resources/locales/ar/layout.yml +5 -0
- data/resources/locales/ar/lists.yml +7 -0
- data/resources/locales/ar/numbers.yml +31 -31
- data/resources/locales/ar/plurals.yml +2 -9
- data/resources/locales/ar/units.yml +220 -220
- data/resources/locales/ca/calendars.yml +78 -77
- data/resources/locales/ca/languages.yml +199 -199
- data/resources/locales/ca/layout.yml +5 -0
- data/resources/locales/ca/lists.yml +7 -0
- data/resources/locales/ca/numbers.yml +36 -36
- data/resources/locales/ca/plurals.yml +2 -3
- data/resources/locales/ca/units.yml +108 -108
- data/resources/locales/cs/calendars.yml +141 -140
- data/resources/locales/cs/languages.yml +399 -399
- data/resources/locales/cs/layout.yml +5 -0
- data/resources/locales/cs/lists.yml +7 -0
- data/resources/locales/cs/numbers.yml +41 -41
- data/resources/locales/cs/plurals.yml +2 -3
- data/resources/locales/cs/units.yml +142 -142
- data/resources/locales/da/calendars.yml +73 -73
- data/resources/locales/da/languages.yml +36 -36
- data/resources/locales/da/layout.yml +5 -0
- data/resources/locales/da/lists.yml +7 -0
- data/resources/locales/da/numbers.yml +37 -37
- data/resources/locales/da/plurals.yml +2 -3
- data/resources/locales/da/units.yml +97 -97
- data/resources/locales/de/calendars.yml +71 -71
- data/resources/locales/de/languages.yml +51 -51
- data/resources/locales/de/layout.yml +5 -0
- data/resources/locales/de/lists.yml +7 -0
- data/resources/locales/de/numbers.yml +36 -36
- data/resources/locales/de/plurals.yml +2 -3
- data/resources/locales/de/units.yml +108 -108
- data/resources/locales/el/calendars.yml +213 -212
- data/resources/locales/el/languages.yml +520 -520
- data/resources/locales/el/layout.yml +5 -0
- data/resources/locales/el/lists.yml +7 -0
- data/resources/locales/el/numbers.yml +39 -39
- data/resources/locales/el/plurals.yml +2 -3
- data/resources/locales/el/units.yml +143 -143
- data/resources/locales/en/calendars.yml +66 -65
- data/resources/locales/en/languages.yml +24 -24
- data/resources/locales/en/layout.yml +5 -0
- data/resources/locales/en/lists.yml +7 -0
- data/resources/locales/en/numbers.yml +27 -27
- data/resources/locales/en/plurals.yml +2 -3
- data/resources/locales/en/units.yml +94 -94
- data/resources/locales/es/calendars.yml +80 -79
- data/resources/locales/es/languages.yml +139 -139
- data/resources/locales/es/layout.yml +5 -0
- data/resources/locales/es/lists.yml +7 -0
- data/resources/locales/es/numbers.yml +36 -36
- data/resources/locales/es/plurals.yml +2 -3
- data/resources/locales/es/units.yml +96 -96
- data/resources/locales/eu/calendars.yml +68 -67
- data/resources/locales/eu/languages.yml +11 -11
- data/resources/locales/eu/layout.yml +5 -0
- data/resources/locales/eu/lists.yml +7 -0
- data/resources/locales/eu/numbers.yml +36 -36
- data/resources/locales/eu/plurals.yml +2 -3
- data/resources/locales/eu/units.yml +80 -80
- data/resources/locales/fa/calendars.yml +223 -222
- data/resources/locales/fa/languages.yml +489 -489
- data/resources/locales/fa/layout.yml +5 -0
- data/resources/locales/fa/lists.yml +7 -0
- data/resources/locales/fa/numbers.yml +26 -26
- data/resources/locales/fa/plurals.yml +2 -3
- data/resources/locales/fa/units.yml +122 -122
- data/resources/locales/fi/calendars.yml +87 -87
- data/resources/locales/fi/languages.yml +86 -86
- data/resources/locales/fi/layout.yml +5 -0
- data/resources/locales/fi/lists.yml +7 -0
- data/resources/locales/fi/numbers.yml +41 -41
- data/resources/locales/fi/plurals.yml +2 -3
- data/resources/locales/fi/units.yml +124 -124
- data/resources/locales/fil/calendars.yml +68 -67
- data/resources/locales/fil/languages.yml +19 -19
- data/resources/locales/fil/layout.yml +5 -0
- data/resources/locales/fil/lists.yml +7 -0
- data/resources/locales/fil/numbers.yml +27 -27
- data/resources/locales/fil/plurals.yml +2 -3
- data/resources/locales/fil/units.yml +80 -80
- data/resources/locales/fr/calendars.yml +83 -83
- data/resources/locales/fr/languages.yml +117 -117
- data/resources/locales/fr/layout.yml +5 -0
- data/resources/locales/fr/lists.yml +7 -0
- data/resources/locales/fr/numbers.yml +37 -37
- data/resources/locales/fr/plurals.yml +2 -3
- data/resources/locales/fr/units.yml +80 -80
- data/resources/locales/he/calendars.yml +155 -154
- data/resources/locales/he/languages.yml +282 -282
- data/resources/locales/he/layout.yml +5 -0
- data/resources/locales/he/lists.yml +7 -0
- data/resources/locales/he/numbers.yml +27 -27
- data/resources/locales/he/plurals.yml +2 -3
- data/resources/locales/he/units.yml +122 -122
- data/resources/locales/hi/calendars.yml +132 -131
- data/resources/locales/hi/languages.yml +511 -511
- data/resources/locales/hi/layout.yml +5 -0
- data/resources/locales/hi/lists.yml +7 -0
- data/resources/locales/hi/numbers.yml +27 -27
- data/resources/locales/hi/plurals.yml +2 -3
- data/resources/locales/hi/units.yml +122 -122
- data/resources/locales/hu/calendars.yml +121 -120
- data/resources/locales/hu/languages.yml +214 -214
- data/resources/locales/hu/layout.yml +5 -0
- data/resources/locales/hu/lists.yml +7 -0
- data/resources/locales/hu/numbers.yml +39 -39
- data/resources/locales/hu/plurals.yml +2 -3
- data/resources/locales/hu/units.yml +102 -102
- data/resources/locales/id/calendars.yml +68 -67
- data/resources/locales/id/languages.yml +21 -21
- data/resources/locales/id/layout.yml +5 -0
- data/resources/locales/id/lists.yml +7 -0
- data/resources/locales/id/numbers.yml +37 -37
- data/resources/locales/id/plurals.yml +2 -3
- data/resources/locales/id/units.yml +73 -73
- data/resources/locales/it/calendars.yml +81 -80
- data/resources/locales/it/languages.yml +20 -20
- data/resources/locales/it/layout.yml +5 -0
- data/resources/locales/it/lists.yml +7 -0
- data/resources/locales/it/numbers.yml +36 -36
- data/resources/locales/it/plurals.yml +2 -3
- data/resources/locales/it/units.yml +94 -94
- data/resources/locales/ja/calendars.yml +123 -122
- data/resources/locales/ja/languages.yml +516 -516
- data/resources/locales/ja/layout.yml +5 -0
- data/resources/locales/ja/lists.yml +7 -0
- data/resources/locales/ja/numbers.yml +38 -38
- data/resources/locales/ja/plurals.yml +2 -3
- data/resources/locales/ja/units.yml +108 -108
- data/resources/locales/ko/calendars.yml +141 -140
- data/resources/locales/ko/languages.yml +509 -509
- data/resources/locales/ko/layout.yml +5 -0
- data/resources/locales/ko/lists.yml +7 -0
- data/resources/locales/ko/numbers.yml +37 -37
- data/resources/locales/ko/plurals.yml +2 -3
- data/resources/locales/ko/units.yml +108 -108
- data/resources/locales/ms/calendars.yml +68 -67
- data/resources/locales/ms/languages.yml +19 -19
- data/resources/locales/ms/layout.yml +5 -0
- data/resources/locales/ms/lists.yml +7 -0
- data/resources/locales/ms/numbers.yml +26 -26
- data/resources/locales/ms/plurals.yml +2 -3
- data/resources/locales/ms/units.yml +73 -73
- data/resources/locales/nb/calendars.yml +78 -78
- data/resources/locales/nb/languages.yml +93 -93
- data/resources/locales/nb/layout.yml +5 -0
- data/resources/locales/nb/lists.yml +7 -0
- data/resources/locales/nb/numbers.yml +37 -37
- data/resources/locales/nb/plurals.yml +2 -3
- data/resources/locales/nb/units.yml +99 -99
- data/resources/locales/nl/calendars.yml +67 -67
- data/resources/locales/nl/languages.yml +30 -30
- data/resources/locales/nl/layout.yml +5 -0
- data/resources/locales/nl/lists.yml +7 -0
- data/resources/locales/nl/numbers.yml +36 -36
- data/resources/locales/nl/plurals.yml +2 -3
- data/resources/locales/nl/units.yml +87 -87
- data/resources/locales/pl/calendars.yml +102 -101
- data/resources/locales/pl/languages.yml +139 -139
- data/resources/locales/pl/layout.yml +5 -0
- data/resources/locales/pl/lists.yml +7 -0
- data/resources/locales/pl/numbers.yml +41 -41
- data/resources/locales/pl/plurals.yml +2 -5
- data/resources/locales/pl/units.yml +149 -149
- data/resources/locales/pt/calendars.yml +83 -83
- data/resources/locales/pt/languages.yml +161 -161
- data/resources/locales/pt/layout.yml +5 -0
- data/resources/locales/pt/lists.yml +7 -0
- data/resources/locales/pt/numbers.yml +39 -39
- data/resources/locales/pt/plurals.yml +2 -3
- data/resources/locales/pt/units.yml +110 -110
- data/resources/locales/ru/calendars.yml +213 -212
- data/resources/locales/ru/languages.yml +511 -511
- data/resources/locales/ru/layout.yml +5 -0
- data/resources/locales/ru/lists.yml +7 -0
- data/resources/locales/ru/numbers.yml +40 -40
- data/resources/locales/ru/plurals.yml +2 -5
- data/resources/locales/ru/units.yml +192 -192
- data/resources/locales/sv/calendars.yml +85 -85
- data/resources/locales/sv/languages.yml +108 -108
- data/resources/locales/sv/layout.yml +5 -0
- data/resources/locales/sv/lists.yml +7 -0
- data/resources/locales/sv/numbers.yml +39 -39
- data/resources/locales/sv/plurals.yml +2 -3
- data/resources/locales/sv/units.yml +116 -116
- data/resources/locales/th/calendars.yml +172 -171
- data/resources/locales/th/languages.yml +510 -510
- data/resources/locales/th/layout.yml +5 -0
- data/resources/locales/th/lists.yml +7 -0
- data/resources/locales/th/numbers.yml +38 -38
- data/resources/locales/th/plurals.yml +2 -3
- data/resources/locales/th/units.yml +107 -107
- data/resources/locales/tr/calendars.yml +117 -116
- data/resources/locales/tr/languages.yml +143 -143
- data/resources/locales/tr/layout.yml +5 -0
- data/resources/locales/tr/lists.yml +7 -0
- data/resources/locales/tr/numbers.yml +37 -37
- data/resources/locales/tr/plurals.yml +2 -3
- data/resources/locales/tr/units.yml +98 -98
- data/resources/locales/uk/calendars.yml +187 -186
- data/resources/locales/uk/languages.yml +520 -520
- data/resources/locales/uk/layout.yml +5 -0
- data/resources/locales/uk/lists.yml +7 -0
- data/resources/locales/uk/numbers.yml +44 -44
- data/resources/locales/uk/plurals.yml +2 -5
- data/resources/locales/uk/units.yml +192 -192
- data/resources/locales/ur/calendars.yml +112 -111
- data/resources/locales/ur/languages.yml +164 -164
- data/resources/locales/ur/layout.yml +5 -0
- data/resources/locales/ur/lists.yml +7 -0
- data/resources/locales/ur/numbers.yml +27 -27
- data/resources/locales/ur/plurals.yml +2 -3
- data/resources/locales/ur/units.yml +136 -136
- data/resources/locales/zh/calendars.yml +212 -211
- data/resources/locales/zh/languages.yml +506 -506
- data/resources/locales/zh/layout.yml +5 -0
- data/resources/locales/zh/lists.yml +7 -0
- data/resources/locales/zh/numbers.yml +37 -37
- data/resources/locales/zh/plurals.yml +2 -3
- data/resources/locales/zh/units.yml +108 -108
- data/resources/locales/zh-Hant/calendars.yml +159 -158
- data/resources/locales/zh-Hant/languages.yml +510 -510
- data/resources/locales/zh-Hant/layout.yml +5 -0
- data/resources/locales/zh-Hant/lists.yml +7 -0
- data/resources/locales/zh-Hant/numbers.yml +38 -38
- data/resources/locales/zh-Hant/plurals.yml +2 -3
- data/resources/locales/zh-Hant/units.yml +108 -108
- data/spec/bidi/bidi_spec.rb +72 -0
- data/spec/bidi/classpath_bidi_test.txt +217202 -0
- data/spec/collation/tailoring_tests/da.txt +1 -1
- data/spec/collation/tailoring_tests/fi.txt +1 -7
- data/spec/collation/tailoring_tests/zh-Hant.txt +1 -1
- data/spec/formatters/list_formatter_spec.rb +119 -0
- data/spec/localized/localized_array_spec.rb +28 -0
- data/spec/localized/localized_hash_spec.rb +22 -0
- data/spec/localized/localized_number_spec.rb +3 -3
- data/spec/localized/localized_string_spec.rb +52 -1
- data/spec/localized/localized_symbol_spec.rb +7 -0
- data/spec/normalization/base_spec.rb +2 -4
- data/spec/shared/languages_spec.rb +21 -0
- data/spec/shared/numbers_spec.rb +4 -4
- data/spec/spec_helper.rb +3 -1
- data/spec/utils/yaml/t.gif +0 -0
- data/spec/utils/yaml/t.yaml +5 -0
- data/spec/utils/yaml/yaml_spec.rb +426 -0
- metadata +82 -2
@@ -0,0 +1,426 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Copyright 2012 Twitter, Inc
|
4
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
5
|
+
|
6
|
+
# This code was adapted from the ya2yaml gem, maintained by Akira Funai.
|
7
|
+
# https://github.com/afunai/ya2yaml
|
8
|
+
|
9
|
+
# Copyright (c) 2006 Akira FUNAI <funai.akira@gmail.com>
|
10
|
+
#
|
11
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
12
|
+
# copy of this software and associated documentation files (the "Software"),
|
13
|
+
# to deal in the Software without restriction, including without limitation
|
14
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
15
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
16
|
+
# Software is furnished to do so, subject to the following conditions:
|
17
|
+
#
|
18
|
+
# The above copyright notice and this permission notice shall be included in
|
19
|
+
# all copies or substantial portions of the Software.
|
20
|
+
#
|
21
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
24
|
+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
26
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
27
|
+
# DEALINGS IN THE SOFTWARE.
|
28
|
+
|
29
|
+
require 'spec_helper'
|
30
|
+
require 'yaml'
|
31
|
+
|
32
|
+
# Psych doesn't handle Unicode characters properly, have to use Syck instead.
|
33
|
+
YAML::ENGINE.yamler = 'syck' if YAML.const_defined?(:ENGINE)
|
34
|
+
|
35
|
+
# There's an incompatibility in how ruby handles struct dumps
|
36
|
+
# between versions that's beyond our scope.
|
37
|
+
# (One uses strings internally, the other symbols.)
|
38
|
+
# This just enables tests to pass.
|
39
|
+
class << Struct
|
40
|
+
alias yaml_new_without_indifferent_keys yaml_new
|
41
|
+
def yaml_new(klass, tag, val)
|
42
|
+
val.keys.each { |k, v| val[k.to_sym] = val.delete(k) }
|
43
|
+
yaml_new_without_indifferent_keys(klass, tag, val)
|
44
|
+
end
|
45
|
+
end if RUBY_VERSION >= "1.9" && RUBY_VERSION <= "1.9.1" # yaml_new is deprecated in 1.9.2 and later
|
46
|
+
|
47
|
+
STRUCT_KLASS = Struct::new('Foo', :bar, :buz)
|
48
|
+
class Moo
|
49
|
+
attr_accessor :val1, :val2
|
50
|
+
def initialize(val1, val2)
|
51
|
+
@val1 = val1
|
52
|
+
@val2 = val2
|
53
|
+
end
|
54
|
+
def ==(k)
|
55
|
+
(k.class == self.class) &&
|
56
|
+
(k.val1 == self.val1) &&
|
57
|
+
(k.val2 == self.val2)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
describe TwitterCldr::Utils do
|
63
|
+
describe '#yaml' do
|
64
|
+
before(:all) do
|
65
|
+
@text = File.open(File.join(File.dirname(__FILE__), 't.yaml'), 'r') { |f| f.read }
|
66
|
+
@gif = File.open(File.join(File.dirname(__FILE__), 't.gif'), 'rb') { |f| f.read }
|
67
|
+
@struct = STRUCT_KLASS.new('barbarbar', STRUCT_KLASS.new('baaaar', 12345))
|
68
|
+
@klass = Moo.new('boobooboo', Time.local(2009, 2, 9, 16, 44, 10))
|
69
|
+
end
|
70
|
+
|
71
|
+
it "tests available options" do
|
72
|
+
opt = { :syck_compatible => true }
|
73
|
+
'foobar'.localize.to_yaml(opt)
|
74
|
+
|
75
|
+
# dump should not change the option hash
|
76
|
+
opt.should == { :syck_compatible => true }
|
77
|
+
|
78
|
+
[
|
79
|
+
[
|
80
|
+
{},
|
81
|
+
"--- \n- \"\\u0086\"\n- |-\n a\xe2\x80\xa8 b\xe2\x80\xa9 c\n- |4-\n abc\n xyz\n",
|
82
|
+
],
|
83
|
+
[
|
84
|
+
{ :indent_size => 4 },
|
85
|
+
"--- \n- \"\\u0086\"\n- |-\n a\xe2\x80\xa8 b\xe2\x80\xa9 c\n- |8-\n abc\n xyz\n",
|
86
|
+
],
|
87
|
+
[
|
88
|
+
{ :minimum_block_length => 16 },
|
89
|
+
"--- \n- \"\\u0086\"\n- \"a\\Lb\\Pc\"\n- \" abc\\nxyz\"\n",
|
90
|
+
],
|
91
|
+
[
|
92
|
+
{ :printable_with_syck => true },
|
93
|
+
"--- \n- \"\\u0086\"\n- |-\n a\xe2\x80\xa8 b\xe2\x80\xa9 c\n- \" abc\\n\\\n xyz\"\n",
|
94
|
+
],
|
95
|
+
[
|
96
|
+
{ :escape_b_specific => true },
|
97
|
+
"--- \n- \"\\u0086\"\n- \"a\\Lb\\Pc\"\n- |4-\n abc\n xyz\n",
|
98
|
+
],
|
99
|
+
[
|
100
|
+
{ :escape_as_utf8 => true },
|
101
|
+
"--- \n- \"\\xc2\\x86\"\n- |-\n a\xe2\x80\xa8 b\xe2\x80\xa9 c\n- |4-\n abc\n xyz\n",
|
102
|
+
],
|
103
|
+
[
|
104
|
+
{ :syck_compatible => true },
|
105
|
+
"--- \n- \"\\xc2\\x86\"\n- \"a\\xe2\\x80\\xa8b\\xe2\\x80\\xa9c\"\n- \" abc\\n\\\n xyz\"\n",
|
106
|
+
],
|
107
|
+
].each do |opt, yaml|
|
108
|
+
["\xc2\x86", "a\xe2\x80\xa8b\xe2\x80\xa9c", " abc\nxyz"].localize.to_yaml(opt).should == yaml
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it "tests hash order" do
|
113
|
+
[
|
114
|
+
[
|
115
|
+
nil,
|
116
|
+
"--- \na: 1\nb: 2\nc: 3\n",
|
117
|
+
],
|
118
|
+
[
|
119
|
+
[],
|
120
|
+
"--- \na: 1\nb: 2\nc: 3\n",
|
121
|
+
],
|
122
|
+
[
|
123
|
+
['c', 'b', 'a'],
|
124
|
+
"--- \nc: 3\nb: 2\na: 1\n",
|
125
|
+
],
|
126
|
+
[
|
127
|
+
['b'],
|
128
|
+
"--- \nb: 2\na: 1\nc: 3\n",
|
129
|
+
],
|
130
|
+
].each do |hash_order, yaml|
|
131
|
+
TwitterCldr::Utils::YAML.dump({ 'a' => 1, 'c' => 3, 'b' => 2 }, :hash_order => hash_order).should == yaml
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
if RUBY_VERSION >= "1.9"
|
136
|
+
it "should preserve hash order" do
|
137
|
+
h = { 'a' => 1, 'c' => 3, 'b' => 2 }
|
138
|
+
TwitterCldr::Utils::YAML.dump(h, :preserve_order => true).should == "--- \na: 1\nc: 3\nb: 2\n"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it "tests normalization of line breaks" do
|
143
|
+
[
|
144
|
+
["\n\n\n\n", "--- \"\\n\\n\\n\\n\"\n"],
|
145
|
+
["\r\n\r\n\r\n", "--- \"\\n\\n\\n\"\n"],
|
146
|
+
["\r\n\n\n", "--- \"\\n\\n\\n\"\n"],
|
147
|
+
["\n\r\n\n", "--- \"\\n\\n\\n\"\n"],
|
148
|
+
["\n\n\r\n", "--- \"\\n\\n\\n\"\n"],
|
149
|
+
["\n\n\n\r", "--- \"\\n\\n\\n\\n\"\n"],
|
150
|
+
["\r\r\n\r", "--- \"\\n\\n\\n\"\n"],
|
151
|
+
["\r\r\r\r", "--- \"\\n\\n\\n\\n\"\n"],
|
152
|
+
["\r\xc2\x85\r\n", "--- \"\\n\\n\\n\"\n"],
|
153
|
+
["\r\xe2\x80\xa8\r\n", "--- \"\\n\\L\\n\"\n"],
|
154
|
+
["\r\xe2\x80\xa9\r\n", "--- \"\\n\\P\\n\"\n"],
|
155
|
+
].each do |src, yaml|
|
156
|
+
src.localize.to_yaml(:minimum_block_length => 16).should == yaml
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
it "tests structs" do
|
161
|
+
[
|
162
|
+
[Struct.new('Hoge', :foo).new(123), "--- !ruby/struct:Hoge \n foo: 123\n", ],
|
163
|
+
[Struct.new(:foo).new(123), "--- !ruby/struct: \n foo: 123\n", ],
|
164
|
+
].each do |src, yaml|
|
165
|
+
TwitterCldr::Utils::YAML.dump(src).should == yaml
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
it "tests successful roundtrip of single byte characters" do
|
170
|
+
("\x00".."\x7f").each do |c|
|
171
|
+
y = c.localize.to_yaml
|
172
|
+
r = YAML.load(y)
|
173
|
+
(c == "\r" ? "\n" : c).should == r # "\r" is normalized as "\n"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
it "tests successful roundtrip of multi-byte characters" do
|
178
|
+
[
|
179
|
+
0x80,
|
180
|
+
0x85,
|
181
|
+
0xa0,
|
182
|
+
0x07ff,
|
183
|
+
0x0800,
|
184
|
+
0x0fff,
|
185
|
+
0x1000,
|
186
|
+
0x2028,
|
187
|
+
0x2029,
|
188
|
+
0xcfff,
|
189
|
+
0xd000,
|
190
|
+
0xd7ff,
|
191
|
+
0xe000,
|
192
|
+
0xfffd,
|
193
|
+
0x10000,
|
194
|
+
0x3ffff,
|
195
|
+
0x40000,
|
196
|
+
0xfffff,
|
197
|
+
0x100000,
|
198
|
+
0x10ffff,
|
199
|
+
].each do |ucs_code|
|
200
|
+
[-1, 0, 1].each do |ofs|
|
201
|
+
(c = [ucs_code + ofs].pack('U'))
|
202
|
+
next unless c.valid_encoding? if c.respond_to? :valid_encoding?
|
203
|
+
c_hex = c.unpack('H8')
|
204
|
+
y = c.localize.to_yaml(
|
205
|
+
:escape_b_specific => true,
|
206
|
+
:escape_as_utf8 => true
|
207
|
+
)
|
208
|
+
r = YAML.load(y)
|
209
|
+
(c == "\xc2\x85" ? "\n" : c).should == r # "\N" is normalized as "\n"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
it "tests successful roundtrip of ambiguous strings" do
|
215
|
+
[
|
216
|
+
'true',
|
217
|
+
'false',
|
218
|
+
'TRUE',
|
219
|
+
'FALSE',
|
220
|
+
'Y',
|
221
|
+
'N',
|
222
|
+
'y',
|
223
|
+
'n',
|
224
|
+
'on',
|
225
|
+
'off',
|
226
|
+
true,
|
227
|
+
false,
|
228
|
+
'0b0101',
|
229
|
+
'-0b0101',
|
230
|
+
0b0101,
|
231
|
+
-0b0101,
|
232
|
+
'031',
|
233
|
+
'-031',
|
234
|
+
031,
|
235
|
+
-031,
|
236
|
+
'123.001e-1',
|
237
|
+
'123.01',
|
238
|
+
'123',
|
239
|
+
123.001e-1,
|
240
|
+
123.01,
|
241
|
+
123,
|
242
|
+
'-123.001e-1',
|
243
|
+
'-123.01',
|
244
|
+
'-123',
|
245
|
+
-123.001e-1,
|
246
|
+
-123.01,
|
247
|
+
-123,
|
248
|
+
'INF',
|
249
|
+
'inf',
|
250
|
+
'NaN',
|
251
|
+
'nan',
|
252
|
+
'0xfe2a',
|
253
|
+
'-0xfe2a',
|
254
|
+
0xfe2a,
|
255
|
+
-0xfe2a,
|
256
|
+
'1:23:32.0200',
|
257
|
+
'1:23:32',
|
258
|
+
'-1:23:32.0200',
|
259
|
+
'-1:23:32',
|
260
|
+
'<<',
|
261
|
+
'~',
|
262
|
+
'null',
|
263
|
+
'nUll',
|
264
|
+
'Null',
|
265
|
+
'NULL',
|
266
|
+
'',
|
267
|
+
nil,
|
268
|
+
'2006-09-12',
|
269
|
+
'2006-09-11T17:28:07Z',
|
270
|
+
'2006-09-11T17:28:07+09:00',
|
271
|
+
'2006-09-11 17:28:07.662694 +09:00',
|
272
|
+
'=',
|
273
|
+
].each do |c|
|
274
|
+
['', 'hoge'].each do |ext|
|
275
|
+
src = (c.class == String) ? (c + ext) : c
|
276
|
+
y = TwitterCldr::Utils::YAML.dump(src, :escape_as_utf8 => true)
|
277
|
+
r = YAML.load(y)
|
278
|
+
src.should == r
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
it "tests successfull roundtrip for a few special characters" do
|
284
|
+
chars = "aあ\t\-\?,\[\{\#&\*!\|>'\"\%\@\`.\\ \n\xc2\xa0\xe2\x80\xa8".split('')
|
285
|
+
|
286
|
+
chars.each do |i|
|
287
|
+
chars.each do |j|
|
288
|
+
chars.each do |k|
|
289
|
+
src = [i, j, k].join
|
290
|
+
y = TwitterCldr::Utils::YAML.dump(src,
|
291
|
+
:printable_with_syck => true,
|
292
|
+
:escape_b_specific => true,
|
293
|
+
:escape_as_utf8 => true
|
294
|
+
)
|
295
|
+
r = YAML.load(y)
|
296
|
+
src.should == r
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
# patch by pawel.j.radecki at gmail.com. thanks!
|
303
|
+
it "tests successful roundtrip_symbols" do
|
304
|
+
symbol1 = :"Batman: The Dark Knight - Why So Serious?!"
|
305
|
+
result_symbol1 = YAML.load(TwitterCldr::Utils::YAML.dump(symbol1))
|
306
|
+
symbol1.should == result_symbol1
|
307
|
+
|
308
|
+
symbol2 = :"Batman: The Dark Knight - \"Why So Serious?!\""
|
309
|
+
result_symbol2 = YAML.load(TwitterCldr::Utils::YAML.dump(symbol2))
|
310
|
+
symbol2.should == result_symbol2
|
311
|
+
end
|
312
|
+
|
313
|
+
it "tests successful roundtrip of natural symbols" do
|
314
|
+
symbol1 = :"Batman: The Dark Knight - Why So Serious?!"
|
315
|
+
result_symbol1 = YAML.load(TwitterCldr::Utils::YAML.dump(symbol1, :use_natural_symbols => true))
|
316
|
+
symbol1.should == result_symbol1
|
317
|
+
|
318
|
+
symbol2 = :batman
|
319
|
+
TwitterCldr::Utils::YAML.dump(symbol2, :use_natural_symbols => true).should include(":batman")
|
320
|
+
result_symbol2 = YAML.load(TwitterCldr::Utils::YAML.dump(symbol2, :use_natural_symbols => true))
|
321
|
+
symbol2.should == result_symbol2
|
322
|
+
end
|
323
|
+
|
324
|
+
it "tests successful roundtrip of mixed types" do
|
325
|
+
objects = [
|
326
|
+
[],
|
327
|
+
[1],
|
328
|
+
{},
|
329
|
+
{'foo' => 'bar'},
|
330
|
+
nil,
|
331
|
+
'hoge',
|
332
|
+
"abc\nxyz\n",
|
333
|
+
(s = "\xff\xff"),
|
334
|
+
true,
|
335
|
+
false,
|
336
|
+
1000,
|
337
|
+
1000.1,
|
338
|
+
-1000,
|
339
|
+
-1000.1,
|
340
|
+
Date.new(2009, 2, 9),
|
341
|
+
Time.local(2009, 2, 9, 16, 35, 22),
|
342
|
+
:foo,
|
343
|
+
1..10,
|
344
|
+
/abc\nxyz/i,
|
345
|
+
@struct,
|
346
|
+
@klass,
|
347
|
+
]
|
348
|
+
s.force_encoding("BINARY") if s.respond_to? :force_encoding
|
349
|
+
|
350
|
+
objects.each do |obj|
|
351
|
+
src = case obj.class.to_s
|
352
|
+
when 'Array'
|
353
|
+
(obj.length) == 0 ? [] : objects
|
354
|
+
when 'Hash'
|
355
|
+
if (obj.length) == 0
|
356
|
+
{}
|
357
|
+
else
|
358
|
+
h = {}
|
359
|
+
c = 0
|
360
|
+
objects.each do |val|
|
361
|
+
h[c] = {}
|
362
|
+
objects.each {|key|
|
363
|
+
h[c][key] = val unless (key.class == Hash || key.class == Moo)
|
364
|
+
}
|
365
|
+
c += 1
|
366
|
+
end
|
367
|
+
h
|
368
|
+
end
|
369
|
+
else
|
370
|
+
obj
|
371
|
+
end
|
372
|
+
y = TwitterCldr::Utils::YAML.dump(src, :syck_compatible => true)
|
373
|
+
r = YAML.load(y)
|
374
|
+
src.should == r
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
it "tests successful roundtrip of nested types" do
|
379
|
+
[
|
380
|
+
[1, 2, ['c', 'd', [[['e']], []], 'f'], 3, Time.local(2009, 2, 9, 17, 9), [[:foo]], nil, true, false, [], {}, {[123, 223]=>456}, {[1]=>2, 'a'=>'b', 'c' => [9, 9, 9], Time.local(2009, 2, 9, 17, 10) => 'hoge'}, ],
|
381
|
+
[],
|
382
|
+
{[123, 223]=>456},
|
383
|
+
{},
|
384
|
+
{'foo' => {1 => {2=>3, 4=>5}, 6 => [7, 8]}},
|
385
|
+
"abc",
|
386
|
+
" abc\n def\ndef\ndef\ndef\ndef\n",
|
387
|
+
"abc\n def\ndef\n",
|
388
|
+
"abc\n def\ndef\n\n",
|
389
|
+
"abc\n def\ndef\n\n ",
|
390
|
+
"abc\n def\ndef\n \n",
|
391
|
+
"abc\n def\ndef \n \n",
|
392
|
+
"abc\n def\ndef \n \n ",
|
393
|
+
' ほげほげほげ',
|
394
|
+
{"ほげ\nほげ\n ほげ" => 123},
|
395
|
+
[["ほげ\nほげ\n ほげ"]],
|
396
|
+
"ほげh\x4fge\nほげ\nほげ",
|
397
|
+
[{'ほげ'=>'abc', "ほげ\nほげ"=>'ほげ'}, 'ほげ', @text],
|
398
|
+
[Date.today, -9.011, 0.023, 4, -5, {1=>-2, -1=>@text, '_foo'=>'bar', 'ぬお-ぬお'=>321}],
|
399
|
+
{1=>-2, -1=>@gif, '_foo'=>'bar', 'ぬお-ぬお'=>321},
|
400
|
+
].each do |src|
|
401
|
+
y = TwitterCldr::Utils::YAML.dump(src, :syck_compatible => true)
|
402
|
+
r = YAML.load(y)
|
403
|
+
src.should == r
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
it "guards against circular references" do
|
408
|
+
a = []
|
409
|
+
a << a
|
410
|
+
lambda { TwitterCldr::Utils::YAML.dump(a) }.should raise_error(ArgumentError)
|
411
|
+
end
|
412
|
+
|
413
|
+
it "tests binary dumps" do
|
414
|
+
unless RUBY_VERSION < '1.9.0'
|
415
|
+
y = nil
|
416
|
+
|
417
|
+
lambda { y = TwitterCldr::Utils::YAML.dump('日本語'.force_encoding('ASCII-8BIT')) }.should_not raise_error
|
418
|
+
y.should == "--- !binary |\n 5pel5pys6Kqe\n\n"
|
419
|
+
|
420
|
+
lambda { y = TwitterCldr::Utils::YAML.dump('日本語'.encode('EUC-JP').force_encoding('UTF-8')) }.should_not raise_error
|
421
|
+
y.should == "--- !binary |\n xvzL3Ljs\n\n"
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
end
|
426
|
+
end
|