public void ClearTest() { CCodeUnitsCollection target = CreateObj(); Assert.AreEqual(target.Size(), 3); target.Clear(); Assert.AreEqual(target.Size(), 0); }
public void RemoveRowTest() { CCodeUnitsCollection target = CreateObj(); Assert.AreEqual(target.Size(), 3); target.RemoveRow(1); Assert.AreEqual(target.Size(), 2); }
public void SetSourceRowsTest() { CCodeUnitsCollection target = new CCodeUnitsCollection(); Assert.AreEqual(target.Size(), 0); List <CExtendedCodeUnit> units = new List <CExtendedCodeUnit>(); units.Add(new CExtendedCodeUnit(new CCodeUnit(new CElementPosition(12, 23), ")"), 1, 1)); units.Add(new CExtendedCodeUnit(new CCodeUnit(new CElementPosition(12, 23), ")"), 1, 1)); units.Add(new CExtendedCodeUnit(new CCodeUnit(new CElementPosition(12, 23), ")"), 1, 1)); Assert.AreEqual(units.Count, 3); target.SetCodeUnits(units); Assert.AreEqual(target.Size(), units.Count); }
public void CCodeUnitsCollectionConstructorTest() { CCodeUnitsCollection target = new CCodeUnitsCollection(); Assert.IsNotNull(target); Assert.AreEqual(target.Size(), 0); }
public void AddTest() { CCodeUnitsCollection target = new CCodeUnitsCollection(); CExtendedCodeUnit item = new CExtendedCodeUnit(new CCodeUnit(new CElementPosition(12, 23), ")"), 1, 1); target.Add(item); Assert.AreEqual(target.Size(), 1); Assert.IsTrue(target[0].EqualsObject(item)); }
private void IncreaseCountOfLines(string filename) { // Нам нужно реальное количество строк в файле! CSourceFileID FileID = new CSourceFileID(); CTokenizerParms args = new CTokenizerParms(filename, FileID); ISourceFileContentLoader loader = new CEntireRowSourceFileContentLoader(args); CCodeUnitsCollection collection = loader.Load(); Interlocked.Add(ref m_CountOfLines, collection.Size()); }
public void LoadTest2() { string filename = Path.GetFullPath("UnitTestSampleFile2.cs"); Assert.IsTrue(File.Exists(filename)); CTokenizerParms args = new CTokenizerParms(filename, new CSourceFileID()); CEntireRowSourceFileContentLoader target = new CEntireRowSourceFileContentLoader(args); CCodeUnitsCollection actual = target.Load(); Assert.AreEqual(76, actual.Size()); }
public void LoadTest3() { string filename = Path.GetFullPath("MimeTypeDetection.cs"); Assert.IsTrue(File.Exists(filename)); CTokenizerParms args = new CTokenizerParms(filename, new CSourceFileID()); CTokenSourceFileContentLoader target = new CTokenSourceFileContentLoader(args, CAvailableExtentions.GetExtention(LANGUAGES.LANGUAGE_C_SHARP)); CCodeUnitsCollection actual = target.Load(); Assert.AreEqual(796, actual.Size()); }
public void PreProcessingTest1() { CSimpleCodePreProcessingAlgorithm target = new CSimpleCodePreProcessingAlgorithm(); CCodePreProcessingOptions PreProcessingOptions = new CCodePreProcessingOptions("//;/* */;///"); PreProcessingOptions.SetDeleteWhiteSpaces(false); CCodeUnitsCollection OriginalCodeUnitsCollection = CreateTestCollection1(); Assert.AreEqual(OriginalCodeUnitsCollection.Size(), 21); CCodeUnitsCollection expected = CreateExpectedCollection1(); Assert.AreEqual(expected.Size(), 11); CCodeUnitsCollection actual = target.PreProcessing(PreProcessingOptions, OriginalCodeUnitsCollection); Assert.AreEqual(actual.Size(), expected.Size()); for (int counter = 0; counter < actual.Size(); ++counter) { Assert.AreEqual(actual[counter].Text, expected[counter].Text); } }
private void IncreaseCountOfTokens(string filename) { try { CSourceFileID FileID = new CSourceFileID(); CTokenizerParms args = new CTokenizerParms(filename, FileID); ISourceFileContentLoader loader = new CTokenSourceFileContentLoader(args, m_Extension); CCodeUnitsCollection collection = loader.Load(); Interlocked.Add(ref m_CountOfTokens, collection.Size()); } catch { // Если поддержка токенизации отсутствует, то ничего не делаем } }
/// <summary> /// /// </summary> /// <param name="PreProcessingOptions"></param> /// <param name="OriginalCodeUnitsCollection"></param> /// <returns></returns> public override CCodeUnitsCollection PreProcessing(CCodePreProcessingOptions PreProcessingOptions, CCodeUnitsCollection OriginalCodeUnitsCollection) { ClearMembers(); m_ModifiedCollection.Clear(); string ScanningSymbol = string.Empty; for (int units_counter = 0; units_counter < OriginalCodeUnitsCollection.Size(); ++units_counter) { CExtendedCodeUnit current_unit = OriginalCodeUnitsCollection[units_counter]; CExtendedCodeUnit new_codeunit = new CExtendedCodeUnit(current_unit); #region // Удаление комментариев из кода if (PreProcessingOptions.DeleteComments) { m_OnelineCodeFragments.Clear(); ClearProcessingCommentSymbol(); // Суть алгоритма в следующем: перебираем все строки; в каждой строке перебираем все символы. // Если текущий символ является одним из возможных символов комментариев, то добавляем его в строку. // Если длина этой строки лежит в пределах от минимальной до максимальной из возможных длин комментариев, то проверяем является ли эта строка комментарием. for (int char_counter = 0; char_counter < current_unit.Text.Length; char_counter++) { char current_char = current_unit.Text[char_counter]; if (PreProcessingOptions.CommentSymbols.IsCommentChar(current_char)) { m_ProcessingCommentSymbol += current_char; m_IndexOfCommentSymbolBeginning = (m_IndexOfCommentSymbolBeginning == CElementPosition.INDEX_NUMBER_LOW_BOUND - 1) ? char_counter : m_IndexOfCommentSymbolBeginning; if (m_ProcessingCommentSymbol.Length >= PreProcessingOptions.CommentSymbols.MinCommentLength) { if (m_ProcessingCommentSymbol.Length <= PreProcessingOptions.CommentSymbols.MaxCommentLength) { if (!String.IsNullOrEmpty(ScanningSymbol)) { if (m_ProcessingCommentSymbol == ScanningSymbol) { AddFragment(GetRealLineNumber(units_counter), char_counter); ScanningSymbol = string.Empty; ClearProcessingCommentSymbol(); } else { if (m_ProcessingCommentSymbol.Length >= ScanningSymbol.Length) { ClearProcessingCommentSymbol(); } } } else { // Попробуем поискать такой символ комментария, при этом нужно узнать парный ли он. bool IsNotPair = false; if (PreProcessingOptions.CommentSymbols.IsCommentSymbol(m_ProcessingCommentSymbol, ref IsNotPair)) { if (IsNotPair) { // Если комментарий непарный, то нужно удалить всё до конца строки CCommentedCodeFragment new_fragment = new CCommentedCodeFragment(new CElementPosition(GetRealLineNumber(units_counter), m_IndexOfCommentSymbolBeginning, GetRealLineNumber(units_counter), current_unit.Text.Length - 1), new CPair <string>(m_ProcessingCommentSymbol, string.Empty)); m_OnelineCodeFragments.Add(new_fragment); break; } else { if (PreProcessingOptions.PairCommentDictionary.ContainsKey(m_ProcessingCommentSymbol)) { m_PairCommentStack.Push(new CCommentedCodeFragment(new CElementPosition(GetRealLineNumber(units_counter), m_IndexOfCommentSymbolBeginning), new CPair <string>(m_ProcessingCommentSymbol, PreProcessingOptions.PairCommentDictionary[m_ProcessingCommentSymbol]))); ClearProcessingCommentSymbol(); } else { AddFragment(GetRealLineNumber(units_counter), char_counter); ClearProcessingCommentSymbol(); } } } } } else { ClearProcessingCommentSymbol(); } } } else { ClearProcessingCommentSymbol(); } } if (m_OnelineCodeFragments.Count > 0) { new_codeunit.Text = string.Empty; int starting_index = 0; foreach (CCommentedCodeFragment fragment in m_OnelineCodeFragments) { //try //{ new_codeunit.Text = new_codeunit.Text + current_unit.Text.Substring(starting_index, fragment.IndexStart - starting_index); //} //catch (ArgumentOutOfRangeException) //{ // throw; //} starting_index = fragment.IndexEnd + 1; } if (starting_index < current_unit.Text.Length) { //try //{ new_codeunit.Text = new_codeunit.Text + current_unit.Text.Substring(starting_index); //} //catch (ArgumentOutOfRangeException) //{ // throw; //} } } if (m_PairCommentStack.Count > 0) { CCommentedCodeFragment open_fragment = m_PairCommentStack.Peek(); ScanningSymbol = open_fragment.CommentSymbolPair.Second; if (open_fragment.IsBelongOneLine(GetRealLineNumber(units_counter))) { int index = new_codeunit.Text.IndexOf(open_fragment.CommentSymbolPair.First); new_codeunit.Text = new_codeunit.Text.Substring(0, index); } else { new_codeunit.Text = string.Empty; } } } #endregion if (PreProcessingOptions.DeleteWhiteSpaces) { new_codeunit.Text = CStringConverter.RemoveMultipleWhiteSpaces(new_codeunit.Text.Trim()); } if (!PreProcessingOptions.DeleteEmptyLines || !String.IsNullOrEmpty(new_codeunit.Text)) { m_ModifiedCollection.Add(new_codeunit); } } return(m_ModifiedCollection); }
/// <summary> /// Размер фрагмента (в единицах кода) /// </summary> /// <returns></returns> public long Size() { return(m_Content.Size()); }