示例#1
0
        public IErrorReporter ErrorIsSameOnValues()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                Int64Literal value = Int64Literal.Create("3");
                root_ns.AddBuilder(FunctionBuilder.Create("foo",
                                                          NameFactory.BoolNameReference(),
                                                          Block.CreateStatement(
                                                              VariableDeclaration.CreateStatement("x", null,
                                                                                                  ExpressionFactory.HeapConstructor(NameFactory.Int64NameReference(), Int64Literal.Create("2"))),
                                                              Return.Create(IsSame.Create(NameReference.Create("x"), value))
                                                              )));


                resolver = NameResolver.Create(env);

                Assert.AreEqual(1, resolver.ErrorManager.Errors.Count);
                Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.CannotUseValueExpression, value));
            }

            return(resolver);
        }
        public virtual void TestCreatedInstanceConfigured()
        {
            ResourceCalculatorProcessTree tree;
            Configuration conf = new Configuration();

            tree = ResourceCalculatorProcessTree.GetResourceCalculatorProcessTree("1", typeof(
                                                                                      TestResourceCalculatorProcessTree.EmptyProcessTree), conf);
            NUnit.Framework.Assert.IsNotNull(tree);
            Assert.AssertThat(tree.GetConf(), IsSame.SameInstance(conf));
        }
        public async Task Post_child_view_model_and_bind_to_parent_on_postback_taghelpers()
        {
            var enteredViewModel = ObjectMother.ChangingContextViewModels.ParentViewModel;

            var page = await _client.GetPageAsync <ChangingContextPage>("/ExampleForms/ChangingContextTH");

            page = await page.PostParentModelAsync(enteredViewModel);

            IsSame.ViewModelAs(enteredViewModel, page.ReadParentModel());
            page.HasValidationErrors().ShouldBeFalse();
        }
        public void Function_correctly_with_checkbox_and_radio_lists()
        {
            var enteredViewModel = ObjectMother.ModelBindingViewModels.BasicValid;

            var page = SelenoHost.NavigateToInitialPage <HomePage>()
                       .GoToModelBindingExamplePage2()
                       .Submit(enteredViewModel);

            Assert.That(page.GetFormValues(), IsSame.ViewModelAs(enteredViewModel));
            Assert.That(page.HasValidationErrors(), Is.False, "There are validation errors on the page");
        }
        public void Function_correctly_with_default_form()
        {
            var enteredViewModel = ObjectMother.ModelBindingViewModels.BasicValid;

            var page = Host.Instance.NavigateToInitialPage <HomePage>()
                       .GoToModelBindingExamplePage()
                       .Submit(enteredViewModel);

            Assert.That(page.GetFormValues(), IsSame.ViewModelAs(enteredViewModel));
            Assert.That(page.HasValidationErrors(), Is.False, "There are validation errors on the page");
        }
示例#6
0
        public void Post_child_view_model_and_bind_to_parent_on_postback()
        {
            var enteredViewModel = ObjectMother.ChangingContextViewModels.ParentViewModel;

            var page = Host.Instance.NavigateToInitialPage <HomePage>()
                       .GoToChangingContextPage2()
                       .PostParentModel(enteredViewModel);

            Assert.That(page.ReadParentModel(), IsSame.ViewModelAs(enteredViewModel));
            Assert.That(page.HasValidationErrors(), Is.False, "There are validation errors on the page");
        }
        public ActionResult ExpectFixtureA(Form1ViewModel vm)
        {
            try
            {
                Assert.That(vm, IsSame.ViewModelAs(Form1Fixtures.A));
            }
            catch (Exception e)
            {
                return(new ContentResult {
                    Content = e.ToString(), ContentType = "text/plain"
                });
            }

            return(new EmptyResult());
        }
示例#8
0
        public ActionResult ExpectFixtureA(Form1ViewModel vm)
        {
            try
            {
                Assert.That(vm, IsSame.ViewModelAs(Form1Fixtures.A));
            }
            catch (Exception e)
            {
                return(View("ExpectedFixtureAResult", new ExceptionViewModel
                {
                    Exception = e
                }));
            }

            return(new EmptyResult());
        }
