Esempio n. 1
0
        public void CanKebanNames()
        {
            var rules = new CssValue[] { "backgroundColor", "#cAcAcA" };

            TransformationsRules.KebabRules(rules, 0);
            CollectionAssert.AreEqual(rules, new CssValue[] { "background-color", "#cAcAcA" });
        }
Esempio n. 2
0
        public void CanKebebWebkitPrefix()
        {
            var rules = new CssValue[] { "WebkitFontSmoothing", "antialiased" };

            TransformationsRules.KebabRules(rules, 0);

            CollectionAssert.AreEqual(rules, new CssValue[] { "-webkit-font-smoothing", "antialiased" });
        }
        public void CanIgnoreOpacity()
        {
            var rules = new List <CssValue> {
                "opacity", 0
            }.ToArray();

            TransformationsRules.ProvideUnits(rules, 0);
            CollectionAssert.That.AreEqualRules(rules, "opacity", "0");
        }
Esempio n. 4
0
        public async Task CanAutoFlipAutoflippingWithNoflip()
        {
            var properties = JsonConvert.DeserializeObject <ICollection <CssValue[][]> >(await File.ReadAllTextAsync(@"Transformations/rtlfyrulesdata.json"), RawConverter.Settings);

            foreach (var test in properties)
            {
                var rules = test[0];
                await TransformationsRules.RtlifyRules(rules, 0);

                CollectionAssert.That.AreEqualRules(rules, test[1]);
            }
        }
Esempio n. 5
0
        public async Task CanFlipRTLAndAddUnits()
        {
            await TransformationsRules.SetRTL(true);

            var style = new Style()
            {
                Left = 40
            };
            var className = await StyleEngine.StyleToClassName(style);

            Assert.AreEqual(".css-0{right:40px;}", _stylesheet.GetRules());
            await TransformationsRules.SetRTL(false);
        }
        public void CanProvideUnits()
        {
            var properties = new List <CssValue> {
                "left", "right", "top", "bottom", "borderWidth"
            }.ToArray();

            foreach (var property in properties)
            {
                var rules = new CssValue[] { property, 1 };
                TransformationsRules.ProvideUnits(rules, 0);
                CollectionAssert.That.AreEqualRules(rules, property, "1px");
            }
        }
Esempio n. 7
0
        public async Task CanProvideTranslateOperaRules()
        {
            foreach (var rule in this._AUTO_TRANSLATED_RULES)
            {
                var rules = new List <CssValue> {
                    rule, "none"
                };
                VendorSettings.SetCurrent(new VendorSettings {
                    IsOpera = true
                });
                await TransformationsRules.PrefixRules(rules, 0);

                CollectionAssert.That.AreEqualRules(rules, rule, "none", "-o-" + rule, "none");
            }
        }
 public void CanRegisterFromToKeyframesInRTL()
 {
     TransformationsRules.SetRTL(true).GetAwaiter().GetResult();
     StyleEngine.Keyframes(new Keyframes {
         From = new Style
         {
             Opacity = 0
         },
         To = new Style
         {
             Opacity = 1
         }
     });
     Assert.AreEqual("@keyframes css-0{from{opacity:0;}to{opacity:1;}}", stylesheet.GetRules());
 }
        public void CanProvideUnitForDirectionalProps()
        {
            var properties = new List <string> {
                "padding", "margin", "border"
            };

            foreach (var property in properties)
            {
                var rules = new List <CssValue>()
                {
                    property,
                    1,
                    property + "Left",
                    1,
                    property + "Right",
                    1,
                    property + "Top",
                    1,
                    property + "Bottom",
                    1
                }.ToArray();

                TransformationsRules.ProvideUnits(rules, 0);
                TransformationsRules.ProvideUnits(rules, 2);
                TransformationsRules.ProvideUnits(rules, 4);
                TransformationsRules.ProvideUnits(rules, 6);
                TransformationsRules.ProvideUnits(rules, 8);

                CollectionAssert.That.AreEqualRules(rules,
                                                    property,
                                                    "1px",
                                                    property + "Left",
                                                    "1px",
                                                    property + "Right",
                                                    "1px",
                                                    property + "Top",
                                                    "1px",
                                                    property + "Bottom",
                                                    "1px");
            }
        }
Esempio n. 10
0
 public async Task Cleanup()
 {
     await TransformationsRules.SetRTL(false);
 }
Esempio n. 11
0
 public async Task TestInit()
 {
     base.Init();
     await TransformationsRules.SetRTL(true);
 }
        public static async Task <string> SerializeRuleEntries(IDictionary <string, object> ruleEntries)
        {
            if (ruleEntries?.Any() != true)
            {
                return("");
            }

            var allEntries = new List <CssValue>();

            foreach (var entry in ruleEntries.Keys)
            {
                object rule;

                if (entry is string str && str != DISPLAY_NAME && ruleEntries.TryGetValue(entry, out rule) && rule != null)
                {
                    allEntries.Add(str);
                    var entryValue = ruleEntries[entry];

                    CssValue value = new CssValue();
                    switch (entryValue)
                    {
                    case CssValue css:
                        value = css;
                        break;

                    case bool bo:
                        value = bo;
                        break;

                    case int @int:
                        value = @int;
                        break;

                    case string strg:
                        value = strg;
                        break;

                    default:
                        value = JsonConvert.SerializeObject(entryValue, Formatting.None, RawConverter.Settings);
                        break;
                    }

                    allEntries.Add(value);
                }
            }
            var arrayRules = allEntries.ToArray();

            // Apply transforms.
            for (var i = 0; i < arrayRules.Length; i += 2)
            {
                TransformationsRules.KebabRules(arrayRules, i);
                TransformationsRules.ProvideUnits(arrayRules, i);
                await TransformationsRules.RtlifyRules(arrayRules, i);

                await TransformationsRules.PrefixRules(arrayRules, i);
            }
            var rules = arrayRules.ToList();

            // Apply punctuation.
            for (var i = 1; i < rules.Count; i += 4)
            {
                rules.Splice(i, 1, ":", rules[i], ";");
            }

            return(string.Join("", rules));
        }
 public void TestEnd()
 {
     TransformationsRules.SetRTL(false).GetAwaiter().GetResult();
 }