<commit_before>﻿using System;
using System.CodeDom;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetTools;

namespace IPRange.Test
{
    [TestClass]
    public class IPAddressRangeParseTest
    {
        public TestContext TestContext { get; set; }


        [TestMethod]
        [TestCase("192.168.60.13", "192.168.60.13", "192.168.60.13")]
        [TestCase("  192.168.60.13  ", "192.168.60.13", "192.168.60.13")]
        [TestCase("fe80::d503:4ee:3882:c586", "fe80::d503:4ee:3882:c586", "fe80::d503:4ee:3882:c586")]
        [TestCase("  fe80::d503:4ee:3882:c586  ", "fe80::d503:4ee:3882:c586", "fe80::d503:4ee:3882:c586")]
        [TestCase("3232252004", "192.168.64.100", "192.168.64.100")] // decimal - new 
        [TestCase("  3232252004  ", "192.168.64.100", "192.168.64.100")] // decimal - new 

        [TestCase("172.16.31.10/19", "172.16.31.10", "192.168.127.12")]
        [TestCase("  172.16.31.10  /  19  ", "172.16.31.10", "192.168.127.12")]
        [TestCase("192.168.1.0/255.255.255.0", "192.168.1.0", "192.168.1.255")]
        [TestCase("  192.168.1.0  /  255.255.255.0  ", "192.168.1.0", "192.168.1.255")]
        [TestCase("3232252004/24", "192.168.64.0", "192.168.64.255")] // decimal - new 
        [TestCase("  3232252004  /  24  ", "192.168.64.0", "192.168.64.255")] // decimal - new 

        [TestCase("192.168.60.26–192.168.60.37", "192.168.60.26", "192.168.60.37")]
        [TestCase("  192.168.60.26  –  192.168.60.37  ", "192.168.60.26", "192.168.60.37")]
        [TestCase("fe80::c586-fe80::c600", "fe80::c586", "fe80::c600")]
        [TestCase("  fe80::c586  -  fe80::c600  ", "fe80::c586", "fe80::c600")]
        [TestCase("3232252004-3232252504", "192.168.64.100", "192.168.66.88")]
        [TestCase("  3232252004  -  3232252504  ", "192.168.64.100", "192.168.66.88")]

        // with "dash (–)" (0x2013) is also support.
        [TestCase("192.168.61.26–192.168.61.37", "192.168.61.26", "192.168.61.37")]
        [TestCase("  192.168.61.26  –  192.168.61.37  ", "192.168.61.26", "192.168.61.37")]
        [TestCase("fe80::c586–fe80::c600", "fe80::c586", "fe80::c600")]
        [TestCase("  fe80::c586  –  fe80::c600  ", "fe80::c586", "fe80::c600")]
        [TestCase("3232252004–3232252504", "192.168.64.100", "192.168.66.88")]
        [TestCase("  3232252004  –  3232252504  ", "192.168.64.100", "192.168.66.88")]
        [TestCase("192.168.1.1-7", "192.168.1.1", "192.168.1.7")]

        // IPv6 with scope id (scope id should be stripped in begin/end properties.)
        [TestCase("fe80::0%eth0/112", "fe80::", "fe80::ffff")]
        [TestCase("fe80::8000%12-fe80::80ff%12", "fe80::8000", "fe80::80ff")]
        [TestCase("fe80::1%lo1", "fe80::1", "fe80::1")]
        public void ParseSucceeds()
        {
            TestContext.Run((string input, string expectedBegin, string expectedEnd) =>
            {
                Console.WriteLine("TestCase: \"{0}\", Expected Begin: {1}, End: {2}", input, expectedBegin, expectedEnd);
                var range = IPAddressRange.Parse(input);
                range.IsNotNull();
                Console.WriteLine("  Result: Begin: {0}, End: {1}", range.Begin, range.End);
                range.Begin.ToString().Is(expectedBegin);
                range.End.ToString().Is(expectedEnd);
            });
        }