示例#9
0
        public async Task Function_correctly_with_checkbox_and_radio_lists()
        {
            var enteredViewModel = ObjectMother.ModelBindingViewModels.BasicValid;

            var page = await _client.GetPageAsync <ModelBindingExamplePage>("/ExampleForms/ModelBindingExample2");

            var pageAfterPostback = await page.SubmitAsync(enteredViewModel);

            _output.WriteLine("### Debug output - POST contents:");
            _postCapture.Posts.ToList().ForEach(p => _output.WriteLine(p));
            _output.WriteLine("###");
            _output.WriteLine("### Debug output - Page HTML after postback:");
            _output.WriteLine(pageAfterPostback.Source);
            _output.WriteLine("###");
            IsSame.ViewModelAs(enteredViewModel, pageAfterPostback.GetFormValues());
            page.HasValidationErrors().ShouldBeFalse();
        }
示例#10
0
        public IInterpreter TestingSamePointers()
        {
            var interpreter = new Interpreter.Interpreter();

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Language.Environment.Create(new Options()
                {
                    AllowInvalidMainResult             = true,
                    DebugThrowOnError                  = true,
                    DiscardingAnyExpressionDuringTests = true
                }.SetMutability(mutability));
                var root_ns = env.Root;


                var main_func = root_ns.AddBuilder(FunctionBuilder.Create(
                                                       "main",
                                                       ExpressionReadMode.OptionalUse,
                                                       NameFactory.Int64NameReference(),
                                                       Block.CreateStatement(new IExpression[] {
                    VariableDeclaration.CreateStatement("x", null,
                                                        ExpressionFactory.HeapConstructor(NameFactory.Int64NameReference(), Int64Literal.Create("2"))),
                    VariableDeclaration.CreateStatement("y", null, NameReference.Create("x")),
                    VariableDeclaration.CreateStatement("z", null,
                                                        ExpressionFactory.HeapConstructor(NameFactory.Int64NameReference(), Int64Literal.Create("2"))),
                    VariableDeclaration.CreateStatement("acc", null, Int64Literal.Create("0"), env.Options.ReassignableModifier()),
                    IfBranch.CreateIf(IsSame.Create(NameReference.Create("x"), NameReference.Create("y")), new[] {
                        Assignment.CreateStatement(NameReference.Create("acc"),
                                                   ExpressionFactory.Add(NameReference.Create("acc"), Int64Literal.Create("2")))
                    }),
                    IfBranch.CreateIf(IsSame.Create(NameReference.Create("x"), NameReference.Create("z")), new[] {
                        Assignment.CreateStatement(NameReference.Create("acc"),
                                                   ExpressionFactory.Add(NameReference.Create("acc"), Int64Literal.Create("7")))
                    }),
                    Return.Create(NameReference.Create("acc"))
                })));

                ExecValue result = interpreter.TestRun(env);

                Assert.AreEqual(2L, result.RetValue.PlainValue);
            }

            return(interpreter);
        }
示例#11
0
        private DiffResult[] DiffCore(string textA, string textB, DiffOption option)
        {
            this.linesA = SplitLine(textA, option);
            this.linesB = SplitLine(textB, option);

            if (this.linesB.Length < this.linesA.Length)
            {
                this.isSwap = true;

                string[] tmps = this.linesA;
                this.linesA = this.linesB;
                this.linesB = tmps;
            }
            this.dataA = MakeHash(this.linesA);
            this.dataB = MakeHash(this.linesB);

            this.isSame = delegate(int posA, int posB) {
                return((this.dataA[posA] == this.dataB[posB]) && (this.linesA[posA] == this.linesB[posB]));
            };

            return(DetectDiff());
        }
