示例#1
0
        private TestTrace <TParserToCheck> TestParse <TTopParser, TParserToCheck>(string parseString)
        {
            var rtn    = new TestTrace <TParserToCheck>();
            var result = Lexico.Parse <TTopParser>(parseString, rtn);

            return(rtn);
        }
示例#2
0
        public void CanRetrieveUserObjectValueType()
        {
            var myUserObject = 3.14f;
            var obj          = Lexico.Parse <ClassWithUserObject>("5", userObject: myUserObject);

            Assert.Equal(myUserObject, obj.UserObject);
        }
示例#3
0
        public void CanUseConcreteTypeForUserObject()
        {
            var myUserObject = 3.14f;
            var obj          = Lexico.Parse <ClassWithConcreteUserObject>("5", userObject: myUserObject);

            Assert.Equal(myUserObject, obj.UserObject);
        }
示例#4
0
        public void CanRetrieveUserObject()
        {
            var myUserObject = new object();
            var obj          = Lexico.Parse <ClassWithUserObject>("5", userObject: myUserObject);

            Assert.Equal(myUserObject, obj.UserObject);
        }
示例#5
0
        public void LexicoJsonWithNoOpTrace()
        {
            var result = Lexico.Parse <JsonDocument>(JsonString, new NoTrace());

            if (result.value == null)
            {
                throw new Exception("Parsing failed");
            }
        }
示例#6
0
 public void WriteProtectedField() => Assert.Equal(5, Lexico.Parse <ProtectedField>("5").Val);
示例#7
0
 public void CannotWriteReadonlyField() => Assert.NotEqual(5, Lexico.Parse <ReadonlyField>("5").Value);
示例#8
0
 public void WritePrivateSetProperty() => Assert.Equal(5, Lexico.Parse <GetOnlyPropWithPrivateSet>("5").Value);
示例#9
0
 public void CannotWriteGetOnlyProperty() => Assert.NotEqual(5, Lexico.Parse <GetOnlyProp>("5").Value);
示例#10
0
        public void WrongUserObjectTypeThrowsCastException()
        {
            var myUserObject = 3;

            Assert.Throws <InvalidCastException>(() => Lexico.Parse <ClassWithConcreteUserObject>("5", userObject: myUserObject));
        }
示例#11
0
 public void BadExplicitAlternativeType()
 {
     Assert.Throws <ArgumentException>(() => Lexico.Parse <TruthyWithInvalidAlternative>("true", new ConsoleDeveloperTrace()));
 }
示例#12
0
                                                                                                    regexPattern, config, flags);  // TODO: Don't pass in regexPattern, retrieve it by unparsing

        public static IParser Parse(string pattern, IConfig config, ParserFlags flags) => Lexico.Parse <Regex>(pattern).Create(pattern, config, flags);
示例#13
0
 public void OrderOfGenericSequenceCorrect() => Lexico.Parse <GenericWrapper>(" 5 ", new ConsoleDeveloperTrace());
示例#14
0
 public void SeperatorWithinRepeatedRecursive() => Lexico.Parse <List <RecBase> >("foobar,bar")
 .Should()
 .ContainEquivalentOf(new Recursive {
     RecBase = { new LiteralCase(), new LiteralCase() }
 });
示例#15
0
 public void OptionalRepeatOfNothingReturnsNull() => Assert.Null(Lexico.Parse <OptionalRepeat>("[]").List);
示例#16
0
 public void GenericRepeatParser() => Assert.Equal(Lexico.Parse <GenericRepeat <int> >("(1, 1, 3, 5, 7)").Values, new [] { 1, 1, 3, 5, 7 });