Exemplo n.º 1
0
        public void ShouldReturnFalseWhenComparingNonEmptyTextsWithDifferentValue()
        {
            var firstText  = NonEmptyText.Create(SampleTextValue).Value;
            var secondText = NonEmptyText.Create("another").Value;

            Assert.AreNotEqual(firstText, secondText);
        }
Exemplo n.º 2
0
        public void SholdReturnTrueWhenComparingNonEmptyTextsWithSameValue()
        {
            var firstText  = NonEmptyText.Create(SampleTextValue).Value;
            var secondText = NonEmptyText.Create(SampleTextValue).Value;

            Assert.AreEqual(firstText, secondText);
        }
Exemplo n.º 3
0
        public void ShouldCreateNonEmptyTextWithNonEmptyValueCorrectly()
        {
            const string textValue = SampleTextValue;

            var textResult = NonEmptyText.Create(textValue);

            Assert.IsTrue(textResult.IsSuccess);
            Assert.AreEqual(textValue, textResult.Value);
        }
Exemplo n.º 4
0
        public static ValueResult <Student> Create(string name)
        {
            var nameResult = NonEmptyText.Create(name);

            if (nameResult.IsFailure)
            {
                return(ValueResult <Student> .Fail(nameResult.Error));
            }

            return(ValueResult <Student> .Ok(new Student(nameResult.Value)));
        }
Exemplo n.º 5
0
        public Option <CodeSnippets> TryParse(NonEmptyText content)
        {
            Option <CodeSnippets> script = Option.Of(CodeSnippets.Empty);
            IText rest = content;

            while (script is Some <CodeSnippets> someScript &&
                   rest is NonEmptyText remaining &&
                   this.TryMatch(remaining) is Some <IPattern> somePattern &&
                   somePattern.Content is IPattern pattern)
            {
                Option <(IText newRest, CodeSnippets newScript)> newState = pattern.Apply(remaining, someScript);
                script = newState.Map(state => state.newScript);
                rest   = newState.Map(state => state.newRest).Reduce(rest);
            }

            return(script);
        }
Exemplo n.º 6
0
 private Option <IPattern> TryMatch(NonEmptyText content) =>
 this.Patterns.FirstOrNone(pattern => pattern.StartsWith.IsMatch(content.CurrentLine));
Exemplo n.º 7
0
        private Student(Id id, NonEmptyText name)
        {
            Id = Maybe <Id> .From(id);

            Name = name;
        }
Exemplo n.º 8
0
 private Student(NonEmptyText name)
 {
     Name = name;
 }
Exemplo n.º 9
0
 private Option <(int number, string terminator)> TryExtractPreamble(NonEmptyText text) =>
Exemplo n.º 10
0
 private Option <(IText remaining, CodeSnippets script)> ApplyBeforePreamble(NonEmptyText current, CodeSnippets script) =>
Exemplo n.º 11
0
 public Option <(IText remaining, CodeSnippets script)> Apply(NonEmptyText current, CodeSnippets script) =>
 this.ApplyBeforePreamble(current, script);
Exemplo n.º 12
0
        public void ShouldReturnResultFailWhenCreatingNonEmptyTextWithWhitespacesOnly()
        {
            var textResult = NonEmptyText.Create("     ");

            Assert.IsTrue(textResult.IsFailure);
        }
Exemplo n.º 13
0
        public void ShouldReturnResultFailWhenCreatingNonEmptyTextWithEmptyValue()
        {
            var textResult = NonEmptyText.Create(string.Empty);

            Assert.IsTrue(textResult.IsFailure);
        }
Exemplo n.º 14
0
 public Option <(IText remaining, CodeSnippets script)> Apply(NonEmptyText current, CodeSnippets script) =>