public CodeError(ErrorType Type, ErrorLevel Level, CodeLine Line, string Remarks = "") { this.Type = Type; this.Level = Level; this.Line = Line; this.Remarks = Remarks; }
public void Setup(CodeLine line, int number) { _codeLine = line; if (line == null) { gameObject.SetActive(false); return; } gameObject.SetActive(true); _number = number; LineNumber.text = number.ToString("D2"); var cmds = new List<Dropdown.OptionData>(); foreach (CodeLine.Instruction cmd in System.Enum.GetValues(typeof(CodeLine.Instruction))) { cmds.Add(new Dropdown.OptionData(CodeLine.PrettyName(cmd))); } Command.options = cmds; Command.value = (int)line.Cmd; SetupParam(0); SetupParam(1); }
public static void CreateCodeLineViaCodeAndIndentionAndLabels() { var line = new CodeLine("code", Indention.Increase, new Label()); Assert.Equal("code", line.Code); Assert.Equal(Indention.Increase, line.Indent); Assert.False(line.IsDebuggable); Assert.Equal(1, line.Labels.Length); }
public static void CreateCodeLineViaCodeAndIsDebuggable() { var line = new CodeLine("code", true); Assert.Equal("code", line.Code); Assert.Equal(Indention.KeepCurrent, line.Indent); Assert.True(line.IsDebuggable); Assert.Equal(0, line.Labels.Length); }
public static void CodeTransmit_Action_ImportDB(Case.BasicTestCase refTestCase, CodeLine activeSelectLine) { if (refTestCase != null && activeSelectLine.KeyCode == Container.KeyWordMap.ImportDB) { if (activeSelectLine.ParamsPool.ContainsKey("name") && activeSelectLine.ParamsPool.ContainsKey("server") && activeSelectLine.ParamsPool.ContainsKey("table") && activeSelectLine.ParamsPool.ContainsKey("db") && activeSelectLine.ParamsPool.ContainsKey("uid") && activeSelectLine.ParamsPool.ContainsKey("pwd")) { try { string sourceName = activeSelectLine.ParamsPool["name"]; string server = activeSelectLine.ParamsPool["server"]; string db = activeSelectLine.ParamsPool["db"]; string uid = activeSelectLine.ParamsPool["uid"]; string pwd = activeSelectLine.ParamsPool["pwd"]; string table = activeSelectLine.ParamsPool["table"]; Buffalo.Basic.Data.Data_SqlConnectionHelper _ConnectionObj = new Basic.Data.Data_SqlConnectionHelper(); _ConnectionObj.Set_NewConnectionItem(sourceName, server, uid, pwd, db); Buffalo.Basic.Data.Data_SqlDataHelper _SqlDataHelper = new Basic.Data.Data_SqlDataHelper(); _SqlDataHelper.ActiveConnection = _ConnectionObj.Get_ActiveConnection(sourceName); DataTable activeDataTable = new DataTable(); _SqlDataHelper.Action_ExecuteForDT("select * from " + table, out activeDataTable); XmlDocument sourceDataDoc = new XmlDocument(); sourceDataDoc.LoadXml("<root></root>"); List<string> columnNameList = new List<string>(); foreach (DataColumn dc in activeDataTable.Columns) { columnNameList.Add(dc.ColumnName); } int rowIndex = 1; foreach (DataRow dr in activeDataTable.Rows) { XmlNode newRowItem = Buffalo.Basic.Data.XmlHelper.CreateNode(sourceDataDoc, "row", ""); Buffalo.Basic.Data.XmlHelper.SetAttribute(newRowItem, "index", rowIndex.ToString()); foreach (string columnName in columnNameList) { string result = ""; _SqlDataHelper.Static_GetColumnData(dr, columnName, out result); Buffalo.Basic.Data.XmlHelper.SetAttribute(newRowItem, "column_" + columnName, result); } sourceDataDoc.SelectSingleNode("/root").AppendChild(newRowItem); } } catch (Exception err) { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Import DB : " + err.Message, true); } } else { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Import DB : invalidate word.", true); } } }
public static void CodeTransmit_Action_Case(Case.BasicTestCase refTestCase, CodeLine activeSelectLine) { if (activeSelectLine.KeyCode == Container.KeyWordMap.Case) { foreach (string paramName in activeSelectLine.ParamsPool.Keys) { switch (paramName) { case "casename": refTestCase.CaseName = activeSelectLine.ParamsPool[paramName]; break; } } } }
public static void CodeTransmit_Action_ImportXML(Case.BasicTestCase refTestCase, CodeLine activeSelectLine) { if (refTestCase != null && activeSelectLine.KeyCode == Container.KeyWordMap.ImportDB) { if (activeSelectLine.ParamsPool.ContainsKey("name") && activeSelectLine.ParamsPool.ContainsKey("source")) { string sourceFile = activeSelectLine.ParamsPool["source"]; XmlDocument tmpDoc = new XmlDocument(); XmlDocument sourceDataDoc = new XmlDocument(); sourceDataDoc.LoadXml("<root></root>"); try { tmpDoc.Load(sourceFile); XmlNodeList rowNodes = tmpDoc.SelectNodes("/root/row"); int rowIndex = 1; foreach (XmlNode rowNode in rowNodes) { XmlNode newRowNode = Buffalo.Basic.Data.XmlHelper.CreateNode(sourceDataDoc, "row", ""); Buffalo.Basic.Data.XmlHelper.SetAttribute(newRowNode, "index", rowIndex.ToString()); foreach (XmlAttribute activeAttr in rowNode.Attributes) { string value = Buffalo.Basic.Data.XmlHelper.GetNodeValue("@" + activeAttr.Name, rowNode); Buffalo.Basic.Data.XmlHelper.SetAttribute(newRowNode, "column_" + activeAttr.Name, value); } sourceDataDoc.SelectSingleNode("/root").AppendChild(newRowNode); rowIndex++; } } catch (Exception err) { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Import XML : " + err.Message, true); } } else { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Import XML : invalidate word namd or source.", true); } } }
public void ContainsSpacesInsideCode() { var result = new CodeLine($" {AnyString} {AnyString} 7;", TabCount); result.SpaceCount.ShouldEqual(1); }
public void StartsWithOneTab_ReturnsCorrectNumberOfSpaces() { var result = new CodeLine($"{TabString}{AnyString}", TabCount); result.SpaceCount.ShouldEqual(TabCount); }
public void StartsWithFullTab_Counted() { var result = new CodeLine($"{TabString}{AnyString}", TabCount); result.TabCount.ShouldEqual(1); }
private static void Main(string[] args) { Int64 lines_covered = 0; Int64 lines_partially_covered = 0; Int64 lines_not_covered = 0; string breakdown_percent_not_covered = ""; string breakdown_lines_not_covered = ""; string unit_names = ""; FileInfo coverage_file = new FileInfo(args[0]); using (CoverageInfo info = CoverageInfo.CreateFromFile(coverage_file.FullName)) { var lines = new List <BlockLineRange>(); foreach (ICoverageModule module in info.Modules) { Console.WriteLine("Analysing " + module.Name); Regex module_regex = new Regex(@"^(.+?)(_tests?)+.exe"); Match module_match = module_regex.Match(module.Name); string tested_unit = module_match.Groups[1].ToString(); Regex regex; if (tested_unit == "ksp_plugin") { Console.WriteLine("Covering principia::" + tested_unit + " as well as extern \"C\" interface functions" + " (of the form ::principia__Identifier)"); regex = new Regex("^principia(::" + tested_unit + "|__)"); } else { Console.WriteLine("Covering principia::" + tested_unit); regex = new Regex("^principia::" + tested_unit); } Regex ignored_files_regex = new Regex( @"((_test\.cpp|" + @"\.generated\.cc|" + @"\.generated\.h|" + @"\.pb\.h|" + @"\.pb\.cc)$|" + @"\\mock_)"); var covered = new Dictionary <CodeLine, Dictionary <uint, bool> >(); byte[] coverage_buffer = module.GetCoverageBuffer(null); using (ISymbolReader reader = module.Symbols.CreateReader()) { for (;;) { string method_name; try { if (!reader.GetNextMethod(out uint method_id, out method_name, out string undecorated_method_name, out string class_name, out string namespace_name, lines)) { break; } } catch (AccessViolationException e) { Console.WriteLine(e.ToString()); continue; } if (regex.Match(method_name).Success) { foreach (var line in lines) { if (!ignored_files_regex.Match(line.SourceFile).Success) { CoverageStatistics stats = CoverageInfo.GetMethodStatistics( coverage_buffer, new List <BlockLineRange> { line }); if (line.StartLine != line.EndLine || stats.LinesCovered + stats.LinesNotCovered != 1) { Console.WriteLine("in " + method_name); Console.WriteLine(line.SourceFile + ":" + line.StartLine + "-" + line.EndLine); Console.WriteLine(stats.LinesCovered + "," + stats.LinesNotCovered); Environment.Exit(1); } bool block_is_covered = stats.LinesCovered == 1; var code_line = new CodeLine { file = line.SourceFile, line_number = line.StartLine }; if (!covered.ContainsKey(code_line)) { covered.Add(code_line, new Dictionary <uint, bool>()); } if (covered[code_line].ContainsKey(line.BlockIndex)) { covered[code_line][line.BlockIndex] |= block_is_covered; } else { covered[code_line].Add(line.BlockIndex, block_is_covered); } } } } lines.Clear(); } } Int64 subtotal_lines = covered.Count; Int64 subtotal_not_covered = 0; foreach (var pair in covered) { bool line_is_partially_covered = (from block_coverage in pair.Value select block_coverage.Value) .Any(_ => _); bool line_is_fully_covered = (from block_coverage in pair.Value select block_coverage.Value) .All(_ => _); if (line_is_fully_covered) { ++lines_covered; } else if (line_is_partially_covered) { ++lines_partially_covered; } else { ++subtotal_not_covered; ++lines_not_covered; Console.WriteLine(pair.Key.file + ":" + pair.Key.line_number); } } CommaSeparatedAppend(ref breakdown_lines_not_covered, subtotal_not_covered.ToString()); CommaSeparatedAppend( ref breakdown_percent_not_covered, (((double)subtotal_not_covered / (double)subtotal_lines) * 100.0) .ToString()); CommaSeparatedAppend(ref unit_names, tested_unit); } } Int64 total = lines_partially_covered + lines_covered + lines_not_covered; Console.WriteLine("Covered : " + ValueAndPercentage(lines_partially_covered + lines_covered, total)); Console.WriteLine(" Partially : " + ValueAndPercentage(lines_partially_covered, total)); Console.WriteLine(" Completely : " + ValueAndPercentage(lines_covered, total)); Console.WriteLine("Not Covered : " + ValueAndPercentage(lines_not_covered, total)); File.WriteAllText( Path.Combine(coverage_file.Directory.FullName, "jenkins_percent_coverage.csv"), "not covered,partially covered,fully covered\n" + ((double)lines_not_covered / (double)total) * 100.0 + "," + ((double)lines_partially_covered / (double)total) * 100.0 + "," + ((double)lines_covered / (double)total) * 100.0); File.WriteAllText(Path.Combine(coverage_file.Directory.FullName, "jenkins_lines_coverage.csv"), "not covered,partially covered,fully covered\n" + lines_not_covered + "," + lines_partially_covered + "," + lines_covered); File.WriteAllText(Path.Combine(coverage_file.Directory.FullName, "jenkins_lines_coverage_breakdown.csv"), unit_names + "\n" + breakdown_lines_not_covered); File.WriteAllText(Path.Combine(coverage_file.Directory.FullName, "jenkins_percent_coverage_breakdown.csv"), unit_names + "\n" + breakdown_percent_not_covered); }
public static void CodeTransmit_Action_ImportExcel(Case.BasicTestCase refTestCase, CodeLine activeSelectLine) { if (refTestCase != null && activeSelectLine.KeyCode == Container.KeyWordMap.ImportExcel) { if (activeSelectLine.ParamsPool.ContainsKey("name") && activeSelectLine.ParamsPool.ContainsKey("excel") && activeSelectLine.ParamsPool.ContainsKey("sheet") && activeSelectLine.ParamsPool.ContainsKey("rows") && activeSelectLine.ParamsPool.ContainsKey("columns")) { try { string sourceName = activeSelectLine.ParamsPool["name"]; Buffalo.Basic.Data.ExcelConnectionHelper _ConnectionObj = new Basic.Data.ExcelConnectionHelper(); string guid = Guid.NewGuid().ToString(); _ConnectionObj.AddNewExcelConnection(guid, activeSelectLine.ParamsPool["excel"], Basic.Data.ExcelConnectionType.NPOI, false); Buffalo.Basic.Data.ExcelConnection_NPIO activeExcelConnection = (Buffalo.Basic.Data.ExcelConnection_NPIO)_ConnectionObj.GetConnection(guid); string str_maxRow = activeSelectLine.ParamsPool["rows"]; string str_maxColumn = activeSelectLine.ParamsPool["columns"]; int i_maxRow = 0; int i_maxColumn = 0; Int32.TryParse(str_maxRow, out i_maxRow); Int32.TryParse(str_maxColumn, out i_maxColumn); XmlDocument sourceDataDoc = new XmlDocument(); sourceDataDoc.LoadXml("<root></root>"); for (int i = 1; i <= i_maxRow; i++) { XmlNode rowNode = Buffalo.Basic.Data.XmlHelper.CreateNode(sourceDataDoc, "row", ""); Buffalo.Basic.Data.XmlHelper.SetAttribute(rowNode, "index", i.ToString()); for (int y = 1; y <= i_maxColumn; y++) { string value = activeExcelConnection.GetCellValue(activeSelectLine.ParamsPool["sheet"], i, y); Buffalo.Basic.Data.XmlHelper.SetAttribute(rowNode, "column_" + y, value); } sourceDataDoc.SelectSingleNode("/root").AppendChild(rowNode); } if (!refTestCase.ActiveCaseDataSourcePool.ContainsKey(sourceName)) { refTestCase.ActiveCaseDataSourcePool.Add(sourceName, sourceDataDoc); } else { refTestCase.ActiveCaseDataSourcePool[sourceName] = sourceDataDoc; } } catch (Exception err) { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Import Excel : " + err.Message, true); } } } }
/// <summary> /// Strips the text of all strings and a potential end of line comment. /// </summary> private static string RemoveStringsAndComment(CodeLine line) { return(RemoveStrings(line.WithoutEnding + line.LineEnding, line.StringDelimiters)); }
public EndConditionLine(CodeLine codeLine) : base(codeLine.Code, codeLine, codeLine.Strings) { base.Comment = codeLine.Comment; base.Raw = codeLine.Raw; }
public static PreprocessorResult Preprocess(string Filename) { var codeLines = new List<CodeLine>(); var defines = new Dictionary<string, string>(); var errors = new List<CodeError>(); string mainContents = File.ReadAllText(Filename); mainContents = mainContents.Replace("\r\n", "\n"); mainContents = mainContents.Replace("\\\n", ""); string[] lines = mainContents.Split('\n'); //var replacementRegexPairs = new Dictionary<Regex, string>(); //foreach (KeyValuePair<string, string> kv in defines) // uint lineCount = 1; // Remove all whitespace and all comments foreach (string line in lines) { string processedLine = commentRegex.Replace(line, "").Trim(); // foreach (KeyValuePair<Regex, string> replacementPair in replacementRegexPairs) // processedLine = replacementPair.Key.Replace(line, replacementPair.Value).Trim(); if (processedLine != "") { if (dataRegex.IsMatch(processedLine)) { codeLines.Add(new CodeLine(processedLine, lineCount, Filename){ Type = CodeLine.LineType.Data }); } else if (instructionRegex.IsMatch(processedLine)) { codeLines.Add(new CodeLine(processedLine, lineCount, Filename){ Type = CodeLine.LineType.Instruction }); } else if (labelRegex.IsMatch(processedLine)) { codeLines.Add(new CodeLine(processedLine, lineCount, Filename){ Type = CodeLine.LineType.Label }); } else if (defineRegex.IsMatch(line) && false) { CodeLine thisLine = new CodeLine(processedLine, lineCount, Filename) { Type = CodeLine.LineType.Preprocessor, Processed = true }; Match match = defineRegex.Match(line); string search = match.Groups[1].Value; string replace = match.Groups[2].Value; replace = (replace != "") ? replace : "1"; if (defines.ContainsKey(search)) defines[search] = replace; else defines.Add(search, replace); codeLines.Add(thisLine); } else if (undefineRegex.IsMatch(line) && false) { CodeLine thisLine = new CodeLine(processedLine, lineCount, Filename) { Type = CodeLine.LineType.Preprocessor, Processed = true }; Match match = defineRegex.Match(line); string search = match.Groups[1].Value.Trim(); if (defines.ContainsKey(search)) defines.Remove(search); else errors.Add(new CodeError(CodeError.ErrorType.DefineNotExistant, ErrorLevel.Warning, thisLine)); codeLines.Add(thisLine); } else if (includeRegex.IsMatch(line)) { CodeLine thisLine = new CodeLine(processedLine, lineCount, Filename) { Type = CodeLine.LineType.Preprocessor, Processed = true }; codeLines.Add(thisLine); Match match = includeRegex.Match(line); string filename = match.Groups[1].Value; if (!File.Exists(filename)) errors.Add(new CodeError(CodeError.ErrorType.IncludeNotFound, ErrorLevel.Error, thisLine)); else { PreprocessorResult includeResult = Preprocess(filename); codeLines.AddRange(includeResult.CodeLines); errors.AddRange(includeResult.Errors); } } else codeLines.Add(new CodeLine(processedLine, lineCount, Filename){ Type = CodeLine.LineType.Unknown }); } else { codeLines.Add(new CodeLine(line, lineCount, Filename) { Type = CodeLine.LineType.Empty, Processed = true }); } lineCount++; } foreach (CodeLine line in codeLines) { if (line.Type == CodeLine.LineType.Unknown) { errors.Add(new CodeError(CodeError.ErrorType.SyntaxError, ErrorLevel.Error, line)); line.Processed = true; } } return new PreprocessorResult(codeLines.ToArray(), errors.ToArray()); }
/// <summary> /// Parse the preprocessed source code lines. /// </summary> /// <param name="CodeLines">Source code lines</param> public static ParserResult Parse(CodeLine[] CodeLines) { var tokens = new List<ClawToken>(); var errors = new List<CodeError>(); // Process all elements foreach (CodeLine line in CodeLines) { if (!line.Processed && line.Type != CodeLine.LineType.Unknown) { if (line.Type == CodeLine.LineType.Data) { Match match = dataRegex.Match(line.Content); string type = match.Groups[1].Value.ToUpper(); string data = match.Groups[2].Value; string strval = match.Groups[3].Value; var values = new List<string>(); // check if its not a string if (data != "") { // Trim all values and add all not empty ones to a list foreach (string value in data.Split(',')) { string trimmedValue = value.Trim(); if (trimmedValue != "") values.Add(trimmedValue); } } if (type == "8") { foreach (string value in values) tokens.Add(new DataToken(Convert.ToSByte(value))); } else if (type == "8U") { foreach (string value in values) tokens.Add(new DataToken(Convert.ToByte(value))); } else if (type == "16") { foreach (string value in values) tokens.Add(new DataToken(Convert.ToInt16(value))); } else if (type == "16U") { foreach (string value in values) tokens.Add(new DataToken(Convert.ToUInt16(value))); } else if (type == "32") { foreach (string value in values) tokens.Add(new DataToken(Convert.ToInt32(value))); } else if (type == "32U") { foreach (string value in values) tokens.Add(new DataToken(Convert.ToUInt32(value))); } else if (type == "F") { foreach (string value in values) tokens.Add(new DataToken(Convert.ToSingle(value))); } else if (type == "S") { strval = strval.Replace("\\\\", "\\").Replace("\\n", "\n"); tokens.Add(new DataToken(strval)); } else { errors.Add(new CodeError(CodeError.ErrorType.UnknownDatatype, ErrorLevel.Error, line)); } line.Processed = true; } else if (line.Type == CodeLine.LineType.Instruction) { Match match = instructionRegex.Match(line.Content); string mnemoric = match.Groups[1].Value.ToUpper(); string instack = match.Groups[2].Value.ToUpper(); string outstack = match.Groups[3].Value.ToUpper(); ClawInstruction instruction; ClawStack input_stack; ClawStack output_stack; if (Enum.TryParse<ClawInstruction>(mnemoric, true, out instruction)) { input_stack = Enum.TryParse<ClawStack>(instack, true, out input_stack) ? input_stack : ClawStack.A; output_stack = Enum.TryParse<ClawStack>(outstack, true, out output_stack) ? output_stack : input_stack; tokens.Add(new InstructionToken(instruction, input_stack, output_stack)); } else errors.Add(new CodeError(CodeError.ErrorType.UnknownInstruction, ErrorLevel.Error, line)); line.Processed = true; } else if (line.Type == CodeLine.LineType.Label) { Match match = labelRegex.Match(line.Content); line.Processed = true; } } } foreach (CodeLine line in CodeLines) if (line.Processed == false) errors.Add(new CodeError(CodeError.ErrorType.SyntaxError, ErrorLevel.Warning, line)); return new ParserResult(tokens.ToArray(), CodeLines, errors.ToArray()); }
public static void CodeTransmit_Action_Connect(Case.BasicTestCase refTestCase, WebDriver.WebBrowserDriver refWebBrowserDriver, CodeLine activeSelectLine) { if (activeSelectLine.KeyCode == Container.KeyWordMap.Connect) { try { foreach (string paramName in activeSelectLine.ParamsPool.Keys) { if (paramName == "type") { switch (activeSelectLine.ParamsPool[paramName]) { case "Chrome": case "chrome": case "CHROME": default: refWebBrowserDriver = WebDriver.WebBrowserDriver.CreateInstanceForWebDriver(WebDriver.WebBrowserType.Chrome); break; case "IE": case "ie": refWebBrowserDriver = WebDriver.WebBrowserDriver.CreateInstanceForWebDriver(WebDriver.WebBrowserType.InternetExplorer); break; case "firefox": case "Firefox": refWebBrowserDriver = WebDriver.WebBrowserDriver.CreateInstanceForWebDriver(WebDriver.WebBrowserType.FireFox); break; } } } refTestCase.ActionWebBrowserActionsObject = new WebDriver.WebBrowserActions(refWebBrowserDriver.ActiveWebDriver); refTestCase.ActiveWebBrowserDriverObject = refWebBrowserDriver; refTestCase.ActiveElementSelectorObject = new ElementActions.ElementSelector(refWebBrowserDriver.ActiveWebDriver); } catch (Exception err) { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Connect : " + err.Message, true); } } }
public static void CodeTransmit_Action_AnalyseContent(Case.CaseMethodItem refCaseMethodItemObj, Case.BasicTestCase refActiveCase, CodeLine activeSelectLine) {
public static void CodeTransmit_Action_ElementAction(Case.CaseMethodItem refCaseMethodItemObj, Case.BasicTestCase refActiveCase, CodeLine activeSelectLine) { if (refCaseMethodItemObj != null && activeSelectLine.KeyCode == Container.KeyWordMap.Action) { try { refCaseMethodItemObj.Index = activeSelectLine.CodeIndex; refCaseMethodItemObj.ActiveMethod = new ElementActions.MethodItem(); refCaseMethodItemObj.ActiveMethod.ActiveType = typeof(ElementActions.ElementActions); refActiveCase.ActiveCaseMethodPool.Add(refCaseMethodItemObj.Index, refCaseMethodItemObj); object[] methodParam; foreach (string paramName in activeSelectLine.ParamsPool.Keys) { switch (paramName) { case ElementActions.ActionMap.Method_Action_Click: refCaseMethodItemObj.ActiveMethod.ActiveMethod = refCaseMethodItemObj.ActiveMethod.ActiveType.GetMethod(ElementActions.ActionMap.Method_Action_Click); if (activeSelectLine.ParamsPool[paramName] != Container.KeyWordMap.Null) { int delayTime = 0; int.TryParse(activeSelectLine.ParamsPool[paramName], out delayTime); methodParam = new object[] { delayTime }; refCaseMethodItemObj.ActiveMethod.MethodParams = methodParam; } break; case ElementActions.ActionMap.Method_Action_SetText: refCaseMethodItemObj.ActiveMethod.ActiveMethod = refCaseMethodItemObj.ActiveMethod.ActiveType.GetMethod(ElementActions.ActionMap.Method_Action_SetText); string textParam = ""; textParam = activeSelectLine.ParamsPool[paramName]; methodParam = new object[] { textParam }; refCaseMethodItemObj.ActiveMethod.MethodParams = methodParam; break; <<<<<<< HEAD case ElementActions.ActionMap.Method_Get_Content: string datanameParam = ""; datanameParam = activeSelectLine.ParamsPool[paramName]; if (datanameParam != Container.KeyWordMap.Null) { string contentFromElement = refActiveCase.ActiveElementActionObject.Get_Content(); if (refActiveCase.ActiveDataBuffer.ContainsKey(datanameParam)) refActiveCase.ActiveDataBuffer[datanameParam] = contentFromElement; else refActiveCase.ActiveDataBuffer.Add(datanameParam, contentFromElement); ======= case ElementActions.ActionMap.Method_Get_Content: refCaseMethodItemObj.ActiveMethod.ActiveMethod = refCaseMethodItemObj.ActiveMethod.ActiveType.GetMethod(ElementActions.ActionMap.Method_Get_Content_Store); if (activeSelectLine.ParamsPool[paramName] != Container.KeyWordMap.Null) { string datanameParam = ""; datanameParam = activeSelectLine.ParamsPool[paramName]; methodParam = new object[] { refActiveCase, datanameParam }; refCaseMethodItemObj.ActiveMethod.MethodParams = methodParam; >>>>>>> origin/master } break; } } } catch (Exception err) { refActiveCase.SingleInterrupt = true; refActiveCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Action : " + err.Message, true); } } }
public RotateRegisterRightLine(CodeLine codeLine) : base(codeLine.Code, codeLine, codeLine.Strings) { base.Comment = codeLine.Comment; base.Raw = codeLine.Raw; }
/// <summary> /// Returns the indentation at the end of the line. /// Note: the indentation saved in CodeLine is the indentation that a variable declared on that line would have. /// </summary> private static int FinalIndentation(this CodeLine line) { var code = RelevantCode(line); return(line.Indentation + NrIndents(code) - NrUnindents(code)); }
public EndRepeatLine(CodeLine codeLine) : base(codeLine.Code, codeLine, codeLine.Strings) { base.Comment = codeLine.Comment; base.Raw = codeLine.Raw; }
public static void CreateCodeLineViaCodeAndSetCodeNull() { var line = new CodeLine("code"); Assert.Throws<ArgumentNullException>(() => line.Code = null); }
public PreprocessorResult(CodeLine[] CodeLines, CodeError[] Errors) { this.CodeLines = CodeLines; this.Errors = Errors; }
public static void CodeTransmit_Action_DataSet(Case.BasicTestCase refTestCase, CodeLine activeSelectLine) { if (refTestCase != null && activeSelectLine.KeyCode == Container.KeyWordMap.DataSet) { if (!activeSelectLine.ParamsPool.ContainsKey("dataname")) { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Data Set : missing dataname.", true); return; } else { if (!activeSelectLine.ParamsPool.ContainsKey("value")) { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Data Set : missing data value.", true); return; } else { string dataName = activeSelectLine.ParamsPool["dataname"]; string dataValue = activeSelectLine.ParamsPool["value"]; if (refTestCase.ActiveDataBuffer.ContainsKey(dataName)) refTestCase.ActiveDataBuffer[dataName] = dataValue; else refTestCase.ActiveDataBuffer.Add(dataName, dataValue); } } } }
/// <summary> /// Computes the updated code line based on the given previous line preceding it, /// and compares its indentation with the current line at <paramref name="continueAt"/> in the given file. /// Returns the difference of the new indentation and the current one. /// </summary> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="continueAt"/> is less than zero or more than the number of lines in <paramref name="file"/>. /// </exception> internal static int GetIndentationChange(FileContentManager file, int continueAt, CodeLine previous) // previous: last element before the one at continueAt { if (continueAt < 0 || continueAt > file.NrLines()) { throw new ArgumentOutOfRangeException(nameof(continueAt)); } if (continueAt == file.NrLines()) { return(0); } var continuation = file.GetLine(continueAt); var updatedContinuation = ComputeCodeLines(new string[] { continuation.Text }, previous).Single(); return(updatedContinuation.Indentation - continuation.Indentation); }
public static void CodeTransmit_Action_WebBrowser(Case.CaseMethodItem refCaseMethodItemObj, Case.BasicTestCase refActiveCase, CodeLine activeSelectLine) { if (refCaseMethodItemObj != null && activeSelectLine.KeyCode == Container.KeyWordMap.WBAction) { try { refCaseMethodItemObj.Index = activeSelectLine.CodeIndex; refCaseMethodItemObj.ActiveMethod = new ElementActions.MethodItem(); refCaseMethodItemObj.ActiveMethod.ActiveType = typeof(WebDriver.WebBrowserActions); refActiveCase.ActiveCaseWebBrowserPool.Add(refCaseMethodItemObj.Index, refCaseMethodItemObj); object[] methodParam; foreach (string paramName in activeSelectLine.ParamsPool.Keys) { switch (paramName) { case WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_StartBrowser: refCaseMethodItemObj.ActiveMethod.ActiveMethod = refCaseMethodItemObj.ActiveMethod.ActiveType.GetMethod(WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_StartBrowser); if (activeSelectLine.ParamsPool[paramName] != Container.KeyWordMap.Null) { methodParam = new object[] { activeSelectLine.ParamsPool[paramName] }; refCaseMethodItemObj.ActiveMethod.MethodParams = methodParam; } break; case WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_SwitchToWindow: refCaseMethodItemObj.ActiveMethod.ActiveMethod = refCaseMethodItemObj.ActiveMethod.ActiveType.GetMethod(WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_SwitchToWindow); if (activeSelectLine.ParamsPool[paramName] != Container.KeyWordMap.Null) { methodParam = new object[] { activeSelectLine.ParamsPool[paramName] }; refCaseMethodItemObj.ActiveMethod.MethodParams = methodParam; } break; case WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_CloseWindow: refCaseMethodItemObj.ActiveMethod.ActiveMethod = refCaseMethodItemObj.ActiveMethod.ActiveType.GetMethod(WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_CloseWindow); break; case WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_Action_IsAlert: refCaseMethodItemObj.ActiveMethod.ActiveMethod = refCaseMethodItemObj.ActiveMethod.ActiveType.GetMethod(WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_Action_IsAlert); break; case WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_GetCurrentWindowHandle: refCaseMethodItemObj.ActiveMethod.ActiveMethod = refCaseMethodItemObj.ActiveMethod.ActiveType.GetMethod(WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_SwitchToWindow); break; case WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_GetSourceOfPage: refCaseMethodItemObj.ActiveMethod.ActiveMethod = refCaseMethodItemObj.ActiveMethod.ActiveType.GetMethod(WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_SwitchToWindow); <<<<<<< HEAD break; ======= break; >>>>>>> origin/master case WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_Action_Wait: refCaseMethodItemObj.ActiveMethod.ActiveMethod = refCaseMethodItemObj.ActiveMethod.ActiveType.GetMethod(WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_Action_Wait); methodParam = new object[] { activeSelectLine.ParamsPool[paramName] }; refCaseMethodItemObj.ActiveMethod.MethodParams = methodParam; <<<<<<< HEAD ======= break; case WebDriver.WebBrowserActionsMap.Method_Action_WB_Action_Action_GetCurrentURL: if (activeSelectLine.ParamsPool[paramName] != Container.KeyWordMap.Null) { string currentURLDataName = activeSelectLine.ParamsPool[paramName]; string currentURL = refActiveCase.ActionWebBrowserActionsObject.Action_GetCurrentURL(); if (refActiveCase.ActiveDataBuffer.ContainsKey(currentURLDataName)) refActiveCase.ActiveDataBuffer[currentURLDataName] = currentURL; else refActiveCase.ActiveDataBuffer.Add(currentURLDataName, currentURL); } >>>>>>> origin/master break; } } } catch (Exception err) { refActiveCase.SingleInterrupt = true; refActiveCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : WBAction : " + err.Message, true); } } }
static string GetFormattedCode(string code, TokenCollection tokens) { var currentLine = new CodeLine(); var lines = new List<CodeLine>(); int pos = 0; foreach (CategorizedToken token in tokens) { AppendCode(lines, ref currentLine, code.Substring(pos, token.StartPosition - pos), null); AppendCode(lines, ref currentLine, token.Value, CssClasses[token.Category].GetClassName(token.Language)); pos = token.EndPosition; } AppendCode(lines, ref currentLine, code.Substring(pos), null); lines.Add(currentLine); return MergeCodeLines(lines); }
public HaltLine(CodeLine codeLine) : base(codeLine.Code, codeLine, codeLine.Strings) { }
public DisableInterruptsLine(CodeLine codeLine) : base(codeLine.Code, codeLine, codeLine.Strings) { base.Comment = codeLine.Comment; base.Raw = codeLine.Raw; }
public void Visit(CodeLine l) { // niks }
public void EndsWithTab_NotCounted() { var result = new CodeLine($"{AnyString}{TabString}", TabCount); result.TabCount.ShouldEqual(0); }
public void OnCodeCreation(CodeLine codeLine, Color color) { ValidateRepeatedColor(codeLine, color); }
public void StartsWithThreeTabs_Counted() { var result = new CodeLine($"{TabString}{TabString}{TabString}{AnyString}", TabCount); result.TabCount.ShouldEqual(3); }
public RotateRegisterLeftLine(CodeLine codeLine) : base(codeLine.Code, codeLine, codeLine.Strings) { }
public void StartsWithSpace_ReturnsCorrectSpaceCount() { var result = new CodeLine($" {AnyString}", TabCount); result.SpaceCount.ShouldEqual(1); }
public PushOptionLine(CodeLine codeLine) : base(codeLine.Code, codeLine, codeLine.Strings) { base.Comment = codeLine.Comment; base.Raw = codeLine.Raw; }
/* Function: Normalize * * Cleans up the list of <CodeLines>. * * - Trims whitespace from all lines. * - Replaces empty lines with Text null, Indent -1. * - Removes empty lines from the beginning and end of the list. * - Removes shared indent. */ protected void Normalize(List <CodeLine> lines) { // Trim lines and make sure all blank lines are null with an indent of -1. We'll be finding the shared indent later and // we don't want to count unindented blank lines against it. for (int i = 0; i < lines.Count; i++) { if (lines[i].Text != null) { // Have to do it this way because CodeLine is a struct. CodeLine temp = lines[i]; temp.Text = temp.Text.Trim(); lines[i] = temp; } if (lines[i].Text == null || lines[i].Text.Length == 0) { CodeLine temp = new CodeLine(); temp.Text = null; temp.Indent = -1; lines[i] = temp; } } // Remove blank lines at the end and the beginning of the block. for (int i = lines.Count - 1; i >= 0; i--) { if (lines[i].Text == null) { lines.RemoveAt(i); } else { break; } } while (lines.Count > 0 && lines[0].Text == null) { lines.RemoveAt(0); } // Find the smallest indent on lines with content. int sharedIndent = -1; foreach (var line in lines) { if (line.Indent != -1 && (sharedIndent == -1 || line.Indent < sharedIndent)) { sharedIndent = line.Indent; } } // Remove shared indent from all lines if (sharedIndent >= 1) { for (int i = 0; i < lines.Count; i++) { if (lines[i].Indent != -1) { CodeLine temp = lines[i]; temp.Indent -= sharedIndent; lines[i] = temp; } } } }
public static void CodeTransmit_Action_DataFill(Case.BasicTestCase refTestCase, CodeLine activeSelectLine) { if (refTestCase != null && activeSelectLine.KeyCode == Container.KeyWordMap.DataFill) { if (!activeSelectLine.ParamsPool.ContainsKey("sourcename")) { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Data Fill : missing sourcename.", true); return; } else { if (!activeSelectLine.ParamsPool.ContainsKey("dataname")) { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Data Fill : missing dataname.", true); return; } else { string sourcename = activeSelectLine.ParamsPool["sourcename"]; if (!refTestCase.ActiveCaseDataSourcePool.ContainsKey(sourcename)) { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Data Fill : can not foune datasource : " + sourcename + ".", true); return; } XmlDocument sourceDoc = refTestCase.ActiveCaseDataSourcePool[sourcename]; if (sourceDoc != null) { if (activeSelectLine.ParamsPool.ContainsKey("row") && activeSelectLine.ParamsPool.ContainsKey("column")) { XmlNodeList rowNodes = sourceDoc.SelectNodes("/root/row"); int MaxRow = rowNodes.Count; if (MaxRow <= 0) { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Data Fill : no data row in data source.", true); return; } string RowValue = activeSelectLine.ParamsPool["row"]; string ColumnName = activeSelectLine.ParamsPool["column"]; int RowIndex = 1; if (RowValue == "rand") { Random rnd = new Random(); RowIndex = rnd.Next(1, MaxRow); } else { int.TryParse(activeSelectLine.ParamsPool["row"], out RowIndex); } XmlNode selectedRowNode = sourceDoc.SelectSingleNode("/root/row[@index='" + RowIndex + "']"); if (selectedRowNode != null) { string value = Buffalo.Basic.Data.XmlHelper.GetNodeValue("@column_" + ColumnName, selectedRowNode); string dataname = activeSelectLine.ParamsPool["dataname"]; if (refTestCase.ActiveDataBuffer.ContainsKey(dataname)) refTestCase.ActiveDataBuffer[dataname] = value; else refTestCase.ActiveDataBuffer.Add(dataname, value); } else { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Data Fill : can not found row node.", true); return; } } else { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Data Fill : missing row or column paramter.", true); return; } } else { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : Data Fill : datasource : " + sourcename + " is Null.", true); return; } } } } }
public PushLine(CodeLine codeLine) : base(codeLine.Code, codeLine, codeLine.Strings) { }
public ConstantAssignLine(CodeLine codeLine, ConstantLine constantLine) : base(codeLine.Code, codeLine, codeLine.Strings) { ConstantLine = constantLine; }
public EndLoadLine(CodeLine codeLine) : base(codeLine.Code, codeLine, codeLine.Strings) { }
static void EndNotHighlightedBlock(ref CodeLine currentLine) { currentLine.Html += "</div>"; }
private static void Main(string[] args) { Int64 lines_covered = 0; Int64 lines_partially_covered = 0; Int64 lines_not_covered = 0; string breakdown_percent_not_covered = ""; string breakdown_lines_not_covered = ""; string unit_names = ""; DirectoryInfo directory = new DirectoryInfo(args[0]); Console.WriteLine(directory.FullName); FileInfo[] files = directory.GetFiles("*.coverage"); foreach (FileInfo file in files) { Console.WriteLine("Analysing " + file.Name); Regex file_regex = new Regex(@"^(.+?)(_tests?)+.exe.coverage"); Match file_match = file_regex.Match(file.Name); string tested_unit = file_match.Groups[1].ToString(); Regex regex; if (tested_unit == "ksp_plugin") { Console.WriteLine("Covering principia::" + tested_unit + " as well as extern \"C\" interface functions" + " (of the form ::principia__Identifier)"); regex = new Regex("^principia(::" + tested_unit + "|__)"); } else { Console.WriteLine("Covering principia::" + tested_unit); regex = new Regex("^principia::" + tested_unit); } Regex ignored_files_regex = new Regex(@"((_test\.cpp|" + @"\.generated\.cc|" + @"\.generated\.h|" + @"\.pb\.h|" + @"\.pb\.cc)$|" + @"\\mock_)"); var covered = new Dictionary<CodeLine, UInt32>(); using (CoverageInfo info = CoverageInfo.CreateFromFile(file.FullName)) { CoverageDS dataset = info.BuildDataSet(); foreach (CoverageDSPriv.LinesRow lines in dataset.Lines) { if (regex.Match(lines.MethodRow.MethodName).Success && !ignored_files_regex.Match( dataset.GetSourceFileName(lines)).Success) { var code_line = new CodeLine { file = dataset.GetSourceFileName(lines), line_number = lines.LnStart}; if (lines.LnStart != lines.LnEnd) { Console.WriteLine("lines.LnStart != lines.LnEnd"); return; } if (covered.ContainsKey(code_line)) { covered[code_line] = Math.Min(covered[code_line], lines.Coverage); } else { covered.Add(code_line, lines.Coverage); } } } } Int64 subtotal_lines = covered.Count; Int64 subtotal_not_covered = 0; foreach (var pair in covered) { if (pair.Value > 1) { ++subtotal_not_covered; ++lines_not_covered; Console.WriteLine(pair.Key.file + ":" + pair.Key.line_number); } else if (pair.Value == 1) { ++lines_partially_covered; } else { ++lines_covered; } } CommaSeparatedAppend(ref breakdown_lines_not_covered, subtotal_not_covered.ToString()); CommaSeparatedAppend( ref breakdown_percent_not_covered, (((double)subtotal_not_covered / (double)subtotal_lines) * 100.0).ToString()); CommaSeparatedAppend(ref unit_names, tested_unit); } Int64 total = lines_partially_covered + lines_covered + lines_not_covered; Console.WriteLine("Covered : " + ValueAndPercentage(lines_partially_covered + lines_covered, total)); Console.WriteLine(" Partially : " + ValueAndPercentage(lines_partially_covered, total)); Console.WriteLine(" Completely : " + ValueAndPercentage(lines_covered, total)); Console.WriteLine("Not Covered : " + ValueAndPercentage(lines_not_covered, total)); File.WriteAllText( Path.Combine(directory.FullName, "jenkins_percent_coverage.csv"), "not covered, partially covered, fully covered\n" + ((double)lines_not_covered / (double)total) * 100.0 + ", " + ((double)lines_partially_covered / (double)total) * 100.0 + ", " + ((double)lines_covered / (double)total) * 100.0); File.WriteAllText( Path.Combine(directory.FullName, "jenkins_lines_coverage.csv"), "not covered, partially covered, fully covered\n" + lines_not_covered + ", " + lines_partially_covered + ", " + lines_covered); File.WriteAllText( Path.Combine(directory.FullName, "jenkins_lines_coverage_breakdown.csv"), unit_names + "\n" + breakdown_lines_not_covered); File.WriteAllText( Path.Combine(directory.FullName, "jenkins_percent_coverage_breakdown.csv"), unit_names + "\n" + breakdown_percent_not_covered); }
static string GetFormattedAspxCode(string code, DevExpress.CodeParser.TokenCollection tokens, string[] highlightedTagNames) { int position = 0; int highlightedTagsCount = 0; bool needCloseHighlightedBlock = false; bool isStartedHighlightedComment = false; bool thisTagIsComplex = true; CodeLine currentLine = new CodeLine(); List<CodeLine> lines = new List<CodeLine>(); StartNotHighlightedBlock(lines); for(int i = 0; i < tokens.Count; i++) { CategorizedToken token = tokens[i] as CategorizedToken; if(token.Value == StartHighlightedCodeBlockMarker) { isStartedHighlightedComment = true; position = token.EndPosition; continue; } if(ContainsTokenInTagNames(token.Value, highlightedTagNames)) { if(tokens[i - 1].Value == "<" && tokens[i + 1].Value != ">") { highlightedTagsCount++; thisTagIsComplex = IsComplexTag(tokens, i); } if(highlightedTagsCount > 0) { if(highlightedTagsCount == 1 && tokens[i + 1].Value != ">" && lines.Count > 0) StartHighlightedBlockAndCloseNotHighlighted(lines, false); AppendCodes(lines, ref currentLine, code, position, token); if(tokens[i - 1].Value == "</" && tokens[i + 1].Value == ">") { highlightedTagsCount--; needCloseHighlightedBlock = highlightedTagsCount == 0; } } } else { if(token.Value != StartHighlightedCodeBlockMarker && token.Value != EndHighlightedCodeBlockMarker) AppendCodes(lines, ref currentLine, code, position, token); if(lines.Count > 0 && isStartedHighlightedComment) { StartHighlightedBlockAndCloseNotHighlighted(lines, true); isStartedHighlightedComment = false; } if(!thisTagIsComplex && token.Value == "/>" || needCloseHighlightedBlock || token.Value == EndHighlightedCodeBlockMarker) EndHighlightedBlockAndStartNotHighlighted(ref currentLine); if(!thisTagIsComplex && token.Value == "/>") if(highlightedTagsCount > 0) highlightedTagsCount--; if(needCloseHighlightedBlock) needCloseHighlightedBlock = false; } position = token.EndPosition; } AppendCode(lines, ref currentLine, code.Substring(position), null); EndNotHighlightedBlock(ref currentLine); lines.Add(currentLine); return MergeCodeLines(lines); }
public PopOptionLine(CodeLine codeLine) : base(codeLine.Code, codeLine, codeLine.Strings) { }
static void AppendCodes(List<CodeLine> lines, ref CodeLine currentLine, string code, int pos, CategorizedToken token) { AppendCode(lines, ref currentLine, code.Substring(pos, token.StartPosition - pos), null); AppendCode(lines, ref currentLine, token.Value, CssClasses[token.Category].GetClassName(token.Language)); }
static void EndHighlightedBlockAndStartNotHighlighted(ref CodeLine currentLine) { currentLine.Html += "</div>" + StartNotHighlightedDivElement; }
public RepeatLine(CodeLine codeLine) : base(codeLine.Code, codeLine, codeLine.Strings) { base.Comment = codeLine.Comment; base.Raw = codeLine.Raw; Repeat = codeLine.Code.Trim()["REPT".Length..].Trim();
static string GetFormattedOtherCode(string code, DevExpress.CodeParser.TokenCollection tokens, string[] highlightedTagNames) { CodeLine currentLine = new CodeLine(); List<CodeLine> lines = new List<CodeLine>(); int position = 0; foreach(CategorizedToken token in tokens) { AppendCode(lines, ref currentLine, code.Substring(position, token.StartPosition - position), null); AppendCode(lines, ref currentLine, token.Value, CssClasses[token.Category].GetClassName(token.Language)); position = token.EndPosition; } AppendCode(lines, ref currentLine, code.Substring(position), null); lines.Add(currentLine); return MergeCodeLines(lines); }
private string GenerateScript(CodeLine code, ref List <string> exportableObjects) { StringBuilder sb = new StringBuilder(); switch (code.CodeActionType) { case CodeLineType.File: break; case CodeLineType.Reference: break; case CodeLineType.Namespace: break; case CodeLineType.Comment: sb.Append("// "); sb.Append(code.Target); sb.Append(Environment.NewLine); break; case CodeLineType.Class: case CodeLineType.FunctionDefinition: break; case CodeLineType.Constructor: CodeConstructor constructor = code as CodeConstructor; if (constructor.VariableType == "Human") { sb.Append("InitHc;"); sb.Append(Environment.NewLine); /* * hc_agressivity, hc_attr, hc_basic_skills, hc_class, hc_face_number, hc_gallery, hc_importance, hc_last_mission, hc_name, hc_sex, hc_skills */ //Nation nation, Class classType, Sex sex, string name if (constructor.ParameterValues.Length == 4) { sb.Append("uc_side = "); sb.Append(constructor.ParameterValues[0]); sb.Append(";"); sb.Append(Environment.NewLine); sb.Append("uc_nation = "); sb.Append(constructor.ParameterValues[1]); sb.Append(";"); sb.Append(Environment.NewLine); sb.Append("hc_class = "); sb.Append(constructor.ParameterValues[2]); sb.Append(";"); sb.Append(Environment.NewLine); sb.Append("hc_sex = "); sb.Append(constructor.ParameterValues[3]); sb.Append(";"); sb.Append(Environment.NewLine); } if (constructor.ParameterValues.Length == 5) { sb.Append("hc_name = "); sb.Append(constructor.ParameterValues[4]); sb.Append(";"); sb.Append(Environment.NewLine); } sb.Append(constructor.Target); sb.Append(" = CreateHuman;"); sb.Append(Environment.NewLine); /* * InitHc; * uc_side = nation_american; * hc_class = class_engineer; * hc_basic_skills = [2,0,0,0]; * Bob = CreateHuman; */ } exportableObjects.Add($"Export {constructor.Target};{Environment.NewLine}"); break; case CodeLineType.FunctionCall: CodeFunction function = code as CodeFunction; if (function.FunctionName == "Starting") { sb.Append(function.FunctionName); sb.Append(Environment.NewLine); sb.Append("Begin"); sb.Append(Environment.NewLine); } else { sb.Append(function.FunctionName); sb.Append('('); if (function.Target.Length > 0) { sb.Append(function.Target); if (function.ParameterValues.Length > 0) { sb.Append(", "); } } for (int i = 0; i < function.ParameterValues.Length; i++) { sb.Append(function.ParameterValues[i]); if (i < function.ParameterValues.Length - 1) { if (function.FunctionName == "Wait") { sb.Append("$ "); } else { sb.Append(", "); } } } sb.Append(");"); sb.Append(Environment.NewLine); } break; case CodeLineType.CodeOperator: CodeOperator action = code as CodeOperator; if (action.FunctionName == "Assignment") { if (action.VariableType == "Skills") { if (action.ParameterValues.Count() != 4) { throw new Exception("Skills does not have 4 parameters!"); } sb.Append("hc_basic_skills = ["); for (int i = 0; i < 4; i++) { sb.Append(action.ParameterValues[i]); if (i < 3) { sb.Append(", "); } } sb.Append("];"); sb.Append(Environment.NewLine); } } break; default: break; } for (int i = 0; i < code.Children.Count; i++) { // Ignore constructors that stand for objects defined in the editor if (!(code.CodeActionType == CodeLineType.Class && code.Children[i].CodeActionType == CodeLineType.Constructor)) { sb.Append(GenerateScript(code.Children[i], ref exportableObjects)); } } return(sb.ToString()); }
public static void CreateCodeLineViaCodeAndSetCode() { var line = new CodeLine("code"); line.Code = "new code"; Assert.Equal("new code", line.Code); }
static string GetFormattedAspxCode(string code, DevExpress.CodeParser.TokenCollection tokens, string[] highlightedTagNames) { int position = 0; int highlightedTagsCount = 0; bool needCloseHighlightedBlock = false; bool isStartedHighlightedComment = false; bool thisTagIsComplex = true; CodeLine currentLine = new CodeLine(); List <CodeLine> lines = new List <CodeLine>(); StartNotHighlightedBlock(lines); for (int i = 0; i < tokens.Count; i++) { CategorizedToken token = tokens[i] as CategorizedToken; if (token.Value == StartHighlightedCodeBlockMarker) { isStartedHighlightedComment = true; position = token.EndPosition; continue; } if (ContainsTokenInTagNames(token.Value, highlightedTagNames)) { if (tokens[i - 1].Value == "<" && tokens[i + 1].Value != ">") { highlightedTagsCount++; thisTagIsComplex = IsComplexTag(tokens, i); } if (highlightedTagsCount > 0) { if (highlightedTagsCount == 1 && tokens[i + 1].Value != ">" && lines.Count > 0) { StartHighlightedBlockAndCloseNotHighlighted(lines, false); } AppendCodes(lines, ref currentLine, code, position, token); if (tokens[i - 1].Value == "</" && tokens[i + 1].Value == ">") { highlightedTagsCount--; needCloseHighlightedBlock = highlightedTagsCount == 0; } } } else { if (token.Value != StartHighlightedCodeBlockMarker && token.Value != EndHighlightedCodeBlockMarker) { AppendCodes(lines, ref currentLine, code, position, token); } if (lines.Count > 0 && isStartedHighlightedComment) { StartHighlightedBlockAndCloseNotHighlighted(lines, true); isStartedHighlightedComment = false; } if (!thisTagIsComplex && token.Value == "/>" || needCloseHighlightedBlock || token.Value == EndHighlightedCodeBlockMarker) { EndHighlightedBlockAndStartNotHighlighted(ref currentLine); } if (!thisTagIsComplex && token.Value == "/>") { if (highlightedTagsCount > 0) { highlightedTagsCount--; } } if (needCloseHighlightedBlock) { needCloseHighlightedBlock = false; } } position = token.EndPosition; } AppendCode(lines, ref currentLine, code.Substring(position), null); EndNotHighlightedBlock(ref currentLine); lines.Add(currentLine); return(MergeCodeLines(lines)); }
public ParserResult(ClawToken[] Tokens, CodeLine[] Lines, CodeError[] CodeErrors) { this.Errors = CodeErrors; this.Tokens = Tokens; }
static void AppendCodes(List <CodeLine> lines, ref CodeLine currentLine, string code, int pos, CategorizedToken token) { AppendCode(lines, ref currentLine, code.Substring(pos, token.StartPosition - pos), null); AppendCode(lines, ref currentLine, token.Value, CssClasses[token.Category].GetClassName(token.Language)); }
static void AppendCode(List<CodeLine> lines, ref CodeLine currentLine, string code, string cssClass) { bool hasCss = !String.IsNullOrEmpty(cssClass); bool first = true; code = code.Replace("\r", "").Replace("\t", " "); foreach (string line in code.Split('\n')) { string text = line; if (!first) { lines.Add(currentLine); currentLine = new CodeLine(); text = text.TrimStart(); currentLine.Indent = line.Length - text.Length; } if (first || text.Trim().Length > 0) { if (hasCss) currentLine.Html += String.Format("<span class=\"{0}\">", cssClass); currentLine.Html += HttpUtility.HtmlEncode(text); if (hasCss) currentLine.Html += "</span>"; } first = false; } }
public static void CodeTransmit_Action_FillExistedData(Case.BasicTestCase refTestCase, CodeLine activeSelectLine) { foreach (string paramName in activeSelectLine.ParamsPool.Keys) { string paramValue = activeSelectLine.ParamsPool[paramName]; if (paramValue.Contains("%D")) { string dataName = paramValue.Replace("%D", ""); if (refTestCase.ActiveDataBuffer.ContainsKey(dataName)) activeSelectLine.ParamsPool[paramName] = refTestCase.ActiveDataBuffer[dataName]; else { refTestCase.SingleInterrupt = true; refTestCase.ActiveTestCaseReport.InsertFaildItem(activeSelectLine.CodeIndex, "Fail to transmit : No data : " + dataName, true); return; } } } }