예제 #1
0
 public static Match2 CreateMatch(Msoft.Match msoftMatch)
 {
     if (msoftMatch.Success)
         return Factory.CreateMatch(msoftMatch.Index, msoftMatch.Length, msoftMatch.Value);
     else
         return Match2.Empty;
 }
예제 #2
0
파일: TRegex.cs 프로젝트: RoyCurtis/Toolbox
        public void ToArray()
        {
            var test     = "My number is 010 123-4567";
            var expected = new[] { "010 123-4567", "010", "123-4567" };
            var actual   = Regex.Match(test, "([0-9]{3,}) ([0-9]{3,3}-[0-9]{4,})").ToArray();

            CollectionAssert.AreEquivalent(expected, actual);
        }
예제 #3
0
파일: TRegex.cs 프로젝트: RoyCurtis/Toolbox
        public void TryMatch()
        {
            string[] actual;
            var test     = "Testing out tryMatch out";
            var expected = new[] { "out" };

            Assert.IsTrue( TRegex.TryMatch(test, "out", out actual) );
            CollectionAssert.AreEqual(expected, actual);
        }
        public void ThenCanSuccessfullyMatch()
        {
            var scenarioOutline = new ScenarioOutline {Name = "Adding several numbers"};
            var exampleRow = new[] {"40", "50", "90"};

            var signatureBuilder = Kernel.Get<xUnitExampleSignatureBuilder>();
            Regex signature = signatureBuilder.Build(scenarioOutline, exampleRow);

            signature.IsMatch("Pickles.TestHarness.xUnit.AdditionFeature.AddingSeveralNumbers(firstNumber: \"40\", secondNumber: \"50\", result: \"90\", exampleTags: System.String[])".ToLowerInvariant()).ShouldBeTrue();
        }
        public void ShouldApplyLimitUsingTop()
        {
            var sql = "select a,b,c from d where a = 1 order by c";
            var expected = new[] { "select top(5) a,b,c from d where a = 1 order by c" };

            var pagedSql = new SqlCe40QueryPager().ApplyLimit(sql, 5);
            var modified = pagedSql.Select(x => Normalize.Replace(x, " ").ToLowerInvariant());

            Assert.IsTrue(expected.SequenceEqual(modified));
        }
예제 #6
0
파일: TRegex.cs 프로젝트: RoyCurtis/Toolbox
        public void TryMatch_Extension()
        {
            string[] actual;
            var regex    = new Regex("out");
            var test     = "Testing out tryMatch out";
            var expected = new[] { "out" };

            Assert.IsTrue( regex.TryMatch(test, out actual) );
            CollectionAssert.AreEqual(expected, actual);
        }
예제 #7
0
        public void ShouldApplyPagingUsingOrderBy()
        {
            var sql = "select a,b,c from d where a = 1 order by c";
            var expected = new[]{
                "select a,b,c from d where a = 1 order by c offset 5 rows fetch next 10 rows only"};

            var pagedSql = new SqlCe40QueryPager().ApplyPaging(sql, 5, 10);
            var modified = pagedSql.Select(x=> Normalize.Replace(x, " ").ToLowerInvariant());

            Assert.IsTrue(expected.SequenceEqual(modified));
        }
예제 #8
0
 public static int LineCount(this string text)
 {
     var lineends = new[] { '\r', '\n' };
      int index = 0, count = 0;
      while ((index = 1 + text.IndexOfAny(lineends, index)) > 0)
      {
     count++;
     index += (text[index] == lineends[1]) ? 1 : 0;
      }
      return count;
 }
        public void ThenCanSuccessfullyMatchSpecialCharacters()
        {
            var scenarioOutline = new ScenarioOutline { Name = "Adding several numbers (foo-bar, foo bar)" };
            var exampleRow = new[] { "40", "50", "90" };

            var signatureBuilder = new NUnit3ExampleSignatureBuilder();
            Regex signature = signatureBuilder.Build(scenarioOutline, exampleRow);

            var isMatch = signature.IsMatch("AddingSeveralNumbersFoo_BarFooBar(\"40\",\"50\",\"90\",System.String[])".ToLowerInvariant());
            Check.That(isMatch).IsTrue();
        }
        public void ShouldApplyPagingUsingOrderByFirstColumnIfNotAlreadyOrdered()
        {
            var sql = "select a,b,c from d where a = 1";
            var expected = new[]{
                "select a,b,c from d where a = 1 order by a offset 10 rows fetch next 20 rows only"};

            var pagedSql = new SqlCe40QueryPager().ApplyPaging(sql, new string[0], 10, 20);
            var modified = pagedSql.Select(x => Normalize.Replace(x, " ").ToLowerInvariant());

            Assert.IsTrue(expected.SequenceEqual(modified));
        }
        public void ThenCanSuccessfullyMatch()
        {
            var scenarioOutline = new ScenarioOutline { Name = "Adding several numbers" };
            var exampleRow = new[] { "40", "50", "90" };

            var signatureBuilder = new NUnit2ExampleSignatureBuilder();
            Regex signature = signatureBuilder.Build(scenarioOutline, exampleRow);

            var isMatch = signature.IsMatch("Pickles.TestHarness.AdditionFeature.AddingSeveralNumbers(\"40\",\"50\",\"90\",System.String[])".ToLowerInvariant());
            Check.That(isMatch).IsTrue();
        }
