public void TestCharacterCount()
        {
            Assert.AreEqual("no change".Length, ParseUtils.CountCharacters("no change", 4));
            Assert.AreEqual("_converted one tab".Length, ParseUtils.CountCharacters("    converted one tab", 4));
            Assert.AreEqual("__converted two tabs".Length, ParseUtils.CountCharacters("        converted two tabs", 4));
            Assert.AreEqual("only    convert    leading    spaces    ".Length, ParseUtils.CountCharacters("only    convert    leading    spaces    ", 4));

            Assert.AreEqual("__".Length, ParseUtils.CountCharacters("     ", 4)); // 5 spaces => 1 tab 1 space
            Assert.AreEqual("___".Length, ParseUtils.CountCharacters("   ", 1));  // 3 spaces => 3 tabs
        }
Exemple #2
0
        protected virtual void ProcessFileContents(File file, Variables.Root variables)
        {
            string[] contents = file.Contents.Split('\n');

            int lineCount = 0, charCount = 0, maxCharsPerLine = 0;

            foreach (string line in contents)
            {
                if (!line.Trim().Equals("{"))
                {
                    ++lineCount;
                }

                if (line.Length > 0)
                {
                    int realLength = ParseUtils.CountCharacters(line);

                    charCount      += realLength;
                    maxCharsPerLine = Math.Max(maxCharsPerLine, realLength);
                }
            }

            variables.Increment(Key + "LinesTotal", lineCount);
            variables.Increment(Key + "CharsTotal", charCount);
            variables.Maximum(Key + "LinesMax", lineCount);
            variables.Maximum(Key + "CharsMax", charCount);
            variables.Maximum(Key + "CharsPerLineMax", maxCharsPerLine);

            State state = variables.GetStateObject <State>(stateOwner);

            FileIntValue fileLines = new FileIntValue(file, lineCount);

            state.MaxLines.Add(fileLines);
            state.MinLines.Add(fileLines);

            FileIntValue fileChars = new FileIntValue(file, charCount);

            state.MaxChars.Add(fileChars);
            state.MinChars.Add(fileChars);
        }