Ejemplo n.º 1
0
        /// <summary>
        /// Reads a list of blocks.
        /// </summary>
        private static List<BlockItem> ParseBlocks(string allText)
        {
            List<BlockItem> blocks = new List<BlockItem>();

            StringBuilder sb = new StringBuilder();
            BlockItem block = new BlockItem();

            string[] lines = allText.Split(
                new[] { "\r\n", "\r", "\n" },
                StringSplitOptions.None);

            foreach (string line in lines)
            {
                if (line.StartsWith("#region "))
                {
                    string[] parts = line.Substring(8).Split(new[] { " // " }, StringSplitOptions.None);
                    if (parts.Length == 0 || String.IsNullOrEmpty(parts[0]))
                        ThrowWrongTestFile();

                    block.Rule = parts[0];
                    if (parts.Length > 1)
                        block.Comment = parts[1];

                    continue;
                }

                if (line.StartsWith("#endregion"))
                {
                    block.Content = sb.ToString();
                    blocks.Add(block);

                    sb.Length = 0;
                    block = new BlockItem();
                    continue;
                }

                if (line.StartsWith("//# ("))
                {
                    string setting = line.Substring(5, line.Length - 6);
                    string[] parts = setting.Split(new[] { " = " }, 2, StringSplitOptions.None);
                    if (parts.Length != 2)
                        ThrowWrongTestFile();

                    string settingName = parts[0];
                    object settingValue = parts[1];

                    bool booleanValue;
                    if (Boolean.TryParse(parts[1], out booleanValue))
                        settingValue = booleanValue;

                    block.CustomSettings.Add(settingName, settingValue);

                    continue;
                }

                sb.AppendLine(line);
            }

            return blocks;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads a list of blocks.
        /// </summary>
        private static List <BlockItem> ParseBlocks(string allText)
        {
            List <BlockItem> blocks = new List <BlockItem>();

            StringBuilder sb    = new StringBuilder();
            BlockItem     block = new BlockItem();

            string[] lines = allText.Split(
                new[] { "\r\n", "\r", "\n" },
                StringSplitOptions.None);

            foreach (string line in lines)
            {
                if (line.StartsWith("#region "))
                {
                    string[] parts = line.Substring(8).Split(new[] { " // " }, StringSplitOptions.None);
                    if (parts.Length == 0 || String.IsNullOrEmpty(parts[0]))
                    {
                        ThrowWrongTestFile();
                    }

                    block.Rule = parts[0];
                    if (parts.Length > 1)
                    {
                        block.Comment = parts[1];
                    }

                    continue;
                }

                if (line.StartsWith("#endregion"))
                {
                    block.Content = sb.ToString();
                    blocks.Add(block);

                    sb.Length = 0;
                    block     = new BlockItem();
                    continue;
                }

                if (line.StartsWith("//# ("))
                {
                    string   setting = line.Substring(5, line.Length - 6);
                    string[] parts   = setting.Split(new[] { " = " }, 2, StringSplitOptions.None);
                    if (parts.Length != 2)
                    {
                        ThrowWrongTestFile();
                    }

                    string settingName  = parts[0];
                    object settingValue = parts[1];

                    bool booleanValue;
                    if (Boolean.TryParse(parts[1], out booleanValue))
                    {
                        settingValue = booleanValue;
                    }

                    block.CustomSettings.Add(settingName, settingValue);

                    continue;
                }

                sb.AppendLine(line);
            }

            return(blocks);
        }