|
| 1 | +const cloudinary = require("../../cloudinary"); |
| 2 | +const createTestConfig = require('../testUtils/createTestConfig'); |
| 3 | + |
| 4 | +describe("normalize_expression tests", function () { |
| 5 | + beforeEach(function () { |
| 6 | + cloudinary.config(createTestConfig({ |
| 7 | + cloud_name: "test123", |
| 8 | + api_key: 'a', |
| 9 | + api_secret: 'b' |
| 10 | + })); |
| 11 | + }); |
| 12 | + |
| 13 | + it("Expression normalization", function() { |
| 14 | + const cases = { |
| 15 | + 'null is not affected': [null, null], |
| 16 | + 'None is not affected': ['None', 'None'], |
| 17 | + 'empty string is not affected': ['', ''], |
| 18 | + 'single space is replaced with a single underscore': [' ', '_'], |
| 19 | + 'blank string is replaced with a single underscore': [' ', '_'], |
| 20 | + 'underscore is not affected': ['_', '_'], |
| 21 | + 'sequence of underscores and spaces is replaced with a single underscore': [' _ __ _', '_'], |
| 22 | + 'arbitrary text is not affected': ['foobar', 'foobar'], |
| 23 | + 'double ampersand replaced with and operator': ['foo && bar', 'foo_and_bar'], |
| 24 | + 'double ampersand with no space at the end is not affected': ['foo&&bar', 'foo&&bar'], |
| 25 | + 'width recognized as variable and replaced with w': ['width', 'w'], |
| 26 | + 'initial aspect ratio recognized as variable and replaced with iar': ['initial_aspect_ratio', 'iar'], |
| 27 | + 'duration is recognized as a variable and replaced with du': ['duration', 'du'], |
| 28 | + 'duration after : is not a variable and is not affected': ['preview:duration_2', 'preview:duration_2'], |
| 29 | + '$width recognized as user variable and not affected': ['$width', '$width'], |
| 30 | + '$initial_aspect_ratio recognized as user variable followed by aspect_ratio variable': [ |
| 31 | + '$initial_aspect_ratio', |
| 32 | + '$initial_ar' |
| 33 | + ], |
| 34 | + '$mywidth recognized as user variable and not affected': ['$mywidth', '$mywidth'], |
| 35 | + '$widthwidth recognized as user variable and not affected': ['$widthwidth', '$widthwidth'], |
| 36 | + '$_width recognized as user variable and not affected': ['$_width', '$_width'], |
| 37 | + '$__width recognized as user variable and not affected': ['$__width', '$_width'], |
| 38 | + '$$width recognized as user variable and not affected': ['$$width', '$$width'], |
| 39 | + '$height recognized as user variable and not affected': ['$height_100', '$height_100'], |
| 40 | + '$heightt_100 recognized as user variable and not affected': ['$heightt_100', '$heightt_100'], |
| 41 | + '$$height_100 recognized as user variable and not affected': ['$$height_100', '$$height_100'], |
| 42 | + '$heightmy_100 recognized as user variable and not affected': ['$heightmy_100', '$heightmy_100'], |
| 43 | + '$myheight_100 recognized as user variable and not affected': ['$myheight_100', '$myheight_100'], |
| 44 | + '$heightheight_100 recognized as user variable and not affected': [ |
| 45 | + '$heightheight_100', |
| 46 | + '$heightheight_100' |
| 47 | + ], |
| 48 | + '$theheight_100 recognized as user variable and not affected': ['$theheight_100', '$theheight_100'], |
| 49 | + '$__height_100 recognized as user variable and not affected': ['$__height_100', '$_height_100'] |
| 50 | + }; |
| 51 | + |
| 52 | + Object.keys(cases).forEach(function (testDescription) { |
| 53 | + const [input, expected] = cases[testDescription]; |
| 54 | + expect(cloudinary.utils.normalize_expression(input)).to.equal(expected); |
| 55 | + }); |
| 56 | + }); |
| 57 | +}); |
0 commit comments