示例#12
0
        public IInterpreter StoringSequenceAsSequence()
        {
            var interpreter = new Interpreter.Interpreter();

            foreach (var mutability in Options.AllMutabilityModes)
            {
                // todo: add analogous test with storing iterable as sequence

                // yes, this test seems like pointless thing but it is important nevertheless because
                // we have to check if conversion does NOT happen
                var env = Language.Environment.Create(new Options()
                {
                }.SetMutability(mutability));
                var root_ns = env.Root;

                var main_func = root_ns.AddBuilder(FunctionBuilder.Create(
                                                       "main",
                                                       ExpressionReadMode.OptionalUse,
                                                       NameFactory.Nat8NameReference(),
                                                       Block.CreateStatement(new IExpression[] {
                    VariableDeclaration.CreateStatement("x", null,
                                                        ExpressionFactory.HeapConstructor(NameFactory.ChunkNameReference(NameFactory.Int64NameReference()),
                                                                                          FunctionArgument.Create(NatLiteral.Create("2"))),
                                                        env.Options.ReassignableModifier()),
                    ExpressionFactory.InitializeIndexable("x", Int64Literal.Create("-6"), Int64Literal.Create("8")),
                    // conversion should NOT happen
                    VariableDeclaration.CreateStatement("stored", null,
                                                        FunctionCall.Create(NameFactory.StoreFunctionReference(), NameReference.Create("x"))),
                    Return.Create(ExpressionFactory.Ternary(IsSame.Create("x", "stored"), Nat8Literal.Create("2"), Nat8Literal.Create("7")))
                })));

                ExecValue result = interpreter.TestRun(env);

                Assert.AreEqual((byte)2, result.RetValue.PlainValue);
            }

            return(interpreter);
        }
示例#13
0
 public void Then_the_model_should_match_the_model_used_to_fill_the_form()
 {
     Assert.That(_viewModel, IsSame.ViewModelAs(Form1Fixtures.A));
 }
示例#14
0
        public IErrorReporter DuckTypingOnEmptyInterface()
        {
            NameResolver resolver = null;

            foreach (var mutability in Options.AllMutabilityModes)
            {
                var env = Environment.Create(new Options()
                {
                    DiscardingAnyExpressionDuringTests = true,
                    // we test this option here or more precisely duck typing
                    InterfaceDuckTyping = true
                }.SetMutability(mutability));
                var root_ns = env.Root;

                // please note it is not the interface is empty (it is not because IObject is not empty),
                // but it does not add anything, so in this sense it is empty
                root_ns.AddBuilder(TypeBuilder.CreateInterface("IWhat"));

                root_ns.AddBuilder(FunctionBuilder.Create("foo",
                                                          NameFactory.UnitNameReference(),
                                                          Block.CreateStatement(
                                                              VariableDeclaration.CreateStatement("x", NameFactory.PointerNameReference(NameFactory.IObjectNameReference()), Undef.Create()),
                                                              // should be legal despite duck typing, i.e. we should not error that the types are exchangable
                                                              // they are in sense of duck typing but checking if the type IS another type should be duck-free
                                                              ExpressionFactory.Readout(IsType.Create(NameReference.Create("x"), NameReference.Create("IWhat"))),
                                                              VariableDeclaration.CreateStatement("y", NameFactory.PointerNameReference(NameReference.Create("IWhat")), Undef.Create()),
                                                              ExpressionFactory.Readout(IsSame.Create(NameReference.Create("x"), NameReference.Create("y")))
                                                              )));


                resolver = NameResolver.Create(env);

                Assert.AreEqual(0, resolver.ErrorManager.Errors.Count);
            }

            return(resolver);
        }
示例#15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="textA"></param>
        /// <param name="textB"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        private DiffResult[] DiffCore(string textA, string textB, DiffOption option)
        {
            this.linesA = SplitLine(textA, option);
            this.linesB = SplitLine(textB, option);

            if (this.linesB.Length < this.linesA.Length)
            {
                this.isSwap = true;

                string[] tmps = this.linesA;
                this.linesA = this.linesB;
                this.linesB = tmps;
            }
            this.dataA = MakeHash(this.linesA);
            this.dataB = MakeHash(this.linesB);

            this.isSame = delegate(int posA, int posB)
            {
                return (this.dataA[posA] == this.dataB[posB]) && (this.linesA[posA] == this.linesB[posB]);
            };

            return DetectDiff();
        }