Example #1
0
        public static IEnumerable <object[]> Strings(DescriptionFallback fallback) =>
        from t in new[]
        {
            new
            {
                Description = "a single basic code point",
                Decoded     = "Bach",
                Encoded     = "Bach-"
            },
            new
            {
                Description = "a single non-ASCII character",
                Decoded     = "\xFC",
                Encoded     = "tda"
            },
            new
            {
                Description = "multiple non-ASCII characters",
                Decoded     = "\xFC\xEB\xE4\xF6\u2665",
                Encoded     = "4can8av2009b"
            },
            new
            {
                Description = "mix of ASCII and non-ASCII characters",
                Decoded     = "b\xFC" + "cher",
                Encoded     = "bcher-kva"
            },
            new
            {
                Description = "long string with both ASCII and non-ASCII characters",
                Decoded     = "Willst du die Bl\xFCthe des fr\xFChen, die Fr\xFC" + "chte des sp\xE4teren Jahres",
                Encoded     = "Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal"
            },
            // https://tools.ietf.org/html/rfc3492#section-7.1
            new
            {
                Description = "Arabic (Egyptian)",
                Decoded     = "\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648\u0634\u0639\u0631\u0628\u064A\u061F",
                Encoded     = "egbpdaj6bu4bxfgehfvwxn"
            },
            new
            {
                Description = "Chinese (simplified)",
                Decoded     = "\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2d\u6587",
                Encoded     = "ihqwcrb4cv8a8dqg056pqjye"
            },
            new
            {
                Description = "Chinese (traditional)",
                Decoded     = "\u4ED6\u5011\u7232\u4EC0\u9EBD\u4E0D\u8AAA\u4E2D\u6587",
                Encoded     = "ihqwctvzc91f659drss3x8bo0yb"
            },
            new
            {
                Description = "Czech",
                Decoded     = "Pro\u010Dprost\u011Bnemluv\xED\u010Desky",
                Encoded     = "Proprostnemluvesky-uyb24dma41a"
            },
            new
            {
                Description = "Hebrew",
                Decoded     = "\u05DC\u05DE\u05D4\u05D4\u05DD\u05E4\u05E9\u05D5\u05D8\u05DC\u05D0\u05DE\u05D3\u05D1\u05E8\u05D9\u05DD\u05E2\u05D1\u05E8\u05D9\u05EA",
                Encoded     = "4dbcagdahymbxekheh6e0a7fei0b"
            },
            new
            {
                Description = "Hindi (Devanagari)",
                Decoded     = "\u092F\u0939\u0932\u094B\u0917\u0939\u093F\u0928\u094D\u0926\u0940\u0915\u094D\u092F\u094B\u0902\u0928\u0939\u0940\u0902\u092C\u094B\u0932\u0938\u0915\u0924\u0947\u0939\u0948\u0902",
                Encoded     = "i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd"
            },
            new
            {
                Description = "Japanese (kanji and hiragana)",
                Decoded     = "\u306A\u305C\u307F\u3093\u306A\u65E5\u672C\u8A9E\u3092\u8A71\u3057\u3066\u304F\u308C\u306A\u3044\u306E\u304B",
                Encoded     = "n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa"
            },
            new
            {
                Description = "Korean (Hangul syllables)",
                Decoded     = "\uC138\uACC4\uC758\uBAA8\uB4E0\uC0AC\uB78C\uB4E4\uC774\uD55C\uAD6D\uC5B4\uB97C\uC774\uD574\uD55C\uB2E4\uBA74\uC5BC\uB9C8\uB098\uC88B\uC744\uAE4C",
                Encoded     = "989aomsvi5e83db1d2a355cv1e0vak1dwrv93d5xbh15a0dt30a5jpsd879ccm6fea98c"
            },

            /**
             * As there's no way to do it in JavaScript, Punycode.js doesn't support
             * mixed-case annotation (which is entirely optional as per the RFC).
             * So, while the RFC sample string encodes to:
             * `b1abfaaepdrnnbgefbaDotcwatmq2g4l`
             * Without mixed-case annotation it has to encode to:
             * `b1abfaaepdrnnbgefbadotcwatmq2g4l`
             * https://github.com/bestiejs/punycode.js/issues/3
             */
            new
            {
                Description = "Russian (Cyrillic)",
                Decoded     = "\u043F\u043E\u0447\u0435\u043C\u0443\u0436\u0435\u043E\u043D\u0438\u043D\u0435\u0433\u043E\u0432\u043E\u0440\u044F\u0442\u043F\u043E\u0440\u0443\u0441\u0441\u043A\u0438",
                Encoded     = "b1abfaaepdrnnbgefbadotcwatmq2g4l"
            },
            new
            {
                Description = "Spanish",
                Decoded     = "Porqu\xE9nopuedensimplementehablarenEspa\xF1ol",
                Encoded     = "PorqunopuedensimplementehablarenEspaol-fmd56a"
            },
            new
            {
                Description = "Vietnamese",
                Decoded     = "T\u1EA1isaoh\u1ECDkh\xF4ngth\u1EC3ch\u1EC9n\xF3iti\u1EBFngVi\u1EC7t",
                Encoded     = "TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g"
            },
            new
            {
                Description = default(string),
                Decoded     = "3\u5E74B\u7D44\u91D1\u516B\u5148\u751F",
                Encoded     = "3B-ww4c5e180e575a65lsy2b"
            },
            new
            {
                Description = default(string),
                Decoded     = "\u5B89\u5BA4\u5948\u7F8E\u6075-with-SUPER-MONKEYS",
                Encoded     = "-with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n"
            },
            new
            {
                Description = default(string),
                Decoded     = "Hello-Another-Way-\u305D\u308C\u305E\u308C\u306E\u5834\u6240",
                Encoded     = "Hello-Another-Way--fc4qua05auwb3674vfr0b"
            },
            new
            {
                Description = default(string),
                Decoded     = "\u3072\u3068\u3064\u5C4B\u6839\u306E\u4E0B2",
                Encoded     = "2-u9tlzr9756bt3uc0v"
            },
            new
            {
                Description = default(string),
                Decoded     = "Maji\u3067Koi\u3059\u308B5\u79D2\u524D",
                Encoded     = "MajiKoi5-783gue6qz075azm5e"
            },
            new
            {
                Description = default(string),
                Decoded     = "\u30D1\u30D5\u30A3\u30FCde\u30EB\u30F3\u30D0",
                Encoded     = "de-jg4avhby1noc0d"
            },
            new
            {
                Description = default(string),
                Decoded     = "\u305D\u306E\u30B9\u30D4\u30FC\u30C9\u3067",
                Encoded     = "d9juau41awczczp"
            },

            /**
             * This example is an ASCII string that breaks the existing rules for host
             * name labels. (It's not a realistic example for IDNA, because IDNA never
             * encodes pure ASCII labels.)
             */
            new
            {
                Description = "ASCII string that breaks the existing rules for host-name labels",
                Decoded     = "-> $1.00 <-",
                Encoded     = "-> $1.00 <--"
            }
        }
        select new object[]
        {
            Fallback(t.Description, fallback, t.Decoded, t.Encoded),
            t.Decoded,
            t.Encoded
        };