예제 #12
0
        /// <summary>
        /// Retorna true se o CPF for válido
        /// </summary>
        public static bool IsValidCpf(string cpf)
        {
            cpf = cpf.OnlyNumbers();

            var multiplicador1 = new[] { 10, 9, 8, 7, 6, 5, 4, 3, 2 };
            var multiplicador2 = new[] { 11, 10, 9, 8, 7, 6, 5, 4, 3, 2 };

            int soma, resto;
            var isNum = IsNumber(cpf);

            if (isNum != true)
                return false;

            if (cpf.Length != 11)
                return false;

            if (cpf == "00000000000")
                return false;

            var tempCpf = cpf.Substring(0, 9);
            soma = 0;

            for (var i = 0; i < 9; i++)
            {
                soma += int.Parse(tempCpf[i].ToString()) * multiplicador1[i];
            }

            resto = soma % 11;
            if (resto < 2)
                resto = 0;
            else
                resto = 11 - resto;

            var digito = resto.ToString();

            tempCpf = tempCpf + digito;

            soma = 0;
            for (var i = 0; i < 10; i++)
                soma += int.Parse(tempCpf[i].ToString()) * multiplicador2[i];

            resto = soma % 11;
            if (resto < 2)
                resto = 0;
            else
                resto = 11 - resto;

            digito = digito + resto;

            return cpf.EndsWith(digito);
        }
        public void ThenCanSuccessfullyMatchExamplesWithLongValues()
        {
            var scenarioOutline = new ScenarioOutline { Name = "Deal correctly with overlong example values" };
            var exampleRow = new[]
            {
                "Please enter a valid two letter country code (e.g. DE)!",
                "This is just a very very very veery long error message!"
            };

            var signatureBuilder = new NUnit3ExampleSignatureBuilder();
            var signature = signatureBuilder.Build(scenarioOutline, exampleRow);

            var isMatch = signature.IsMatch("DealCorrectlyWithOverlongExampleValues(\"Please enter a valid two letter count...\",\"This is just a very very very veery l...\",null)".ToLowerInvariant());
            Check.That(isMatch).IsTrue();
        }
        public void ThenCanSuccessfullyMatchExamplesWithLongValues()
        {
            var scenarioOutline = new ScenarioOutline { Name = "Deal correctly with overlong example values" };
            var exampleRow = new[]
            {
                "Please enter a valid two letter country code (e.g. DE)!",
                "This is just a very very very veery long error message!"
            };

            var signatureBuilder = new XUnitExampleSignatureBuilder();
            var signature = signatureBuilder.Build(scenarioOutline, exampleRow);

            var isMatch = signature.IsMatch("Pickles.TestHarness.xunit2.ScenarioOutlinesFeature.DealCorrectlyWithOverlongExampleValues(value1: \"Please enter a valid two letter country code (e.g.\"..., value2: \"This is just a very very very veery long error mes\"..., exampleTags: [])".ToLowerInvariant());
            Check.That(isMatch).IsTrue();
        }
        private static bool MatchRegexSpecialChars(string expectedParameter)
        {
            var scenarioOutline = new ScenarioOutline { Name = "This scenario contains examples with Regex-special characters" };
            var exampleRow = new[] { expectedParameter };

            var signatureBuilder = new XUnitExampleSignatureBuilder();
            var signature = signatureBuilder.Build(scenarioOutline, exampleRow);

            var matchEntry = string
                .Format(
                    "Pickles.TestHarness.xunit2.ScenariosWithSpecialCharactersFeature.ThisScenarioContainsExamplesWithRegex_SpecialCharacters(regex: \"{0}\", exampleTags: System.String[])",
                    expectedParameter)
                .ToLowerInvariant();

            return signature.IsMatch(matchEntry);
        }
        public CreateFileDialog()
        {
            InitializeComponent();

            var mainFileTypes = new[]
            {
                ".txt",
                ".doc",
                ".docx",
                ".xls",
                ".bmp",
                "..."
            };
            CbFileType.ItemsSource = mainFileTypes;
            CbFileType.SelectedIndex = 0;
        }
