Ejemplo n.º 1
0
        public void ContextScope_Description_ReturnsParentDescription()
        {
            MockScope    parent       = new MockScope("special-desc");
            ContextScope contextScope = new ContextScope(parent, ValueTypeEnum.DateTime, true);

            Assert.AreEqual("special-desc", contextScope.Description);
        }
Ejemplo n.º 2
0
        public void Option_ProcessOption_PassesThroughCountError()
        {
            ExprFunc  func      = s => { throw new CountError(1); };
            MockScope mockScope = new MockScope();

            Option.ProcessOption("whence", func, mockScope, "arg", "name");
        }
Ejemplo n.º 3
0
        public void ScopeExtensions_SearchScope_ReturnsCurrentScopeIfSearchTypeMatches()
        {
            MockScope scope  = new MockScope();
            MockScope result = ScopeExtensions.SearchScope <MockScope>(scope);

            Assert.Equal(scope, result);
        }
Ejemplo n.º 4
0
        public void Option_ProcessEnvironment_IgnoresEmptyValues()
        {
            OptFunctScopes.Clear();

            MockScope mockScope = new MockScope();

            mockScope.LookupResult            = new ExprOp(OpKindEnum.FUNCTION);
            mockScope.LookupResult.AsFunction = OptFunct;

            IDictionary <string, string> envp = new Dictionary <string, string>();

            envp.Add("opt-1-1", "val1");
            envp.Add("opt-1-2", "val2");
            envp.Add("opt-2-1", "");
            envp.Add("opt-2-2", "val4");
            envp.Add("opt-3-1", "val5");
            envp.Add("opt-3-2", "val6");

            Option.ProcessEnvironment(envp, "opt-2", mockScope);

            Assert.AreEqual(1, OptFunctScopes.Count);
            CallScope callScope = OptFunctScopes.First() as CallScope;

            Assert.AreEqual(2, callScope.Size);
            Assert.AreEqual("$-2", callScope[0].ToString());
            Assert.AreEqual("val4", callScope[1].ToString());
        }
Ejemplo n.º 5
0
        public void Option_ProcessOption_PassesThroughCountError()
        {
            ExprFunc  func      = s => { throw new CountError(1, String.Empty); };
            MockScope mockScope = new MockScope();

            Assert.Throws <CountError>(() => Option.ProcessOption("whence", func, mockScope, "arg", "name"));
        }
Ejemplo n.º 6
0
        public void SymbolScope_Symbols_AreEmptyByDefault()
        {
            MockScope   mockScope   = new MockScope();
            SymbolScope symbolScope = new SymbolScope(mockScope);

            Assert.AreEqual(0, symbolScope.Symbols.Count);
        }
Ejemplo n.º 7
0
        public void ChildScope_Constructor_PopulatesParent()
        {
            MockScope      parent     = new MockScope();
            TestChildScope childScope = new TestChildScope(parent);

            Assert.AreEqual(parent, childScope.Parent);
        }
Ejemplo n.º 8
0
        public void SymbolScope_Description_ReturnsParentDesription()
        {
            MockScope   mockScope   = new MockScope();
            SymbolScope symbolScope = new SymbolScope(mockScope);

            Assert.Equal(mockScope.Description, symbolScope.Description);
        }
Ejemplo n.º 9
0
        public void SymbolScope_Symbols_AreEmptyByDefault()
        {
            MockScope   mockScope   = new MockScope();
            SymbolScope symbolScope = new SymbolScope(mockScope);

            Assert.Null(symbolScope.Symbols);  // By default, Symbols is empty until Define is called
        }
Ejemplo n.º 10
0
        public void ScopeExtensions_SearchScope_ReturnsNullIfNoSuccess()
        {
            MockScope scope  = new MockScope();
            Scope     result = ScopeExtensions.SearchScope <TestChildScope>(scope);

            Assert.Null(result);
        }
Ejemplo n.º 11
0
        public void ScopeExtensions_SearchScope_MakesReqursiveCallForChildScope()
        {
            MockScope  parent     = new MockScope();
            ChildScope childScope = new TestChildScope(parent);

            MockScope result = ScopeExtensions.SearchScope <MockScope>(childScope);

            Assert.Equal(parent, result);
        }
Ejemplo n.º 12
0
        public void ContextScope_Constructor_PopulatesParentTypeContextAndIsRequired()
        {
            MockScope    parent       = new MockScope();
            ContextScope contextScope = new ContextScope(parent, ValueTypeEnum.DateTime, true);

            Assert.AreEqual(parent, contextScope.Parent);
            Assert.AreEqual(ValueTypeEnum.DateTime, contextScope.TypeContext);
            Assert.IsTrue(contextScope.IsRequired);
        }
Ejemplo n.º 13
0
        public void CallScope_Context_LooksForParentContextByType()
        {
            MockScope parent    = new MockScope();
            CallScope callScope = new CallScope(parent);

            MockScope result = callScope.Context <MockScope>();

            Assert.Equal(parent, result);
        }
