public void TestDomainColorNamed() { // parses the MapCSS. AstParserRuleReturnScope <object, IToken> result = this.TestMapCSSParsing( "OsmSharp.UI.Unittests.Data.MapCSS.color-named.mapcss"); // Test the very minimum; no errors during parsing says a lot already! var tree = result.Tree as Antlr.Runtime.Tree.CommonTree; Assert.NotNull(tree); Assert.AreEqual(2, tree.ChildCount); // parse into domain. MapCSSFile file = MapCSSDomainParser.Parse(tree); Assert.IsNotNull(file); Assert.AreEqual(1, file.Rules.Count); Assert.AreEqual(1, file.Rules[0].Declarations.Count); Assert.IsInstanceOf(typeof(DeclarationInt), file.Rules[0].Declarations[0]); // get color declaration. var declarationInt = file.Rules[0].Declarations[0] as DeclarationInt; Assert.IsNotNull(declarationInt); Assert.AreEqual(DeclarationIntEnum.Color, declarationInt.Qualifier); // instantiate color. var simpleColor = new SimpleColor(); simpleColor.Value = declarationInt.Eval((MapCSSObject)null); Assert.AreEqual("#FFFFFF", simpleColor.HexRgb); }
public void TestMetaSettingsCSS() { // create CSS. string css = "meta { " + " title: \"Parking lanes\"; /* title shown in the menu */ " + " icon: \"images/logo.png\"; /* small icon shown in the menu next to the title */ " + "} "; // parses the MapCSS. AstParserRuleReturnScope <object, IToken> result = this.TestMapCSSParsingString(css); // Test the very minimum; no errors during parsing says a lot already! var tree = result.Tree as Antlr.Runtime.Tree.CommonTree; Assert.NotNull(tree); Assert.AreEqual(1, tree.ChildCount); // parse into domain. MapCSSFile file = MapCSSDomainParser.Parse(tree); Assert.IsNotNull(file); Assert.AreEqual(0, file.Rules.Count); Assert.AreEqual("Parking lanes", file.Title); Assert.AreEqual("images/logo.png", file.Icon); }
/// <summary> /// Creates and parses mapcss from a string. /// </summary> /// <param name="css"></param> /// <returns></returns> public static MapCSSFile FromString(string css) { var input = new ANTLRStringStream(css); var lexer = new MapCSSLexer(input); var tokens = new CommonTokenStream(lexer); var parser = new MapCSSParser(tokens); var tree = parser.stylesheet().Tree as Antlr.Runtime.Tree.CommonTree; // parse into domain. return(MapCSSDomainParser.Parse(tree)); }
public void TestDomainDefault() { // parses the MapCSS. AstParserRuleReturnScope <object, IToken> result = this.TestMapCSSParsing( "OsmSharp.UI.Unittests.Data.MapCSS.default.mapcss"); // Test the very minimum; no errors during parsing says a lot already! var tree = result.Tree as Antlr.Runtime.Tree.CommonTree; Assert.NotNull(tree); Assert.AreEqual(54, tree.ChildCount); // parse into domain. MapCSSFile file = MapCSSDomainParser.Parse(tree); Assert.IsNotNull(file); }