Esempio n. 1
0
        private static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                return;
            }

            if (!IOHelper.IsThisADirectory(args[0]))
            {
                return;
            }

            string directory = args[0];

            RulesReader.FromFile("codeDefinition.json");
            ExcludeWordsConfig excludeWordsConfig = ExcludeWordsConfig.FromJsonFile("excludeWords.json");

            LinesOfCode.LineProcessComplete += LinesOfCode_LineProcessComplete;
            FilesOfCode.FileFound           += (f) => LinesOfCode.CountLinesOfCodeInFile(f);
            FilesOfCode.Find(directory);

            foreach (KeyValuePair <string, int> k in _occurrances
                     .Where(kvp => kvp.Value > THRESHOLD)
                     .Where(kvp => !excludeWordsConfig.ExcludeWords.Contains(kvp.Key))
                     .OrderByDescending(kvp => { return(kvp.Value); }))
            {
                Console.WriteLine(k.Value + ":\t" + k.Key);
            }
#if DEBUG
            Console.ReadLine();
#endif
        }
Esempio n. 2
0
        public void ExcludeLinesWithComments()
        {
            RulesReader.FromFile("codeDefinition.json");

            Assert.IsFalse(LinesOfCode.DoCount("//"));
            Assert.IsFalse(LinesOfCode.DoCount("   //"));
            Assert.IsFalse(LinesOfCode.DoCount("///"));
        }
Esempio n. 3
0
        public void ExcludeLinesThatOnlyContainBrackets()
        {
            RulesReader.FromFile("codeDefinition.json");

            Assert.IsFalse(LinesOfCode.DoCount("	}"));
            Assert.IsFalse(LinesOfCode.DoCount("{"));
            Assert.IsFalse(LinesOfCode.DoCount("{}"));

            Assert.IsTrue(LinesOfCode.DoCount("{ i=0;"));
        }
Esempio n. 4
0
        public void When_Json_File_Is_Empty_Then_Rules_Are_Empty()
        {
            RulesReader.FromFile("empty.json");

            Assert.AreEqual(0, Rules.FilesMustMatch.Count);
            Assert.AreEqual(0, Rules.CodeLineMustContain.Count);
            Assert.AreEqual(0, Rules.IgnoreFilesThatMatch.Count);
            Assert.AreEqual(0, Rules.IgnoreFoldersThatMatch.Count);
            Assert.AreEqual(0, Rules.IgnoreIfLineContainsOnly.Count);
            Assert.AreEqual(0, Rules.IgnoreLinesThatStartWith.Count);
            Assert.AreEqual(0, Rules.IgnoreLinesThatContains.Count);
        }
Esempio n. 5
0
        public void ReadConfigWithRulesReader()
        {
            RulesReader.FromFile("codeDefinition.json");

            Assert.AreEqual(1, Rules.FilesMustMatch.Count);
            Assert.AreEqual(0, Rules.CodeLineMustContain.Count);
            Assert.AreEqual(3, Rules.IgnoreFilesThatMatch.Count);
            Assert.AreEqual(3, Rules.IgnoreFoldersThatMatch.Count);
            Assert.AreEqual(8, Rules.IgnoreIfLineContainsOnly.Count);
            Assert.AreEqual(6, Rules.IgnoreLinesThatStartWith.Count);
            Assert.AreEqual(2, Rules.IgnoreLinesThatContains.Count);
        }
Esempio n. 6
0
 public void When_Json_File_Does_Not_Exist_Then_Exception_Is_Thrown()
 {
     RulesReader.FromFile("doesNotExist.json");
 }
Esempio n. 7
0
 public void CountOneLine()
 {
     RulesReader.FromFile("codeDefinition.json");
     Assert.IsTrue(LinesOfCode.DoCount("i=0;\n"));
 }
Esempio n. 8
0
        private static int Main(string[] args)
        {
            // Show change since last run (which files have a difference in loc?)

            // Break out ConsoleApplicationLogic and test it.
            // Solve the output-problem/Break out printing from Program
            // Refactor how parameters effect the output. Break out most of the logic.

            // Break out arguments analysis from Program.
            string path;

            if (args.Length > 0)
            {
                path = args[0];
            }
            else
            {
                PrintUsage();
                return(0);
            }

            RulesReader.FromFile("codeDefinition.json");

            if (args.Length > 1)
            {
                string lastArgument = args[args.Length - 1];
                _verboseOutput = lastArgument == "-v";
                _minimalOutput = lastArgument == "-m";
                _orderedOutput = lastArgument == "-o";
            }

            if (_verboseOutput)
            {
                LinesOfCode.LineProcessComplete += LineProcessComplete;
            }

            if (IOHelper.IsThisAFile(path))
            {
                int loc = ProcessFile(path);
                if (_minimalOutput)
                {
                    Console.WriteLine(loc);
                }
                return(0);
            }

            if (IOHelper.IsThisADirectory(path))
            {
                // TODO: Refactor!
                Dictionary <string, int> files = new Dictionary <string, int>();

                if (!_minimalOutput)
                {
                    Console.WriteLine();
                }

                if (_orderedOutput)
                {
                    FilesOfCode.FileFound += f => files.Add(f, CountFile(f));
                }
                else
                {
                    FilesOfCode.FileFound += f => ProcessFile(f);
                }

                FilesOfCode.Find(path);

                if (_orderedOutput)
                {
                    var orderedFiles = files.OrderByDescending(kvp => { return(kvp.Value); });
                    foreach (KeyValuePair <string, int> k in orderedFiles)
                    {
                        FileProcessComplete(k.Key, k.Value);
                    }

                    Console.Write("\nTotal lines of code: ");
                }
                else if (!_minimalOutput)
                {
                    foreach (KeyValuePair <string, int> k in files)
                    {
                        FileProcessComplete(k.Key, k.Value);
                    }

                    Console.Write("\nTotal lines of code: ");
                }
                Console.WriteLine(_totalLinesOfCode);

#if DEBUG
                Console.ReadLine();
#endif
                return(0);
            }

            PrintUsage();
            return(1);
        }