Ejemplo n.º 14
0
        public void ChildScope_Define_CallsParentDefine()
        {
            MockScope      parent     = new MockScope();
            TestChildScope childScope = new TestChildScope(parent);

            childScope.Define(SymbolKindEnum.FUNCTION, "dummy", new ExprOp());

            Assert.AreEqual(1, parent.DefineCalls.Count);
        }
Ejemplo n.º 15
0
        public void BindScope_Description_IsGrandChildDescription()
        {
            MockScope mockScope1 = new MockScope();
            MockScope mockScope2 = new MockScope("grand-child");

            BindScope bindScope = new BindScope(mockScope1, mockScope2);

            Assert.Equal(mockScope2.Description, bindScope.Description);
        }
Ejemplo n.º 16
0
        public void BindScope_Contructor_PopulatesGrandChild()
        {
            MockScope mockScope1 = new MockScope();
            MockScope mockScope2 = new MockScope();

            BindScope bindScope = new BindScope(mockScope1, mockScope2);

            Assert.Equal(mockScope1, bindScope.Parent);
            Assert.Equal(mockScope2, bindScope.GrandChild);
        }
Ejemplo n.º 17
0
        public void ScopeExtensions_SearchScope_MakesReqursiveCallForBindScope()
        {
            MockScope parent     = new MockScope();
            MockScope grandChild = new MockScope();
            BindScope bindScope  = new BindScope(parent, grandChild);

            MockScope result = ScopeExtensions.SearchScope <MockScope>(bindScope);

            Assert.Equal(grandChild, result);
        }
Ejemplo n.º 18
0
        public void BindScope_Lookup_CallsGrandChildLookupFirst()
        {
            MockScope mockScope1 = new MockScope();
            MockScope mockScope2 = new MockScope("grand-child");

            BindScope bindScope    = new BindScope(mockScope1, mockScope2);
            ExprOp    lookupResult = bindScope.Lookup(SymbolKindEnum.FUNCTION, "dummy");

            Assert.Equal(mockScope2.LookupResult, lookupResult);
            Assert.Equal(1, mockScope2.LookupCalls.Count);
        }
Ejemplo n.º 19
0
        public void CallScope_Get_ConvertsByDefault()
        {
            MockScope parent    = new MockScope();
            CallScope callScope = new CallScope(parent);

            callScope.Args = Value.Get(new List <Value>());
            callScope.Args.AsSequence.Add(Value.Get(new Amount(22)));

            int result = callScope.Get <int>(0); // convert is not specified; "true" by default

            Assert.Equal(22, result);            // Amount is automatically converted to int
        }
Ejemplo n.º 20
0
        public void CallScope_Get_SupportsDateTime()
        {
            MockScope parent    = new MockScope();
            CallScope callScope = new CallScope(parent);

            callScope.Args = Value.Get(new List <Value>());
            callScope.Args.AsSequence.Add(Value.Get(new DateTime(2015, 10, 22)));

            DateTime result = callScope.Get <DateTime>(0);

            Assert.Equal(new DateTime(2015, 10, 22), result);
        }
Ejemplo n.º 21
0
        public void CallScope_Resolve_UpdatesArgumentWithExpressionResult_ArgsIsSingleValue()
        {
            MockScope parent    = new MockScope();
            CallScope callScope = new CallScope(parent);

            callScope.Args = Value.Get(new Expr("\"ABC\"").Op);
            Value val1 = callScope.Resolve(0, ValueTypeEnum.String, true);

            Assert.Equal("ABC", val1.AsString);
            Assert.Equal(val1, callScope.Args);
            Assert.Equal(val1.AsString, callScope.Args.AsSequence[0].AsString);
        }
Ejemplo n.º 22
0
        public void CallScope_Contructor_PopulatesParentLocusDepth()
        {
            MockScope parentScope = new MockScope();
            ExprOp    locus       = new ExprOp();
            int       depth       = 9;

            CallScope callScope = new CallScope(parentScope, locus, depth);

            Assert.Equal(parentScope, callScope.Parent);
            Assert.Equal(locus, callScope.Locus);
            Assert.Equal(depth, callScope.Depth);
        }
Ejemplo n.º 23
0
        public void BindScope_Define_CallsParentAndGrandChildDefine()
        {
            MockScope mockScope1 = new MockScope();
            MockScope mockScope2 = new MockScope("grand-child");

            BindScope bindScope = new BindScope(mockScope1, mockScope2);

            bindScope.Define(SymbolKindEnum.FUNCTION, "dummy", new ExprOp());

            Assert.Equal(1, mockScope1.DefineCalls.Count);
            Assert.Equal(1, mockScope2.DefineCalls.Count);
        }