        [TestMethod]
        [TestCase(null, typeof(ArgumentNullException))]
        [TestCase("", typeof(FormatException))]
        [TestCase(" ", typeof(FormatException))]
        [TestCase("gvvdv", typeof(FormatException))]
        [TestCase("192.168.0.10/48", typeof(FormatException))] // out of CIDR range 
        [TestCase("192.168.0.10-192.168.0.5", typeof(ArgumentException))] // bigger to lower
        [TestCase("fe80::2%eth1-fe80::1%eth1", typeof(ArgumentException))] // bigger to lower
        [TestCase("10.256.1.1", typeof(FormatException))] // invalid ip
        [TestCase("127.0.0.1%1", typeof(FormatException))] // ipv4, but with scope id
        public void ParseFails()
        {
            TestContext.Run((string input, Type expectedException) =>
            {
                Console.WriteLine("TestCase: \"{0}\", Expected Exception: {1}", input, expectedException.Name);
                try
                {
                    IPAddressRange.Parse(input);
                    Assert.Fail("Expected exception of type {0} to be thrown for input \"{1}\"", expectedException.Name, input);<commit_msg>Add test cases for more strict check about implementation of IPv4 shortcut notation is valid or not.<commit_after>﻿using System;
using System.CodeDom;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetTools;

namespace IPRange.Test
{
    [TestClass]
    public class IPAddressRangeParseTest
    {
        public TestContext TestContext { get; set; }


        [TestMethod]
        [TestCase("192.168.60.13", "192.168.60.13", "192.168.60.13")]
        [TestCase("  192.168.60.13  ", "192.168.60.13", "192.168.60.13")]
        [TestCase("fe80::d503:4ee:3882:c586", "fe80::d503:4ee:3882:c586", "fe80::d503:4ee:3882:c586")]
        [TestCase("  fe80::d503:4ee:3882:c586  ", "fe80::d503:4ee:3882:c586", "fe80::d503:4ee:3882:c586")]
        [TestCase("3232252004", "192.168.64.100", "192.168.64.100")] // decimal - new 
        [TestCase("  3232252004  ", "192.168.64.100", "192.168.64.100")] // decimal - new 

        [TestCase("172.16.31.10/19", "172.16.31.10", "192.168.127.12")]
        [TestCase("  172.16.31.10  /  19  ", "172.16.31.10", "192.168.127.12")]
        [TestCase("192.168.1.0/255.255.255.0", "192.168.1.0", "192.168.1.255")]
        [TestCase("  192.168.1.0  /  255.255.255.0  ", "192.168.1.0", "192.168.1.255")]
        [TestCase("3232252004/24", "192.168.64.0", "192.168.64.255")] // decimal - new 
        [TestCase("  3232252004  /  24  ", "192.168.64.0", "192.168.64.255")] // decimal - new 

        [TestCase("192.168.60.26–192.168.60.37", "192.168.60.26", "192.168.60.37")]
        [TestCase("  192.168.60.26  –  192.168.60.37  ", "192.168.60.26", "192.168.60.37")]
        [TestCase("fe80::c586-fe80::c600", "fe80::c586", "fe80::c600")]
        [TestCase("  fe80::c586  -  fe80::c600  ", "fe80::c586", "fe80::c600")]
        [TestCase("3232252004-3232252504", "192.168.64.100", "192.168.66.88")]
        [TestCase("  3232252004  -  3232252504  ", "192.168.64.100", "192.168.66.88")]

        // with "dash (–)" (0x2013) is also support.
        [TestCase("192.168.61.26–192.168.61.37", "192.168.61.26", "192.168.61.37")]
        [TestCase("  192.168.61.26  –  192.168.61.37  ", "192.168.61.26", "192.168.61.37")]
        [TestCase("fe80::c586–fe80::c600", "fe80::c586", "fe80::c600")]
        [TestCase("  fe80::c586  –  fe80::c600  ", "fe80::c586", "fe80::c600")]
        [TestCase("3232252004–3232252504", "192.168.64.100", "192.168.66.88")]
        [TestCase("  3232252004  –  3232252504  ", "192.168.64.100", "192.168.66.88")]
        [TestCase("192.168.1.1-7", "192.168.1.1", "192.168.1.7")]

        // IPv6 with scope id (scope id should be stripped in begin/end properties.)
        [TestCase("fe80::0%eth0/112", "fe80::", "fe80::ffff")]
        [TestCase("fe80::8000%12-fe80::80ff%12", "fe80::8000", "fe80::80ff")]
        [TestCase("fe80::1%lo1", "fe80::1", "fe80::1")]
        public void ParseSucceeds()
        {
            TestContext.Run((string input, string expectedBegin, string expectedEnd) =>
            {
                Console.WriteLine("TestCase: \"{0}\", Expected Begin: {1}, End: {2}", input, expectedBegin, expectedEnd);
                var range = IPAddressRange.Parse(input);
                range.IsNotNull();
                Console.WriteLine("  Result: Begin: {0}, End: {1}", range.Begin, range.End);
                range.Begin.ToString().Is(expectedBegin);
                range.End.ToString().Is(expectedEnd);
            });
        }

        [TestMethod]
        [TestCase(null, typeof(ArgumentNullException))]
        [TestCase("", typeof(FormatException))]
        [TestCase(" ", typeof(FormatException))]
        [TestCase("gvvdv", typeof(FormatException))]
        [TestCase("192.168.0.10/48", typeof(FormatException))] // out of CIDR range 
        [TestCase("192.168.0.10-192.168.0.5", typeof(ArgumentException))] // bigger to lower
        [TestCase("fe80::2%eth1-fe80::1%eth1", typeof(ArgumentException))] // bigger to lower
        [TestCase("10.256.1.1", typeof(FormatException))] // invalid ip
        [TestCase("127.0.0.1%1", typeof(FormatException))] // ipv4, but with scope id
        [TestCase("192.168.0.0-192.168.0.1%1", typeof(FormatException))] // ipv4, but with scope id at end of range
        [TestCase("192.168.0.0%1-192.168.0.1", typeof(FormatException))] // ipv4, but with scope id at begin of range
        [TestCase("192.168.0.0%1-192.168.0.1%1", typeof(FormatException))] // ipv4, but with scope id at both of begin and end
        [TestCase("192.168.0.0%1/24", typeof(FormatException))] // CIDR ipv4, but with scope id
        [TestCase("192.168.0.0%1/255.255.255.0", typeof(FormatException))] // ipv4 and subnet mask, but with scope id
        [TestCase("192.168-::1", typeof(FormatException))] // Invalid comibination of IPv4 and IPv6
        [TestCase("192.168.0.0-256", typeof(FormatException))] // shortcut notation, but out of range
        [TestCase("192.168.0.0-1%1", typeof(FormatException))] // ipv4 shortcut, but with scope id at end of range
        [TestCase("192.168.0.0%1-1", typeof(FormatException))] // ipv4 shortcut, but with scope id at begin of range
        public void ParseFails()
        {
            TestContext.Run((string input, Type expectedException) =>
            {
                Console.WriteLine("TestCase: \"{0}\", Expected Exception: {1}", input, expectedException.Name);
                try
                {
                    IPAddressRange.Parse(input);
                    Assert.Fail("Expected exception of type {0} to be thrown for input \"{1}\"", expectedException.Name, input);
{'fraction_non_alphanumeric': 0.19888290444843407, 'fraction_numerical': 0.2004787552363854, 'mean_word_length': 2.646181818181818, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 130, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5442393', 'n_tokens_mistral': 4729, 'n_tokens_neox': 3550, 'n_words': 620}