1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,140 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-/* |
|
4 |
- * This file is part of the Symfony package. |
|
5 |
- * |
|
6 |
- * (c) Fabien Potencier <fabien@symfony.com> |
|
7 |
- * |
|
8 |
- * For the full copyright and license information, please view the LICENSE |
|
9 |
- * file that was distributed with this source code. |
|
10 |
- */ |
|
11 |
- |
|
12 |
-namespace Symfony\Component\Translation\Tests; |
|
13 |
- |
|
14 |
-use PHPUnit\Framework\TestCase; |
|
15 |
-use Symfony\Component\Translation\MessageSelector; |
|
16 |
- |
|
17 |
-/** |
|
18 |
- * @group legacy |
|
19 |
- */ |
|
20 |
-class MessageSelectorTest extends TestCase |
|
21 |
-{ |
|
22 |
- /** |
|
23 |
- * @dataProvider getChooseTests |
|
24 |
- */ |
|
25 |
- public function testChoose($expected, $id, $number) |
|
26 |
- { |
|
27 |
- $selector = new MessageSelector(); |
|
28 |
- |
|
29 |
- $this->assertEquals($expected, $selector->choose($id, $number, 'en')); |
|
30 |
- } |
|
31 |
- |
|
32 |
- public function testReturnMessageIfExactlyOneStandardRuleIsGiven() |
|
33 |
- { |
|
34 |
- $selector = new MessageSelector(); |
|
35 |
- |
|
36 |
- $this->assertEquals('There are two apples', $selector->choose('There are two apples', 2, 'en')); |
|
37 |
- } |
|
38 |
- |
|
39 |
- /** |
|
40 |
- * @dataProvider getNonMatchingMessages |
|
41 |
- * @expectedException \Symfony\Component\Translation\Exception\InvalidArgumentException |
|
42 |
- */ |
|
43 |
- public function testThrowExceptionIfMatchingMessageCannotBeFound($id, $number) |
|
44 |
- { |
|
45 |
- $selector = new MessageSelector(); |
|
46 |
- |
|
47 |
- $selector->choose($id, $number, 'en'); |
|
48 |
- } |
|
49 |
- |
|
50 |
- public function getNonMatchingMessages() |
|
51 |
- { |
|
52 |
- return [ |
|
53 |
- ['{0} There are no apples|{1} There is one apple', 2], |
|
54 |
- ['{1} There is one apple|]1,Inf] There are %count% apples', 0], |
|
55 |
- ['{1} There is one apple|]2,Inf] There are %count% apples', 2], |
|
56 |
- ['{0} There are no apples|There is one apple', 2], |
|
57 |
- ]; |
|
58 |
- } |
|
59 |
- |
|
60 |
- public function getChooseTests() |
|
61 |
- { |
|
62 |
- return [ |
|
63 |
- ['There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0], |
|
64 |
- ['There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0], |
|
65 |
- ['There are no apples', '{0}There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0], |
|
66 |
- |
|
67 |
- ['There is one apple', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 1], |
|
68 |
- |
|
69 |
- ['There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10], |
|
70 |
- ['There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf]There are %count% apples', 10], |
|
71 |
- ['There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10], |
|
72 |
- |
|
73 |
- ['There are %count% apples', 'There is one apple|There are %count% apples', 0], |
|
74 |
- ['There is one apple', 'There is one apple|There are %count% apples', 1], |
|
75 |
- ['There are %count% apples', 'There is one apple|There are %count% apples', 10], |
|
76 |
- |
|
77 |
- ['There are %count% apples', 'one: There is one apple|more: There are %count% apples', 0], |
|
78 |
- ['There is one apple', 'one: There is one apple|more: There are %count% apples', 1], |
|
79 |
- ['There are %count% apples', 'one: There is one apple|more: There are %count% apples', 10], |
|
80 |
- |
|
81 |
- ['There are no apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 0], |
|
82 |
- ['There is one apple', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 1], |
|
83 |
- ['There are %count% apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 10], |
|
84 |
- |
|
85 |
- ['', '{0}|{1} There is one apple|]1,Inf] There are %count% apples', 0], |
|
86 |
- ['', '{0} There are no apples|{1}|]1,Inf] There are %count% apples', 1], |
|
87 |
- |
|
88 |
- // Indexed only tests which are Gettext PoFile* compatible strings. |
|
89 |
- ['There are %count% apples', 'There is one apple|There are %count% apples', 0], |
|
90 |
- ['There is one apple', 'There is one apple|There are %count% apples', 1], |
|
91 |
- ['There are %count% apples', 'There is one apple|There are %count% apples', 2], |
|
92 |
- |
|
93 |
- // Tests for float numbers |
|
94 |
- ['There is almost one apple', '{0} There are no apples|]0,1[ There is almost one apple|{1} There is one apple|[1,Inf] There is more than one apple', 0.7], |
|
95 |
- ['There is one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1], |
|
96 |
- ['There is more than one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1.7], |
|
97 |
- ['There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0], |
|
98 |
- ['There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0.0], |
|
99 |
- ['There are no apples', '{0.0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0], |
|
100 |
- |
|
101 |
- // Test texts with new-lines |
|
102 |
- // with double-quotes and \n in id & double-quotes and actual newlines in text |
|
103 |
- ["This is a text with a\n new-line in it. Selector = 0.", '{0}This is a text with a |
|
104 |
- new-line in it. Selector = 0.|{1}This is a text with a |
|
105 |
- new-line in it. Selector = 1.|[1,Inf]This is a text with a |
|
106 |
- new-line in it. Selector > 1.', 0], |
|
107 |
- // with double-quotes and \n in id and single-quotes and actual newlines in text |
|
108 |
- ["This is a text with a\n new-line in it. Selector = 1.", '{0}This is a text with a |
|
109 |
- new-line in it. Selector = 0.|{1}This is a text with a |
|
110 |
- new-line in it. Selector = 1.|[1,Inf]This is a text with a |
|
111 |
- new-line in it. Selector > 1.', 1], |
|
112 |
- ["This is a text with a\n new-line in it. Selector > 1.", '{0}This is a text with a |
|
113 |
- new-line in it. Selector = 0.|{1}This is a text with a |
|
114 |
- new-line in it. Selector = 1.|[1,Inf]This is a text with a |
|
115 |
- new-line in it. Selector > 1.', 5], |
|
116 |
- // with double-quotes and id split accros lines |
|
117 |
- ['This is a text with a |
|
118 |
- new-line in it. Selector = 1.', '{0}This is a text with a |
|
119 |
- new-line in it. Selector = 0.|{1}This is a text with a |
|
120 |
- new-line in it. Selector = 1.|[1,Inf]This is a text with a |
|
121 |
- new-line in it. Selector > 1.', 1], |
|
122 |
- // with single-quotes and id split accros lines |
|
123 |
- ['This is a text with a |
|
124 |
- new-line in it. Selector > 1.', '{0}This is a text with a |
|
125 |
- new-line in it. Selector = 0.|{1}This is a text with a |
|
126 |
- new-line in it. Selector = 1.|[1,Inf]This is a text with a |
|
127 |
- new-line in it. Selector > 1.', 5], |
|
128 |
- // with single-quotes and \n in text |
|
129 |
- ['This is a text with a\nnew-line in it. Selector = 0.', '{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.', 0], |
|
130 |
- // with double-quotes and id split accros lines |
|
131 |
- ["This is a text with a\nnew-line in it. Selector = 1.", "{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.", 1], |
|
132 |
- // esacape pipe |
|
133 |
- ['This is a text with | in it. Selector = 0.', '{0}This is a text with || in it. Selector = 0.|{1}This is a text with || in it. Selector = 1.', 0], |
|
134 |
- // Empty plural set (2 plural forms) from a .PO file |
|
135 |
- ['', '|', 1], |
|
136 |
- // Empty plural set (3 plural forms) from a .PO file |
|
137 |
- ['', '||', 1], |
|
138 |
- ]; |
|
139 |
- } |
|
140 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,140 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/* |
|
4 |
+ * This file is part of the Symfony package. |
|
5 |
+ * |
|
6 |
+ * (c) Fabien Potencier <fabien@symfony.com> |
|
7 |
+ * |
|
8 |
+ * For the full copyright and license information, please view the LICENSE |
|
9 |
+ * file that was distributed with this source code. |
|
10 |
+ */ |
|
11 |
+ |
|
12 |
+namespace Symfony\Component\Translation\Tests; |
|
13 |
+ |
|
14 |
+use PHPUnit\Framework\TestCase; |
|
15 |
+use Symfony\Component\Translation\MessageSelector; |
|
16 |
+ |
|
17 |
+/** |
|
18 |
+ * @group legacy |
|
19 |
+ */ |
|
20 |
+class MessageSelectorTest extends TestCase |
|
21 |
+{ |
|
22 |
+ /** |
|
23 |
+ * @dataProvider getChooseTests |
|
24 |
+ */ |
|
25 |
+ public function testChoose($expected, $id, $number) |
|
26 |
+ { |
|
27 |
+ $selector = new MessageSelector(); |
|
28 |
+ |
|
29 |
+ $this->assertEquals($expected, $selector->choose($id, $number, 'en')); |
|
30 |
+ } |
|
31 |
+ |
|
32 |
+ public function testReturnMessageIfExactlyOneStandardRuleIsGiven() |
|
33 |
+ { |
|
34 |
+ $selector = new MessageSelector(); |
|
35 |
+ |
|
36 |
+ $this->assertEquals('There are two apples', $selector->choose('There are two apples', 2, 'en')); |
|
37 |
+ } |
|
38 |
+ |
|
39 |
+ /** |
|
40 |
+ * @dataProvider getNonMatchingMessages |
|
41 |
+ * @expectedException \Symfony\Component\Translation\Exception\InvalidArgumentException |
|
42 |
+ */ |
|
43 |
+ public function testThrowExceptionIfMatchingMessageCannotBeFound($id, $number) |
|
44 |
+ { |
|
45 |
+ $selector = new MessageSelector(); |
|
46 |
+ |
|
47 |
+ $selector->choose($id, $number, 'en'); |
|
48 |
+ } |
|
49 |
+ |
|
50 |
+ public function getNonMatchingMessages() |
|
51 |
+ { |
|
52 |
+ return [ |
|
53 |
+ ['{0} There are no apples|{1} There is one apple', 2], |
|
54 |
+ ['{1} There is one apple|]1,Inf] There are %count% apples', 0], |
|
55 |
+ ['{1} There is one apple|]2,Inf] There are %count% apples', 2], |
|
56 |
+ ['{0} There are no apples|There is one apple', 2], |
|
57 |
+ ]; |
|
58 |
+ } |
|
59 |
+ |
|
60 |
+ public function getChooseTests() |
|
61 |
+ { |
|
62 |
+ return [ |
|
63 |
+ ['There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0], |
|
64 |
+ ['There are no apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0], |
|
65 |
+ ['There are no apples', '{0}There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 0], |
|
66 |
+ |
|
67 |
+ ['There is one apple', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 1], |
|
68 |
+ |
|
69 |
+ ['There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10], |
|
70 |
+ ['There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf]There are %count% apples', 10], |
|
71 |
+ ['There are %count% apples', '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples', 10], |
|
72 |
+ |
|
73 |
+ ['There are %count% apples', 'There is one apple|There are %count% apples', 0], |
|
74 |
+ ['There is one apple', 'There is one apple|There are %count% apples', 1], |
|
75 |
+ ['There are %count% apples', 'There is one apple|There are %count% apples', 10], |
|
76 |
+ |
|
77 |
+ ['There are %count% apples', 'one: There is one apple|more: There are %count% apples', 0], |
|
78 |
+ ['There is one apple', 'one: There is one apple|more: There are %count% apples', 1], |
|
79 |
+ ['There are %count% apples', 'one: There is one apple|more: There are %count% apples', 10], |
|
80 |
+ |
|
81 |
+ ['There are no apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 0], |
|
82 |
+ ['There is one apple', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 1], |
|
83 |
+ ['There are %count% apples', '{0} There are no apples|one: There is one apple|more: There are %count% apples', 10], |
|
84 |
+ |
|
85 |
+ ['', '{0}|{1} There is one apple|]1,Inf] There are %count% apples', 0], |
|
86 |
+ ['', '{0} There are no apples|{1}|]1,Inf] There are %count% apples', 1], |
|
87 |
+ |
|
88 |
+ // Indexed only tests which are Gettext PoFile* compatible strings. |
|
89 |
+ ['There are %count% apples', 'There is one apple|There are %count% apples', 0], |
|
90 |
+ ['There is one apple', 'There is one apple|There are %count% apples', 1], |
|
91 |
+ ['There are %count% apples', 'There is one apple|There are %count% apples', 2], |
|
92 |
+ |
|
93 |
+ // Tests for float numbers |
|
94 |
+ ['There is almost one apple', '{0} There are no apples|]0,1[ There is almost one apple|{1} There is one apple|[1,Inf] There is more than one apple', 0.7], |
|
95 |
+ ['There is one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1], |
|
96 |
+ ['There is more than one apple', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 1.7], |
|
97 |
+ ['There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0], |
|
98 |
+ ['There are no apples', '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0.0], |
|
99 |
+ ['There are no apples', '{0.0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple', 0], |
|
100 |
+ |
|
101 |
+ // Test texts with new-lines |
|
102 |
+ // with double-quotes and \n in id & double-quotes and actual newlines in text |
|
103 |
+ ["This is a text with a\n new-line in it. Selector = 0.", '{0}This is a text with a |
|
104 |
+ new-line in it. Selector = 0.|{1}This is a text with a |
|
105 |
+ new-line in it. Selector = 1.|[1,Inf]This is a text with a |
|
106 |
+ new-line in it. Selector > 1.', 0], |
|
107 |
+ // with double-quotes and \n in id and single-quotes and actual newlines in text |
|
108 |
+ ["This is a text with a\n new-line in it. Selector = 1.", '{0}This is a text with a |
|
109 |
+ new-line in it. Selector = 0.|{1}This is a text with a |
|
110 |
+ new-line in it. Selector = 1.|[1,Inf]This is a text with a |
|
111 |
+ new-line in it. Selector > 1.', 1], |
|
112 |
+ ["This is a text with a\n new-line in it. Selector > 1.", '{0}This is a text with a |
|
113 |
+ new-line in it. Selector = 0.|{1}This is a text with a |
|
114 |
+ new-line in it. Selector = 1.|[1,Inf]This is a text with a |
|
115 |
+ new-line in it. Selector > 1.', 5], |
|
116 |
+ // with double-quotes and id split accros lines |
|
117 |
+ ['This is a text with a |
|
118 |
+ new-line in it. Selector = 1.', '{0}This is a text with a |
|
119 |
+ new-line in it. Selector = 0.|{1}This is a text with a |
|
120 |
+ new-line in it. Selector = 1.|[1,Inf]This is a text with a |
|
121 |
+ new-line in it. Selector > 1.', 1], |
|
122 |
+ // with single-quotes and id split accros lines |
|
123 |
+ ['This is a text with a |
|
124 |
+ new-line in it. Selector > 1.', '{0}This is a text with a |
|
125 |
+ new-line in it. Selector = 0.|{1}This is a text with a |
|
126 |
+ new-line in it. Selector = 1.|[1,Inf]This is a text with a |
|
127 |
+ new-line in it. Selector > 1.', 5], |
|
128 |
+ // with single-quotes and \n in text |
|
129 |
+ ['This is a text with a\nnew-line in it. Selector = 0.', '{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.', 0], |
|
130 |
+ // with double-quotes and id split accros lines |
|
131 |
+ ["This is a text with a\nnew-line in it. Selector = 1.", "{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.", 1], |
|
132 |
+ // esacape pipe |
|
133 |
+ ['This is a text with | in it. Selector = 0.', '{0}This is a text with || in it. Selector = 0.|{1}This is a text with || in it. Selector = 1.', 0], |
|
134 |
+ // Empty plural set (2 plural forms) from a .PO file |
|
135 |
+ ['', '|', 1], |
|
136 |
+ // Empty plural set (3 plural forms) from a .PO file |
|
137 |
+ ['', '||', 1], |
|
138 |
+ ]; |
|
139 |
+ } |
|
140 |
+} |