|
| 1 | +require "spec_helper" |
| 2 | + |
| 3 | +describe "Expression normalization" do |
| 4 | + { |
| 5 | + 'nil is not affected' => [nil, nil], |
| 6 | + 'number replaced with a string value' => [10, '10'], |
| 7 | + 'empty string is not affected' => ['', ''], |
| 8 | + 'single space is replaced with a single underscore' => [' ', '_'], |
| 9 | + 'blank string is replaced with a single underscore' => [' ', '_'], |
| 10 | + 'underscore is not affected' => ['_', '_'], |
| 11 | + 'sequence of underscores and spaces is replaced with a single underscore' => [' _ __ _', '_'], |
| 12 | + 'arbitrary text is not affected' => ['foobar', 'foobar'], |
| 13 | + 'double ampersand replaced with and operator' => ['foo && bar', 'foo_and_bar'], |
| 14 | + 'double ampersand with no space at the end is not affected' => ['foo&&bar', 'foo&&bar'], |
| 15 | + 'width recognized as variable and replaced with w' => ['width', 'w'], |
| 16 | + 'initial aspect ratio recognized as variable and replaced with iar' => ['initial_aspect_ratio', 'iar'], |
| 17 | + '$width recognized as user variable and not affected' => ['$width', '$width'], |
| 18 | + '$initial_aspect_ratio recognized as user variable followed by aspect_ratio variable' => [ |
| 19 | + '$initial_aspect_ratio', |
| 20 | + '$initial_ar', |
| 21 | + ], |
| 22 | + '$mywidth recognized as user variable and not affected' => ['$mywidth', '$mywidth'], |
| 23 | + '$widthwidth recognized as user variable and not affected' => ['$widthwidth', '$widthwidth'], |
| 24 | + '$_width recognized as user variable and not affected' => ['$_width', '$_width'], |
| 25 | + '$__width recognized as user variable and not affected' => ['$__width', '$_width'], |
| 26 | + '$$width recognized as user variable and not affected' => ['$$width', '$$width'], |
| 27 | + '$height recognized as user variable and not affected' => ['$height_100', '$height_100'], |
| 28 | + '$heightt_100 recognized as user variable and not affected' => ['$heightt_100', '$heightt_100'], |
| 29 | + '$$height_100 recognized as user variable and not affected' => ['$$height_100', '$$height_100'], |
| 30 | + '$heightmy_100 recognized as user variable and not affected' => ['$heightmy_100', '$heightmy_100'], |
| 31 | + '$myheight_100 recognized as user variable and not affected' => ['$myheight_100', '$myheight_100'], |
| 32 | + '$heightheight_100 recognized as user variable and not affected' => [ |
| 33 | + '$heightheight_100', |
| 34 | + '$heightheight_100', |
| 35 | + ], |
| 36 | + '$theheight_100 recognized as user variable and not affected' => ['$theheight_100', '$theheight_100'], |
| 37 | + '$__height_100 recognized as user variable and not affected' => ['$__height_100', '$_height_100'] |
| 38 | + }.each do |test_description, (input, expected)| |
| 39 | + specify test_description do |
| 40 | + actual = Cloudinary::Utils.normalize_expression(input) |
| 41 | + expect(actual).to eq(expected) |
| 42 | + end |
| 43 | + end |
| 44 | +end |
0 commit comments