예제 #17
0
		public void ShouldThrowIfRegExIsMissing()
		{
			const string wordToMatch = "the toggle";

			var content = new[]
			{
				"sometoggle=myRegex"
			};
			var mappings = new DefaultSpecificationMappings();
			mappings.AddMapping("myRegex", new RegExSpecification(new Regex("^" + wordToMatch + "$")));

			Assert.Throws<IncorrectTextFileException>(() => 
				new ToggleConfiguration(new FileParser(new FileReaderStub(content), mappings))
				.Create()).ToString()
			.Should().Contain(string.Format(RegExSpecification.MustDeclareRegexPattern, "sometoggle"));
		}
예제 #18
0
		public void ShouldHandleMiss()
		{
			const string wordToMatch = "the toggle";

			var content = new[]
			{
				"sometoggle=myRegex",
				"sometoggle.myRegex." + RegExSpecification.RegExParameter + "=" + wordToMatch
			};
			var mappings = new DefaultSpecificationMappings();
			mappings.AddMapping("myRegex", new RegExSpecification(new Regex("^somethingelse$")));

			var toggleChecker = new ToggleConfiguration(new FileParser(new FileReaderStub(content), mappings))
				.Create();

			toggleChecker.IsEnabled("sometoggle")
				.Should().Be.False();
		}
예제 #19
0
		static RegexCollection()
		{
			string[] tags = new[] {
				@"<base.*?[^>]>([\s\S]?<\/base>)?",
				@"<meta.*?(\s\w+=[""].[^""]*[""])*[^>]*>([\s\S]?<\/meta>)?",
				@"<link.*?[^>]>([\s\S]?<\/link>)?",
				@"<style\b[^>]*>[\s\S]*?<\/style>",
				@"<script\b[^>]*>[\s\S]*?<\/script>"
			};

			RegexOptions defaultRegexOptions =
				RegexOptions.Compiled
				| RegexOptions.Multiline
				| RegexOptions.CultureInvariant
				;

			Tags = new Regex(string.Join("|", tags), defaultRegexOptions);

			Head = new Regex(@"<head.*?>", defaultRegexOptions);

			End = new Regex(@"<\/body>", defaultRegexOptions);
		}
        public static void AssertMatches(E.MatchCollection<char> matches, STR.MatchCollection regexMatches)
        {
            if (matches == null && regexMatches == null)
            return;
             if (matches == null)
            Assert.Fail ("matches == null");
             if (regexMatches == null)
            Assert.Fail ("regexMatches == null");

             Assert.AreEqual (regexMatches.Count, matches.Count, "matches.Count");
             for (int i = 0; i < regexMatches.Count; i++)
             {
            var rMatch = regexMatches[i];
            var eMatch = matches[i];

            Assert.AreEqual (rMatch.Index, eMatch.Index, "Index of match " + i);
            Assert.AreEqual (rMatch.Length, eMatch.Length, "Length of match " + i);

            string rValue = rMatch.Value;
            string eValue = new string (eMatch.Items.ToArray ());
            Assert.AreEqual (rValue.Length, eValue.Length, "Value of match " + i);
             }
        }
예제 #21
0
                public void Properties(string prop1, string prop2, string prop3)
                {
                    var properties = new [] { prop1, prop2, prop3 };

                    var account = new BankAccount(BankAccountTest.NUMBER,
                            BankAccountTest.SORTCODE, BankAccountTest.NAME);

                    var serialize = account.Serialize(SerializeMethod.FixedWidth, properties);

                    var composed = "";
                    foreach(var prop in properties)
                    {
                        var p = typeof(ISerializedAccount).GetProperty(prop);
                        composed += p.GetValue(serialize, null).ToString();
                    }

                    Assert.Equal(composed, serialize.Line);
                }
예제 #22
0
        public void VerifyRows(string column, string dataValue, string dataFormat = null)
        {
            var tableName = "Import_" + column;
              var columnNames = new[] {column};
              var dataValues = new[] { new[] { dataValue } };

              CreateTable(tableName, column);
              ImportRows(tableName, columnNames, dataValues);
              VerifyRows(tableName, columnNames, dataValues, dataFormat);
        }
