public void AnnotatedCommodity_StripAnnotations_CanKeepvEverything() { Commodity commodity = new Commodity(CommodityPool.Current, new CommodityBase("comm")); AnnotatedCommodity annCommodity = new AnnotatedCommodity(commodity, new Annotation(new Amount(10), (Date)DateTime.Now.Date, "tag") { IsPriceFixated = true, IsPriceCalculated = true, IsDateCalculated = true, IsTagCalculated = true }); AnnotationKeepDetails keepDetails = new AnnotationKeepDetails() { KeepPrice = true, KeepDate = true, KeepTag = true }; Commodity newCommodity = annCommodity.StripAnnotations(keepDetails); Assert.IsNotNull(newCommodity); Assert.AreEqual(annCommodity, newCommodity); Assert.IsFalse(Object.ReferenceEquals(annCommodity, newCommodity)); Assert.IsTrue(newCommodity.IsAnnotated); AnnotatedCommodity newAnnCommodity = (AnnotatedCommodity)newCommodity; Assert.AreEqual(annCommodity.Details.Price, newAnnCommodity.Details.Price); Assert.AreEqual(annCommodity.Details.Date, newAnnCommodity.Details.Date); Assert.AreEqual(annCommodity.Details.Tag, newAnnCommodity.Details.Tag); // Flags are added even though they were not set in the original commodity Assert.IsTrue(newAnnCommodity.Details.IsPriceCalculated); Assert.IsTrue(newAnnCommodity.Details.IsPriceFixated); Assert.IsTrue(newAnnCommodity.Details.IsDateCalculated); Assert.IsTrue(newAnnCommodity.Details.IsTagCalculated); }
public QueryParser(Value args, AnnotationKeepDetails whatToKeep = default(AnnotationKeepDetails), bool multipleArgs = true) { Args = args; Lexer = new QueryLexer(args.AsSequence, multipleArgs); WhatToKeep = whatToKeep; QueryMap = new Dictionary <QueryKindEnum, string>(); }
public Query(Value args, AnnotationKeepDetails whatToKeep = default(AnnotationKeepDetails), bool multipleArgs = true) : this() { if (!Value.IsNullOrEmpty(args)) { ParseArgs(args, whatToKeep, multipleArgs); } }
public void AnnotationKeepDetails_DefaultContructors_ProducesInstanceWithAllFlagsUnchecked() { AnnotationKeepDetails details = new AnnotationKeepDetails(); Assert.False(details.KeepPrice); Assert.False(details.KeepDate); Assert.False(details.KeepTag); Assert.False(details.OnlyActuals); }
public ExprOp ParseArgs(Value args, AnnotationKeepDetails whatToKeep = default(AnnotationKeepDetails), bool multipleArgs = true, bool subExpression = false) { if (Parser == null) { Parser = new QueryParser(args, whatToKeep, multipleArgs); } return(Parser.Parse(subExpression)); }
public Query(string arg, AnnotationKeepDetails whatToKeep = default(AnnotationKeepDetails), bool multipleArgs = true) : this() { if (!String.IsNullOrEmpty(arg)) { Value temp = Value.Get(arg); ParseArgs(Value.Get(temp.AsSequence), whatToKeep, multipleArgs); } }
/** * Annotated commodity methods. The amounts contained by a balance * may use annotated commodities. The `strip_annotations' method * will return a balance all of whose component amount have had * their commodity annotations likewise stripped. See * amount_t::strip_annotations for more details. */ public Balance StripAnnotations(AnnotationKeepDetails whatToKeep) { Balance balance = new Balance(); foreach (Amount amount in Amounts.Values) { balance = balance.Add(amount.StripAnnotations(whatToKeep)); } return(balance); }
public void Amount_StripAnnotations_ReturnsOriginalAmountIfKeepAllIsTrue() { Commodity comm = new Commodity(CommodityPool.Current, new CommodityBase("comm")); Amount amount = new Amount(10, comm); AnnotationKeepDetails keepDetails = new AnnotationKeepDetails(); // Commodity is not annotated - it is enough condition to return the original object Amount newAmount = amount.StripAnnotations(keepDetails); Assert.AreEqual(amount, newAmount); }
public void Amount_StripAnnotations_ReturnsNewAmountForAnnotatedCommodity() { Commodity comm = new Commodity(CommodityPool.Current, new CommodityBase("comm")); AnnotatedCommodity annComm = new AnnotatedCommodity(comm, new Annotation()); Amount amount = new Amount(10, annComm); AnnotationKeepDetails keepDetails = new AnnotationKeepDetails(); // The original ampunt has annotated commodity, but "keepDetails" does not specify anything to keep. // Therefore, the new amount has not annotated commodity Amount newAmount = amount.StripAnnotations(keepDetails); Assert.IsFalse(newAmount.Commodity.IsAnnotated); }
public void AnnotationKeepDetails_KeepAll_IfCommodityIsNotAnnotated() { AnnotationKeepDetails detailsKeepAllTrue = new AnnotationKeepDetails() { KeepPrice = true, KeepDate = true, KeepTag = true, OnlyActuals = false }; AnnotationKeepDetails detailsKeepAllFalse = new AnnotationKeepDetails() { KeepPrice = true, KeepDate = true, KeepTag = true, OnlyActuals = true }; Commodity commodity = new Commodity(CommodityPool.Current, new CommodityBase("comm")); AnnotatedCommodity annCommodity = new AnnotatedCommodity(commodity, new Annotation()); Assert.True(detailsKeepAllTrue.KeepAll(commodity)); Assert.True(detailsKeepAllTrue.KeepAll(annCommodity)); Assert.True(detailsKeepAllFalse.KeepAll(commodity)); Assert.False(detailsKeepAllFalse.KeepAll(annCommodity)); }
public void AnnotationKeepDetails_KeepAny_IfCommodityIsAnnotated() { AnnotationKeepDetails detailsKeepAnyTrue = new AnnotationKeepDetails() { KeepPrice = true, KeepDate = true, KeepTag = true }; AnnotationKeepDetails detailsKeepAnyFalse = new AnnotationKeepDetails() { KeepPrice = false, KeepDate = false, KeepTag = false }; Commodity commodity = new Commodity(CommodityPool.Current, new CommodityBase("comm")); AnnotatedCommodity annCommodity = new AnnotatedCommodity(commodity, new Annotation()); Assert.False(detailsKeepAnyTrue.KeepAny(commodity)); Assert.True(detailsKeepAnyTrue.KeepAny(annCommodity)); Assert.False(detailsKeepAnyFalse.KeepAny(commodity)); Assert.False(detailsKeepAnyFalse.KeepAny(annCommodity)); }
public Predicate(string str, AnnotationKeepDetails whatToKeep, AmountParseFlagsEnum parseFlags = AmountParseFlagsEnum.PARSE_DEFAULT) : base(str, parseFlags) { WhatToKeep = whatToKeep; }
public Predicate(ExprOp op, AnnotationKeepDetails whatToKeep, Scope context = null) : base(op, context) { WhatToKeep = whatToKeep; }
public Predicate(AnnotationKeepDetails whatToKeep = default(AnnotationKeepDetails)) { WhatToKeep = whatToKeep; }
public virtual Commodity StripAnnotations(AnnotationKeepDetails whatToKeep) { return(this); }
public Value StripAnnotations(AnnotationKeepDetails whatToKeep) { IValueStorage storage = Storage != null?Storage.StripAnnotations(whatToKeep) : null; return(storage == Storage ? this : new Value(storage)); }