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())); }
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)); }
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)); }
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)); }
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); }
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)); }
/// <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)); }
protected override Either <Action, object, string, Type> CreateValueX() { return(Either <Action, object, string, Type> .B("x")); }
protected override Either <Action, object, string> CreateValueY() { return(Either <Action, object, string> .B("y")); }
protected override Either <Action, object> CreateValueZ() { return(Either <Action, object> .B("z")); }
public void Either4_B_ValueNull() { Either <Action, object, string, Type> .B(null); }
public void Either3_B_ValueNull() { Either <Action, object, string> .B(null); }
public void Either2_B_ValueNull() { Either <Action, object> .B(null); }