예제 #23
0
		public void TestLessThanDecimal()
		{
			var model = new { value = new decimal(-10.5) };

			string output = Template.Parse("{% if model.value < 0 %}passed{% endif %}")
				.Render(Hash.FromAnonymousObject(new { model }));

			Assert.AreEqual("passed", output);
		}
예제 #24
0
 public static Match2[] CreateMatches(Msoft.MatchCollection msoftMatches)
 {
     return msoftMatches.Cast<Msoft.Match>()
                        .Select(m => CreateMatch(m))
                        .ToArray();
 }
예제 #25
0
파일: gzjs.cs 프로젝트: akinomyoga/agh
 /// <summary>
 /// 読み取った引数の内容を正規化します。(trim, dequotation)
 /// </summary>
 static string ReadArg(Rgx::Group g){
   string ret=g.Value.Trim();
   if(ret.Length>=2){
     if(ret[0]=='"'||ret[0]=='\''){
       ret=Rgx::Regex.Unescape(ret.Substring(1,ret.Length-2));
     }else if(ret[0]=='/'){
       ret=ret.Substring(1,ret.Length-2);
     }
   }
   return ret;
 }
예제 #26
0
    /// <summary>
    /// Validates an html tag against the allowedTags. Also check that
    /// it doesn't have any "extra" features such as javascript in it.
    /// </summary>
    /// <param name="tag">
    /// </param>
    /// <param name="allowedTags">
    /// </param>
    /// <returns>
    /// The is valid tag.
    /// </returns>
    public static bool IsValidTag(string tag, IEnumerable<string> allowedTags)
    {
      if (tag.IndexOf("javascript") >= 0)
      {
        return false;
      }

      if (tag.IndexOf("vbscript") >= 0)
      {
        return false;
      }

      if (tag.IndexOf("onclick") >= 0)
      {
        return false;
      }

      var endchars = new[]
        {
          ' ', '>', '/', '\t'
        };

      int pos = tag.IndexOfAny(endchars, 1);
      if (pos > 0)
      {
        tag = tag.Substring(0, pos);
      }

      if (tag[0] == '/')
      {
        tag = tag.Substring(1);
      }

      // check if it's a valid tag
      return allowedTags.Any(allowedTag => tag == allowedTag);
    }
예제 #27
0
파일: reptxt.cs 프로젝트: akinomyoga/agh
 public string GetProcessedAfter(Rgx::Match match)
 {
     string ret=this.after;
     ret=reg_after.Replace(ret,delegate(Rgx::Match m){
         //System.Console.WriteLine("replacement match: "+m.Value);
         if(m.Groups["num"].Success){
             int n=int.Parse(m.Groups["num"].Value);
             if(n==0)
                 return match.Value;
             Rgx::Group g=match.Groups[n];
             if(g!=null&&g.Success)
                 return g.Value;
         }else if(m.Groups["name"].Success){
             Rgx::Group g=match.Groups[m.Groups["name"].Value];
             if(g!=null&&g.Success)
                 return g.Value;
         }else switch(m.Groups["cmd"].Value){
             case "include":
                 string fname=m.Groups["arg"].Value.Trim();
                 fname=System.IO.Path.Combine(this.directory,fname);
                 if(!System.IO.File.Exists(fname))break;
                 return System.IO.File.ReadAllText(fname);
         }
         return m.Value;
     });
     return ret;
 }
예제 #28
0
        /// <summary>
        /// Retorna true se o CNPJ for válido
        /// </summary>
        public static bool IsValidCnpj(string cnpj)
        {
            if (cnpj != null)
            {
                cnpj = cnpj.OnlyNumbers();
            }

            var multiplicador1 = new[] { 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 };
            var multiplicador2 = new[] { 6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 };

            int soma, resto;
            var isNum = IsNumber(cnpj);

            cnpj = (cnpj ?? "").Trim();

            if (isNum != true)
                return false;

            if (cnpj.Length != 14)
                return false;

            var tempCnpj = cnpj.Substring(0, 12);

            soma = 0;
            for (var i = 0; i < 12; i++)
            {
                soma += int.Parse(tempCnpj[i].ToString()) * multiplicador1[i];
            }

            resto = (soma % 11);
            if (resto < 2)
                resto = 0;
            else
                resto = 11 - resto;

            var digito = resto.ToString();

            tempCnpj = tempCnpj + digito;
            soma = 0;
            for (var i = 0; i < 13; i++)
                soma += int.Parse(tempCnpj[i].ToString()) * multiplicador2[i];

            resto = (soma % 11);
            if (resto < 2)
                resto = 0;
            else
                resto = 11 - resto;

            digito = digito + resto;

            return cnpj.EndsWith(digito);
        }