Ejemplo n.º 24
0
        public void Option_FindOption_ReplacesMinusWithUnderscoreForFirstSearch()
        {
            MockScope scope = new MockScope();

            scope.LookupResult = new ExprOp();

            Tuple <ExprOp, bool> result = Option.FindOption(scope, "search-name");

            Assert.AreEqual(scope.LookupResult, result.Item1);
            Assert.IsTrue(result.Item2);
            Assert.AreEqual(SymbolKindEnum.OPTION, scope.LookupCalls.First().Item1);
            Assert.AreEqual("search_name_", scope.LookupCalls.First().Item2);
        }
Ejemplo n.º 25
0
        public void Option_FindOption_RepeatsSearchingWithAnotherName()
        {
            MockScope scope = new MockScope();

            scope.LookupResult = null;

            Tuple <ExprOp, bool> result = Option.FindOption(scope, "search-name");

            Assert.IsNull(result.Item1);
            Assert.IsFalse(result.Item2);
            Assert.AreEqual(SymbolKindEnum.OPTION, scope.LookupCalls.Last().Item1);
            Assert.AreEqual("search_name", scope.LookupCalls.Last().Item2);
        }
Ejemplo n.º 26
0
        public void ChildScope_Lookup_CallsParentLookup()
        {
            MockScope parent = new MockScope()
            {
                LookupResult = new ExprOp()
            };
            TestChildScope childScope = new TestChildScope(parent);

            ExprOp result = childScope.Lookup(SymbolKindEnum.FUNCTION, "dummy");

            Assert.AreEqual(1, parent.LookupCalls.Count);
            Assert.AreEqual(result, parent.LookupResult);
        }
Ejemplo n.º 27
0
        public void BindScope_Lookup_CallsParentLookupNext()
        {
            MockScope mockScope1 = new MockScope();
            MockScope mockScope2 = new MockScope("grand-child");

            mockScope2.LookupResult = null;

            BindScope bindScope    = new BindScope(mockScope1, mockScope2);
            ExprOp    lookupResult = bindScope.Lookup(SymbolKindEnum.FUNCTION, "dummy");

            Assert.AreEqual(mockScope1.LookupResult, lookupResult);
            Assert.AreEqual(1, mockScope1.LookupCalls.Count);
            Assert.AreEqual(1, mockScope2.LookupCalls.Count);
        }
Ejemplo n.º 28
0
        public void SymbolScope_Define_AddsSymbolToSymbols()
        {
            MockScope   mockScope   = new MockScope();
            SymbolScope symbolScope = new SymbolScope(mockScope);

            SymbolKindEnum kind   = SymbolKindEnum.FUNCTION;
            string         name   = "the-name";
            ExprOp         exprOp = new ExprOp(OpKindEnum.CONSTANTS);

            symbolScope.Define(kind, name, exprOp);

            Assert.Equal(1, symbolScope.Symbols.Count);
            Assert.Equal(kind, symbolScope.Symbols.First().Key.Kind);
            Assert.Equal(name, symbolScope.Symbols.First().Key.Name);
            Assert.Equal(exprOp, symbolScope.Symbols.First().Key.Definition);
            Assert.Equal(exprOp, symbolScope.Symbols[symbolScope.Symbols.First().Key]);
        }
Ejemplo n.º 29
0
        public void CallScope_Resolve_UpdatesArgumentWithExpressionResult_ArgsIsSequence()
        {
            MockScope parent    = new MockScope();
            CallScope callScope = new CallScope(parent);

            callScope.Args = Value.Get(new List <Value>());
            callScope.Args.AsSequence.Add(Value.Get(new Expr("22").Op));
            callScope.Args.AsSequence.Add(Value.Get(new Expr("\"A\"").Op));

            Value val1 = callScope.Resolve(0, ValueTypeEnum.Amount, true);
            Value val2 = callScope.Resolve(1, ValueTypeEnum.String, true);

            Assert.Equal(22, val1.AsLong);
            Assert.Equal("A", val2.AsString);

            Assert.Equal(val1, callScope.Args.AsSequence[0]);
            Assert.Equal(val2, callScope.Args.AsSequence[1]);
        }
Ejemplo n.º 30
0
        public void SymbolScope_Lookup_TriesGetAValueFromSymbols()
        {
            MockScope   mockScope   = new MockScope();
            SymbolScope symbolScope = new SymbolScope(mockScope);

            SymbolKindEnum kind   = SymbolKindEnum.FUNCTION;
            string         name   = "the-name";
            ExprOp         exprOp = new ExprOp(OpKindEnum.CONSTANTS);

            symbolScope.Define(kind, name, exprOp);

            ExprOp result = symbolScope.Lookup(kind, name);

            Assert.Equal(exprOp, result);

            ExprOp result2 = symbolScope.Lookup(SymbolKindEnum.OPTION, "dummy");

            Assert.Equal(mockScope.LookupResult, result2);
        }