Exemple #1
0
        public void Either2_Fold()
        {
            Action a = () => {};
            Either <Action, object> e = Either <Action, object> .A(a);

            Assert.AreEqual(a, e.Fold(v => v, v => null));

            e = Either <Action, object> .B("foo");

            Assert.AreEqual("foo", e.Fold(v => null, v => v.ToString()));
        }
Exemple #2
0
        public void Either2_Fold_b_Null()
        {
            Func <Action, int> a = x => 42;
            Func <object, int> b = null;

            var e = Either <Action, object> .A(() => {});

            AssertException <ArgumentNullException> (() => e.Fold(a, b));

            e = Either <Action, object> .B(new object());

            AssertException <ArgumentNullException> (() => e.Fold(a, b));
        }
Exemple #3
0
        public void Either2_Fold_a_Null()
        {
            Func <Action, int> a = null;
            Func <object, int> b = x => Convert.ToInt32(x);

            var e = Either <Action, object> .A(() => {});

            AssertException <ArgumentNullException> (() => e.Fold(a, b));

            e = Either <Action, object> .B(new object());

            AssertException <ArgumentNullException> (() => e.Fold(a, b));
        }
Exemple #4
0
        public void Either3_Fold_c_Null()
        {
            Func <Action, int> a = x => 42;
            Func <object, int> b = x => Convert.ToInt32(x);
            Func <string, int> c = null;

            var e = Either <Action, object, string> .A(() => {});

            AssertException <ArgumentNullException> (() => e.Fold(a, b, c));

            e = Either <Action, object, string> .B(new object());

            AssertException <ArgumentNullException> (() => e.Fold(a, b, c));

            e = Either <Action, object, string> .C("foo");

            AssertException <ArgumentNullException> (() => e.Fold(a, b, c));
        }
Exemple #5
0
        public static IProject GetProject(this _DTE dte, Document currentDoc, string code)
        {
            Project instantProject = new Project();

            instantProject.Sources.Add(Either <FileInfo, string> .B(code));

            EnvDTE.Project project = currentDoc.ProjectItem.ContainingProject;

            EnvDTE.Properties properties = project.ConfigurationManager.ActiveConfiguration.Properties;

            instantProject.DefinedConstants = (string)properties.Item("DefineConstants").Value;
            instantProject.AllowUnsafe      = (bool)properties.Item("AllowUnsafeBlocks").Value;
            instantProject.Optimize         = (bool)properties.Item("Optimize").Value;

            AddFiles(instantProject, project.ProjectItems, currentDoc);
            AddReferences(instantProject, ((VSProject)project.Object).References);

            return(instantProject);
        }
        private async void ProcessInput()
        {
            var source = Interlocked.Exchange(ref this.submission, null);

            if (source != null)
            {
                source.Cancel();
            }

            if (String.IsNullOrEmpty(input) || String.IsNullOrEmpty(TestCode))
            {
                return;
            }

            int id = Interlocked.Increment(ref this.submissionId);

            Either <string, Error> result = await Instantly.Instrument(input, id);

            string instrumented = result.Fold(i => i, e => null);

            if (instrumented == null)
            {
                return;
            }

            Project project = new Project();

            project.Sources.Add(Either <FileInfo, string> .B(instrumented));

            Submission s    = null;
            var        sink = new MemoryInstrumentationSink(() => s.IsCanceled);

            s = new Submission(id, project, sink, TestCode);

            if (DebugTree)
            {
                Debug = instrumented;
            }

            this.evaluator.PushSubmission(s);
        }
Exemple #7
0
        public void Either4_Fold_d_Null()
        {
            Func <Action, int> a = x => 42;
            Func <object, int> b = x => Convert.ToInt32(x);
            Func <string, int> c = x => Convert.ToInt32(x);
            Func <Type, int>   d = null;

            var e = Either <Action, object, string, Type> .A(() => {});

            AssertException <ArgumentNullException> (() => e.Fold(a, b, c, d));

            e = Either <Action, object, string, Type> .B(new object());

            AssertException <ArgumentNullException> (() => e.Fold(a, b, c, d));

            e = Either <Action, object, string, Type> .C("foo");

            AssertException <ArgumentNullException> (() => e.Fold(a, b, c, d));

            e = Either <Action, object, string, Type> .D(typeof(object));

            AssertException <ArgumentNullException> (() => e.Fold(a, b, c, d));
        }
Exemple #8
0
        /// <summary>
        /// Instruments the supplied code to call the <see cref="Hook"/> methods.
        /// </summary>
        /// <param name="code">The code to instrument.</param>
        /// <param name="submissionId">The submission ID.</param>
        /// <returns>A task for a <see cref="string"/> representing the instrumented code.</returns>
        /// <seealso cref="Hook.CreateSubmission"/>
        public static Task <Either <string, Error> > Instrument(string code, int submissionId)
        {
            if (code == null)
            {
                throw new ArgumentNullException("code");
            }

            return(Task <Either <string, Error> > .Factory.StartNew(s =>
            {
                SyntaxTree tree = SyntaxTree.Parse((string)s);

                InstrumentingRewriter rewriter = new InstrumentingRewriter(submissionId);
                tree.AcceptVisitor(rewriter);

                Error error = tree.Errors.FirstOrDefault(e => e.ErrorType == ErrorType.Error);
                if (error != null)
                {
                    return Either <string, Error> .B(error);
                }

                return Either <string, Error> .A(tree.GetText());
            }, code));
        }
 private Either <CachedSequence <T>, IEnumerator <T> > Either(IEnumerator <T> iter)
 {
     return(Either <CachedSequence <T>, IEnumerator <T> > .B(iter));
 }
Exemple #10
0
 protected override Either <Action, object, string, Type> CreateValueX()
 {
     return(Either <Action, object, string, Type> .B("x"));
 }
Exemple #11
0
 protected override Either <Action, object, string> CreateValueY()
 {
     return(Either <Action, object, string> .B("y"));
 }
Exemple #12
0
 protected override Either <Action, object> CreateValueZ()
 {
     return(Either <Action, object> .B("z"));
 }
Exemple #13
0
 public void Either4_B_ValueNull()
 {
     Either <Action, object, string, Type> .B(null);
 }
Exemple #14
0
 public void Either3_B_ValueNull()
 {
     Either <Action, object, string> .B(null);
 }
Exemple #15
0
 public void Either2_B_ValueNull()
 {
     Either <Action, object> .B(null);
 }