Пример #1
0
        public void CanUseNode(bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent("node[test] { z-index: 0.1}\n", canUseExprTree);

            // ACT
            var node = MapCssHelper.GetNode(new Dictionary <string, string>()
            {
                { "test", "yes" },
            }.ToTags());

            // ASSERT
            Assert.IsTrue(stylesheet.GetModelRule(node, MapConsts.MaxZoomLevel).IsApplicable);
        }
Пример #2
0
        public void CanUseZoomLevel(string zoomStr, int start, int end, int currentZoomLevel, bool expectedResult)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent(
                String.Format("area|{0}[level>0] {{ z-index: 0.1}}\n", zoomStr));

            var area = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "level", "1" }
            }.ToTags());

            // ACT
            var rule = stylesheet.GetModelRule(area, currentZoomLevel);

            // ASSERT
            Assert.IsTrue(rule.IsApplicable == expectedResult);
        }
Пример #3
0
        public void CanUseLess()
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent("area[level<0] { z-index: 0.1}\n");

            // ACT
            var area1 = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "level", "-1" }
            }.ToTags());
            var area2 = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "level", "1" }
            }.ToTags());

            // ASSERT
            Assert.IsTrue(stylesheet.GetModelRule(area1, MapConsts.MaxZoomLevel).IsApplicable);
            Assert.IsFalse(stylesheet.GetModelRule(area2, MapConsts.MaxZoomLevel).IsApplicable);
        }
Пример #4
0
        public void CanUseNotEqual()
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent("area[landuse!=forest] { z-index: 0.1}\n");

            // ACT
            var area1 = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "landuse", "forest" }
            }.ToTags());
            var area2 = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "landuse", "grass" }
            }.ToTags());

            // ASSERT
            Assert.IsFalse(stylesheet.GetModelRule(area1, MapConsts.MaxZoomLevel).IsApplicable);
            Assert.IsTrue(stylesheet.GetModelRule(area2, MapConsts.MaxZoomLevel).IsApplicable);
        }
Пример #5
0
        public void CanUseSingleValueInList(bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent(
                "area[building] { behaviours:test1; non-important:test}", canUseExprTree);
            var building = MapCssHelper.GetArea(new Dictionary <string, string>()
            {
                { "building", "commercial" },
            }.ToTags());
            var rule = stylesheet.GetModelRule(building, MapConsts.MaxZoomLevel);

            // ACT
            var behaviours = rule.EvaluateList <string>("behaviours");

            // ASSERT
            var list = behaviours.ToList();

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual("test1", list[0]);
        }
Пример #6
0
        public void CanUseGradient()
        {
            // ARRANGE
            const string gradientString = "gradient(#f4f4f4, yellow 10%, green 20%)";
            var          stylesheet     = MapCssHelper
                                          .GetStylesheetFromContent(String.Format("node[test] {{ facade: {0};}}\n", gradientString));

            // ACT
            var node = MapCssHelper.GetNode(new Dictionary <string, string>()
            {
                { "test", "yes" },
            }.ToTags());

            // ASSERT
            var rule           = stylesheet.GetModelRule(node, MapConsts.MaxZoomLevel);
            var facadeGradient = rule.Evaluate <string>("facade");

            Assert.IsNotEmpty(facadeGradient);
            Assert.AreEqual(gradientString, facadeGradient);
        }
Пример #7
0
        public void CanEvaluateGradient()
        {
            // ARRANGE
            var stylesheet = MapCssHelper
                             .GetStylesheetFromContent(String.Format("node[test] {{ facade: eval(gradient(tag('colour')));}}\n"));

            // ACT
            var node = MapCssHelper.GetNode(new Dictionary <string, string>()
            {
                { "test", "yes" },
                { "colour", "#0fff8f" },
            }.ToTags());

            // ASSERT
            var rule           = stylesheet.GetModelRule(node, MapConsts.MaxZoomLevel);
            var facadeGradient = rule.Evaluate <string>("facade");

            Assert.IsNotEmpty(facadeGradient);
            Assert.AreEqual("gradient(#0fff8f, #0fff8f 50%, #099956)", facadeGradient);
        }
Пример #8
0
        public void CanUseAndSelectors(bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent("way[waterway][name],way[waterway] { z-index: 0.1}\n", canUseExprTree);

            // ACT
            var way1 = MapCssHelper.GetWay(
                new Dictionary <string, string>()
            {
                { "waterway", "river" },
                { "name", "spree" }
            }.ToTags());
            var way2 = MapCssHelper.GetWay(new Dictionary <string, string>()
            {
                { "name", "some name" }
            }.ToTags());

            // ASSERT
            Assert.IsTrue(stylesheet.GetModelRule(way1, MapConsts.MaxZoomLevel).IsApplicable);
            Assert.IsFalse(stylesheet.GetModelRule(way2, MapConsts.MaxZoomLevel).IsApplicable);
        }
Пример #9
0
        public void CanPerformSimpleOperationWithTags(bool canUseExprTree)
        {
            // ARRANGE
            var model = new Area
            {
                Id   = 1,
                Tags = new Dictionary <string, string>()
                {
                    { "building:height", "20" },
                    { "roof:height", "5" },
                }.ToTags()
            };

            var stylesheet = MapCssHelper.GetStylesheetFromContent("area[building:height][roof:height] { height: eval(num(tag('building:height')) - num(tag('roof:height')));}\n", canUseExprTree);
            var rule       = stylesheet.GetModelRule(model, MapConsts.MaxZoomLevel);

            // ACT
            var evalResult = rule.GetHeight();

            // ASSERT
            Assert.AreEqual(15, evalResult);
        }
Пример #10
0
        public void CanApplyColorByRGB(string path, bool canUseExprTree)
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent("area[building:color] { fill-color:eval(color(tag('building:color')));}", canUseExprTree);

            var buildingWithColorCode = new Area
            {
                Id     = 1,
                Points = new List <GeoCoordinate>(),
                Tags   = new Dictionary <string, string>()
                {
                    { "building", "commercial" },
                    { "building:color", "#cfc6b5" }
                }.ToTags()
            };

            // ACT
            var rule = stylesheet.GetModelRule(buildingWithColorCode, MapConsts.MaxZoomLevel);

            // ASSERT
            Assert.AreEqual(ColorUtils.FromUnknown("#cfc6b5"),
                            GetOriginalColorTypeObject(rule.GetFillUnityColor()));
        }