Ejemplo n.º 1
0
        public void CurrentStep()
        {
            var pipeline = new CompilerPipeline();

            var step1 = new ActionStep(delegate {});

            pipeline.Add(step1);

            ActionStep step2 = null;

            step2 = new ActionStep(() => Assert.AreSame(step2, pipeline.CurrentStep));
            pipeline.Add(step2);

            var currentSteps = new Boo.Lang.List();

            pipeline.Before     += (sender, args) => currentSteps.Add(pipeline.CurrentStep);
            pipeline.BeforeStep += (sender, args) => currentSteps.Add(pipeline.CurrentStep);
            pipeline.AfterStep  += (sender, args) => currentSteps.Add(pipeline.CurrentStep);
            pipeline.After      += (sender, args) => currentSteps.Add(pipeline.CurrentStep);

            pipeline.Run(new CompilerContext());

            Assert.AreEqual(
                new object[] { null, step1, step1, step2, step2, null },
                currentSteps.ToArray());
        }
Ejemplo n.º 2
0
        private void BlockTag(string tag, IDictionary attributes, ICallable block)
        {
            Output.Write("<{0}", tag);

            List<string> attributeValues = new List<string>();

            if (null != attributes)
            {
                foreach (DictionaryEntry entry in attributes)
                {
                    attributeValues.Add(string.Format("{0}=\"{1}\"", entry.Key, entry.Value));
                }
            }

            if (0 != attributeValues.Count)
            {
                Output.Write(" ");
                Output.Write(string.Join(" ", attributeValues.ToArray()));
            }

            Output.Write(">");
            if(block!=null)
            {
                block.Call(null);
            }
            Output.Write("</{0}>", tag);
        }
    public static string CreateUXMLTemplate(string folder)
    {
        UxmlSchemaGenerator.UpdateSchemaFiles();

        string[] pathComponents         = folder.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
        Boo.Lang.List <string> backDots = new Boo.Lang.List <string>();
        foreach (var s in pathComponents)
        {
            if (s == ".")
            {
                continue;
            }
            if (s == ".." && backDots.Count > 0)
            {
                backDots.RemoveAt(backDots.Count - 1);
            }
            else
            {
                backDots.Add("..");
            }
        }
        backDots.Add(UxmlSchemaGenerator.k_SchemaFolder);
        string schemaDirectory = string.Join("/", backDots.ToArray());

        string xmlnsList          = String.Empty;
        string schemaLocationList = String.Empty;
        Dictionary <string, string> namespacePrefix = UxmlSchemaGenerator.GetNamespacePrefixDictionary();

        foreach (var prefix in namespacePrefix)
        {
            if (prefix.Key == String.Empty)
            {
                continue;
            }

            if (prefix.Value != String.Empty)
            {
                xmlnsList += "    xmlns:" + prefix.Value + "=\"" + prefix.Key + "\"\n";
            }
            schemaLocationList += "                        " + prefix.Key + " " + schemaDirectory + "/" +
                                  UxmlSchemaGenerator.GetFileNameForNamespace(prefix.Key) + "\n";
        }

        // The noNamespaceSchemaLocation attribute should be sufficient to reference all namespaces
        // but Rider does not support it very well, so we add schemaLocation to make it happy.
        string uxmlTemplate = String.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
<engine:{0}
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
{1}
xsi:noNamespaceSchemaLocation=""{2}/UIElements.xsd""
xsi:schemaLocation=""
{3}""
>
    <engine:Label text=""Hello World! From UXML"" />
</engine:{0}>", UXMLImporterImpl.k_RootNode, xmlnsList, schemaDirectory, schemaLocationList);

        return(uxmlTemplate);
    }
Ejemplo n.º 4
0
		public void EventSequence()
		{
			var calls = new List<string>();
			var pipeline = new CompilerPipeline();
			pipeline.Before += delegate { calls.Add("before"); };
			pipeline.BeforeStep += delegate { calls.Add("before step"); };
			pipeline.Add(new ActionStep(() => calls.Add("step")));
			pipeline.AfterStep += delegate { calls.Add("after step"); };
			pipeline.After += delegate { calls.Add("after"); };
			pipeline.Run(new CompilerContext());
			Assert.AreEqual(
				new string[] {"before", "before step", "step", "after step", "after"},
				calls.ToArray());
		}
Ejemplo n.º 5
0
		public void CurrentStep()
		{
			var pipeline = new CompilerPipeline();

			var step1 = new ActionStep(delegate {});
			pipeline.Add(step1);

			ActionStep step2 = null;
			step2 = new ActionStep(() => Assert.AreSame(step2, pipeline.CurrentStep));
			pipeline.Add(step2);

			var currentSteps = new Boo.Lang.List();
			pipeline.Before += (sender, args) => currentSteps.Add(pipeline.CurrentStep);
			pipeline.BeforeStep += (sender, args) => currentSteps.Add(pipeline.CurrentStep);
			pipeline.AfterStep += (sender, args) => currentSteps.Add(pipeline.CurrentStep);
			pipeline.After += (sender, args) => currentSteps.Add(pipeline.CurrentStep);

			pipeline.Run(new CompilerContext());

			Assert.AreEqual(
				new object[] { null, step1, step1, step2, step2, null },
				currentSteps.ToArray());
		}
Ejemplo n.º 6
0
		public void ExecutionOrder()
		{
			var order = new List<string>();
			var p1 = new ActionStep(() => order.Add("p1"));
			var p2 = new ActionStep(() => order.Add("p2"));

			var pipeline = new CompilerPipeline { p1, p2 };
			pipeline.Run(new CompilerContext());

			Assert.AreEqual(new[] { "p1", "p2" }, order.ToArray());
		}