Esempio n. 1
0
    public void CreateContextWithReferences()
    {
        LightList <StyleASTNode> nodes = new LightList <StyleASTNode>();

        nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("x", StyleASTNodeFactory.ConstReferenceNode("y"))));
        nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("y", StyleASTNodeFactory.ConstReferenceNode("z"))));
        var stringValue = StyleASTNodeFactory.StringLiteralNode("you win!");

        nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("z", stringValue)));

        var context = new StyleSheetConstantImporter(new StyleSheetImporter(null, null)).CreateContext(nodes, default);

        Assert.AreEqual(3, context.constants.Count);

        Assert.AreEqual("x", context.constants[2].name);
        Assert.AreEqual(stringValue, context.constants[2].value);
        Assert.True(context.constants[2].exported);

        Assert.AreEqual("y", context.constants[1].name);
        Assert.AreEqual(stringValue, context.constants[1].value);
        Assert.True(context.constants[1].exported);

        Assert.AreEqual("z", context.constants[0].name);
        Assert.AreEqual(stringValue, context.constants[0].value);
        Assert.True(context.constants[0].exported);

        Assert.AreEqual(0, context.constantsWithReferences.Count, "There should be no unresolved const left.");
    }
Esempio n. 2
0
    public void ImportAndUseConsts()
    {
        LightList <StyleASTNode> nodes = new LightList <StyleASTNode>();

        nodes.Add(StyleASTNodeFactory.ImportNode("importedThing", "Data/Styles/ImportFromMe.style"));
        string basepath             = Path.Combine(Application.dataPath, "..", "Packages", "UIForia", "Tests");
        StyleCompileContext context = new StyleSheetConstantImporter(new StyleSheetImporter(basepath, null)).CreateContext(nodes, default);

        Assert.AreEqual(1, context.importedStyleConstants.Count);
        Assert.AreEqual(1, context.importedStyleConstants["importedThing"].Count);
        Assert.AreEqual("colorRed", context.importedStyleConstants["importedThing"][0].name);
    }
Esempio n. 3
0
    public void CreateContextWithMultipleConstants()
    {
        LightList <StyleASTNode> nodes = new LightList <StyleASTNode>();

        nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("col0", StyleASTNodeFactory.ColorNode("red"))));
        nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("thing0", StyleASTNodeFactory.StringLiteralNode("someVal"))));
        nodes.Add(StyleASTNodeFactory.ExportNode(StyleASTNodeFactory.ConstNode("number", StyleASTNodeFactory.NumericLiteralNode("1"))));

        var context = new StyleSheetConstantImporter(new StyleSheetImporter(null, null)).CreateContext(nodes, default);

        Assert.AreEqual(3, context.constants.Count);
        Assert.AreEqual("col0", context.constants[0].name);
        Assert.True(context.constants[0].exported);

        Assert.AreEqual("thing0", context.constants[1].name);
        Assert.True(context.constants[1].exported);

        Assert.AreEqual("number", context.constants[2].name);
        Assert.True(context.constants[2].exported);
    }