Example #2
0
 static string Fallback(string description, DescriptionFallback fallback, string decoded, string encoded) =>
 description ?? (fallback == DescriptionFallback.Decoded ? decoded
                    : fallback == DescriptionFallback.Encoded ? encoded
                    : null);
Example #3
0
        #pragma warning restore xUnit1026

        public static IEnumerable <object[]> Domains(DescriptionFallback fallback) =>
        from t in new[]
        {
            new
            {
                Description = default(string),
                Decoded     = "ma\xF1" + "ana.com",
                Encoded     = "xn--maana-pta.com"
            },
            new
            {     // https://github.com/bestiejs/punycode.js/issues/17
                Description = default(string),
                Decoded     = "example.com.",
                Encoded     = "example.com."
            },
            new
            {
                Description = default(string),
                Decoded     = "b\xFC" + "cher.com",
                Encoded     = "xn--bcher-kva.com"
            },
            new
            {
                Description = default(string),
                Decoded     = "caf\xE9.com",
                Encoded     = "xn--caf-dma.com"
            },
            new
            {
                Description = default(string),
                Decoded     = "\u2603-\u2318.com",
                Encoded     = "xn----dqo34k.com"
            },
            new
            {
                Description = default(string),
                Decoded     = "\uD400\u2603-\u2318.com",
                Encoded     = "xn----dqo34kn65z.com"
            },
            new
            {
                Description = "Emoji",
                Decoded     = "\uD83D\uDCA9.la",
                Encoded     = "xn--ls8h.la"
            },
            new
            {
                Description = "Non-printable ASCII",
                Decoded     = "\0\x01\x02" + "foo.bar",
                Encoded     = "\0\x01\x02" + "foo.bar"
            },
            new
            {
                Description = "Email address",
                Decoded     = "\u0434\u0436\u0443\u043C\u043B\u0430@\u0434\u0436p\u0443\u043C\u043B\u0430\u0442\u0435\u0441\u0442.b\u0440\u0444a",
                Encoded     = "\u0434\u0436\u0443\u043C\u043B\[email protected]"
            }
        }
        select new object[]
        {
            Fallback(t.Description, fallback, t.Decoded, t.Encoded),
            t.Decoded,
            t.Encoded
        };