1+ package com .cloudinary .transformation ;
2+
3+ import org .junit .Test ;
4+
5+ import static org .junit .Assert .assertEquals ;
6+ import static org .junit .Assert .assertNull ;
7+
8+ public class ExpressionTest {
9+
10+ @ Test
11+ public void normalize_null_null () {
12+ String result = Expression .normalize (null );
13+ assertNull (result );
14+ }
15+
16+ @ Test
17+ public void normalize_number_number () {
18+ String result = Expression .normalize (10 );
19+ assertEquals ("10" , result );
20+ }
21+
22+ @ Test
23+ public void normalize_emptyString_emptyString () {
24+ String result = Expression .normalize ("" );
25+ assertEquals ("" , result );
26+ }
27+
28+ @ Test
29+ public void normalize_singleSpace_underscore () {
30+ String result = Expression .normalize (" " );
31+ assertEquals ("_" , result );
32+ }
33+
34+ @ Test
35+ public void normalize_blankString_underscore () {
36+ String result = Expression .normalize (" " );
37+ assertEquals ("_" , result );
38+ }
39+
40+ @ Test
41+ public void normalize_underscore_underscore () {
42+ String result = Expression .normalize ("_" );
43+ assertEquals ("_" , result );
44+ }
45+
46+ @ Test
47+ public void normalize_underscores_underscore () {
48+ String result = Expression .normalize ("___" );
49+ assertEquals ("_" , result );
50+ }
51+
52+ @ Test
53+ public void normalize_underscoresAndSpaces_underscore () {
54+ String result = Expression .normalize (" _ __ _" );
55+ assertEquals ("_" , result );
56+ }
57+
58+ @ Test
59+ public void normalize_arbitraryText_isNotAffected () {
60+ String result = Expression .normalize ("foobar" );
61+ assertEquals ("foobar" , result );
62+ }
63+
64+ @ Test
65+ public void normalize_doubleAmpersand_replacedWithAndOperator () {
66+ String result = Expression .normalize ("foo && bar" );
67+ assertEquals ("foo_and_bar" , result );
68+ }
69+
70+ @ Test
71+ public void normalize_doubleAmpersandWithNoSpaceAtEnd_isNotAffected () {
72+ String result = Expression .normalize ("foo&&bar" );
73+ assertEquals ("foo&&bar" , result );
74+ }
75+
76+ @ Test
77+ public void normalize_width_recognizedAsVariableAndReplacedWithW () {
78+ String result = Expression .normalize ("width" );
79+ assertEquals ("w" , result );
80+ }
81+
82+ @ Test
83+ public void normalize_initialAspectRatio_recognizedAsVariableAndReplacedWithW () {
84+ String result = Expression .normalize ("initial_aspect_ratio" );
85+ assertEquals ("iar" , result );
86+ }
87+
88+ @ Test
89+ public void normalize_dollarWidth_recognizedAsUserVariableAndNotAffected () {
90+ String result = Expression .normalize ("$width" );
91+ assertEquals ("$width" , result );
92+ }
93+
94+ @ Test
95+ public void normalize_dollarInitialAspectRatio_recognizedAsUserVariableAndAsVariableReplacedWithAr () {
96+ String result = Expression .normalize ("$initial_aspect_ratio" );
97+ assertEquals ("$initial_ar" , result );
98+ }
99+
100+ @ Test
101+ public void normalize_dollarMyWidth_recognizedAsUserVariableAndNotAffected () {
102+ String result = Expression .normalize ("$mywidth" );
103+ assertEquals ("$mywidth" , result );
104+ }
105+
106+ @ Test
107+ public void normalize_dollarWidthWidth_recognizedAsUserVariableAndNotAffected () {
108+ String result = Expression .normalize ("$widthwidth" );
109+ assertEquals ("$widthwidth" , result );
110+ }
111+
112+ @ Test
113+ public void normalize_dollarUnderscoreWidth_recognizedAsUserVariableAndNotAffected () {
114+ String result = Expression .normalize ("$_width" );
115+ assertEquals ("$_width" , result );
116+ }
117+
118+ @ Test
119+ public void normalize_dollarUnderscoreX2Width_recognizedAsUserVariableAndNotAffected () {
120+ String result = Expression .normalize ("$__width" );
121+ assertEquals ("$_width" , result );
122+ }
123+
124+ @ Test
125+ public void normalize_dollarX2Width_recognizedAsUserVariableAndNotAffected () {
126+ String result = Expression .normalize ("$$width" );
127+ assertEquals ("$$width" , result );
128+ }
129+
130+ @ Test
131+ public void normalize_doesntReplaceVariable_1 () {
132+ String actual = Expression .normalize ("$height_100" );
133+ assertEquals ("$height_100" , actual );
134+ }
135+
136+ @ Test
137+ public void normalize_doesntReplaceVariable_2 () {
138+ String actual = Expression .normalize ("$heightt_100" );
139+ assertEquals ("$heightt_100" , actual );
140+ }
141+
142+ @ Test
143+ public void normalize_doesntReplaceVariable_3 () {
144+ String actual = Expression .normalize ("$$height_100" );
145+ assertEquals ("$$height_100" , actual );
146+ }
147+
148+ @ Test
149+ public void normalize_doesntReplaceVariable_4 () {
150+ String actual = Expression .normalize ("$heightmy_100" );
151+ assertEquals ("$heightmy_100" , actual );
152+ }
153+
154+ @ Test
155+ public void normalize_doesntReplaceVariable_5 () {
156+ String actual = Expression .normalize ("$myheight_100" );
157+ assertEquals ("$myheight_100" , actual );
158+ }
159+
160+ @ Test
161+ public void normalize_doesntReplaceVariable_6 () {
162+ String actual = Expression .normalize ("$heightheight_100" );
163+ assertEquals ("$heightheight_100" , actual );
164+ }
165+
166+ @ Test
167+ public void normalize_doesntReplaceVariable_7 () {
168+ String actual = Expression .normalize ("$theheight_100" );
169+ assertEquals ("$theheight_100" , actual );
170+ }
171+
172+ @ Test
173+ public void normalize_doesntReplaceVariable_8 () {
174+ String actual = Expression .normalize ("$__height_100" );
175+ assertEquals ("$_height_100" , actual );
176+ }
177+ }
0 commit comments