public void CheckContract(string contract, ContractKind kind, Category expected)
        {
            var root = Syntax.ParseExpression(contract);
              var collector = new CodeContractCollector(kind, Categories.SemanticCategories);

              collector.Visit(root);

              Assert.AreEqual(1, collector.Labels.Count, "Expected a single top-level contract clause");

              var labels = collector.Labels[0].Labels.ToList();

              Assert.IsTrue(labels.Count > 0, string.Format("Contract {0} not labeled", contract));
              Assert.AreEqual(1, labels.Count, "Expected a single label for the contract");
              Assert.AreEqual(expected.Name, labels[0], string.Format("Contract {0} miscategorized", contract));
        }
示例#2
0
 private static string CategoryLogName(Category category)
 {
     // https://stackoverflow.com/questions/5680730/c-sharp-remove-special-characters
       var clean = Regex.Replace(category.Name, "[^a-zA-Z0-9% ._]", "_");
       return clean + ".txt";
 }
 /// <summary>
 /// Create a <see cref="CodeContractCollector"/> for the given kinds of contracts and categories
 /// </summary>
 /// <param name="kind">The kind(s) of contracts to operate on</param>
 /// <param name="categories">
 /// An ordered array of categories where earlier categories take precedence if
 /// the <see cref="CATEGORIES_ARE_MUTEX"/> flag is set
 /// </param>
 public CodeContractCollector(ContractKind kind, Category[] categories)
 {
     this.ContractType = kind;
       this.Categories = categories;
       this.Labels = new List<ContractTags>();
 }