Exemplo n.º 1
0
		public void NewEntryGetsGuid()
		{
			Extensible extensibleInfo = new Extensible();
			extensibleInfo.Guid = Guid.NewGuid();
			LexEntry e = _builder.GetOrMakeEntry(extensibleInfo, 0);
			Assert.AreEqual(extensibleInfo.Guid, e.Guid);
			_builder.FinishEntry(e);
			Assert.AreEqual(1, _repository.CountAllItems());
		}
Exemplo n.º 2
0
 public ActivityDefinition(LanguageMap name,LanguageMap description, Uri type, string interactionType, string moreInfo, Extensible extensions)
 {
     this.name = name;
     this.description = description;
     this.type = type;
     this.interaction = interaction;
     this.moreInfo = moreInfo;
     this.extensions = extensions;
 }
Exemplo n.º 3
0
		public void NewEntry_NoDefYesGloss_GlossCopiedToDefintion()
		{
			Extensible extensibleInfo = new Extensible();
			LexEntry e = _builder.GetOrMakeEntry(extensibleInfo, 0);
			LexSense s = _builder.GetOrMakeSense(e, new Extensible(), string.Empty);
			_builder.MergeInGloss(s, new LiftMultiText("x","x meaning"));
			_builder.FinishEntry(e);
			Assert.AreEqual("x meaning",e.Senses[0].Gloss.GetExactAlternative("x"));
			Assert.AreEqual("x meaning",e.Senses[0].Definition.GetExactAlternative("x"));
		}
Exemplo n.º 4
0
		public void NewEntryGetsDates()
		{
			Extensible extensibleInfo = new Extensible();
			extensibleInfo.CreationTime = DateTime.Parse("2/2/1969  12:15:12").ToUniversalTime();
			extensibleInfo.ModificationTime =
					DateTime.Parse("10/11/1968  12:15:12").ToUniversalTime();
			LexEntry e = _builder.GetOrMakeEntry(extensibleInfo, 0);
			Assert.AreEqual(extensibleInfo.CreationTime, e.CreationTime);
			Assert.AreEqual(extensibleInfo.ModificationTime, e.ModificationTime);
			_builder.FinishEntry(e);
			Assert.AreEqual(1, _repository.CountAllItems());
		}
Exemplo n.º 5
0
 public void Construct_ModificationTimeIsUtc()
 {
     Extensible e = new Extensible();
     Assert.AreEqual(DateTimeKind.Utc, e.ModificationTime.Kind);
 }
Exemplo n.º 6
0
		public void EntryWithChildren()
		{
			Extensible extensibleInfo = new Extensible();
			LexEntry e = MakeSimpleEntry();
			LexSense s = _builder.GetOrMakeSense(e, extensibleInfo, string.Empty);

			LexExampleSentence ex = _builder.GetOrMakeExample(s, new Extensible());
			ex.Sentence["foo"] = "this is a sentence";
			ex.Translation["aa"] = "aaaa";
			_builder.FinishEntry(e);
			CheckCompleteEntry(e);

			RepositoryId[] entries = _repository.GetAllItems();
			Assert.AreEqual(1, entries.Length);

			//now check it again, from the list
			CheckCompleteEntry(_repository.GetItem(entries[0]));
		}
Exemplo n.º 7
0
        private static object FastNew(CodeContext /*!*/ context, object o)
        {
            Extensible <BigInteger> el;

            if (o is string)
            {
                return(__new__(null, (string)o, 10));
            }
            if (o is double)
            {
                return(DoubleOps.__int__((double)o));
            }
            if (o is int)
            {
                return(o);
            }
            if (o is bool)
            {
                return(((bool)o) ? 1 : 0);
            }
            if (o is BigInteger)
            {
                int res;
                if (((BigInteger)o).AsInt32(out res))
                {
                    return(ScriptingRuntimeHelpers.Int32ToObject(res));
                }
                return(o);
            }

            if ((el = o as Extensible <BigInteger>) != null)
            {
                int res;
                if (el.Value.AsInt32(out res))
                {
                    return(ScriptingRuntimeHelpers.Int32ToObject(res));
                }
                return(el.Value);
            }

            if (o is float)
            {
                return(DoubleOps.__int__((double)(float)o));
            }

            if (o is Complex)
            {
                throw PythonOps.TypeError("can't convert complex to int; use int(abs(z))");
            }

            if (o is Int64)
            {
                Int64 val = (Int64)o;
                if (Int32.MinValue <= val && val <= Int32.MaxValue)
                {
                    return((Int32)val);
                }
                else
                {
                    return((BigInteger)val);
                }
            }
            else if (o is UInt32)
            {
                UInt32 val = (UInt32)o;
                if (val <= Int32.MaxValue)
                {
                    return((Int32)val);
                }
                else
                {
                    return((BigInteger)val);
                }
            }
            else if (o is UInt64)
            {
                UInt64 val = (UInt64)o;
                if (val <= Int32.MaxValue)
                {
                    return((Int32)val);
                }
                else
                {
                    return((BigInteger)val);
                }
            }
            else if (o is Decimal)
            {
                Decimal val = (Decimal)o;
                if (Int32.MinValue <= val && val <= Int32.MaxValue)
                {
                    return((Int32)val);
                }
                else
                {
                    return((BigInteger)val);
                }
            }
            else if (o is Enum)
            {
                return(((IConvertible)o).ToInt32(null));
            }

            Extensible <string> es = o as Extensible <string>;

            if (es != null)
            {
                // __int__ takes precedence, call it if it's available...
                object value;
                if (PythonTypeOps.TryInvokeUnaryOperator(DefaultContext.Default, es, "__int__", out value))
                {
                    return(value);
                }

                // otherwise call __new__ on the string value
                return(__new__(null, es.Value, 10));
            }

            object     result;
            int        intRes;
            BigInteger bigintRes;

            if (PythonTypeOps.TryInvokeUnaryOperator(context, o, "__int__", out result) &&
                !Object.ReferenceEquals(result, NotImplementedType.Value))
            {
                if (result is int || result is BigInteger ||
                    result is Extensible <int> || result is Extensible <BigInteger> )
                {
                    return(result);
                }
                else
                {
                    throw PythonOps.TypeError("__int__ returned non-Integral (type {0})", PythonTypeOps.GetOldName(result));
                }
            }
            else if (PythonOps.TryGetBoundAttr(context, o, "__trunc__", out result))
            {
                result = PythonOps.CallWithContext(context, result);
                if (result is int || result is BigInteger ||
                    result is Extensible <int> || result is Extensible <BigInteger> )
                {
                    return(result);
                }
                else if (Converter.TryConvertToInt32(result, out intRes))
                {
                    return(intRes);
                }
                else if (Converter.TryConvertToBigInteger(result, out bigintRes))
                {
                    return(bigintRes);
                }
                else
                {
                    throw PythonOps.TypeError("__trunc__ returned non-Integral (type {0})", PythonTypeOps.GetOldName(result));
                }
            }

            if (o is OldInstance)
            {
                throw PythonOps.AttributeError("{0} instance has no attribute '__trunc__'", PythonTypeOps.GetOldName((OldInstance)o));
            }
            else
            {
                throw PythonOps.TypeError("int() argument must be a string or a number, not '{0}'", PythonTypeOps.GetName(o));
            }
        }
Exemplo n.º 8
0
 public static int Compare(BigInteger x, Extensible<double> y) {
     return -((int)DoubleOps.Compare(y.Value, x));
 }
Exemplo n.º 9
0
		public void Entry_Order()
		{
			Extensible extensibleInfo = new Extensible();
			LexEntry entry4 = this._builder.GetOrMakeEntry(extensibleInfo, 4);
			this._builder.FinishEntry(entry4);
			LexEntry entry1 = this._builder.GetOrMakeEntry(extensibleInfo, 1);
			this._builder.FinishEntry(entry1);
			LexEntry entry2 = this._builder.GetOrMakeEntry(extensibleInfo, 2);
			this._builder.FinishEntry(entry2);
			_exporter.Add(entry4, 3);
			_exporter.Add(entry1, 1);
			_exporter.Add(entry2, 2);

			_exporter.End();
			AssertXPathNotNull("//entry[@order='1']");
			AssertXPathNotNull("//entry[@order='2']");
			AssertXPathNotNull("//entry[@order='3']");
		}
Exemplo n.º 10
0
		public void SenseGetsPictureWithCaption()
		{
			Extensible extensibleInfo = new Extensible();
			LexEntry e = MakeSimpleEntry();
			LexSense s = _builder.GetOrMakeSense(e, extensibleInfo, string.Empty);

			LiftMultiText caption = new LiftMultiText();
			caption["aa"] = new LiftString("acaption");
			_builder.MergeInPicture(s, "testPicture.png", caption);
			PictureRef pict = s.GetProperty<PictureRef>("Picture");
			Assert.AreEqual("testPicture.png", pict.Value);
			Assert.AreEqual("acaption", pict.Caption["aa"]);
		}
Exemplo n.º 11
0
		private static Extensible AddDates(Extensible extensibleInfo)
		{
			extensibleInfo.CreationTime = Extensible.ParseDateTimeCorrectly("2003-08-07T08:42:42Z");
			extensibleInfo.ModificationTime =
					Extensible.ParseDateTimeCorrectly("2005-01-01T01:11:11+8:00");
			return extensibleInfo;
		}
Exemplo n.º 12
0
 public void Construct_CreationTimeSameAsModifiedTime()
 {
     Extensible e = new Extensible();
     Assert.IsTrue(e.CreationTime == e.ModificationTime);
 }
Exemplo n.º 13
0
 public void Construct_GuidIsNotEmpty()
 {
     Extensible e = new Extensible();
     Assert.IsTrue(e.Guid != Guid.Empty);
 }
Exemplo n.º 14
0
 public void Construct_CreationTimeRecent()
 {
     Extensible e = new Extensible();
     // created less than one second ago
     Assert.Less(DateTime.UtcNow - e.CreationTime, new TimeSpan(0, 0, 1));
 }
 IExtension IExtensible.GetExtensionObject(bool createIfMissing)
 {
     return(Extensible.GetExtensionObject(ref this.extensionObject, createIfMissing));
 }
Exemplo n.º 16
0
        private DynamicMetaObject TryToCharConversion(DynamicMetaObject /*!*/ self)
        {
            DynamicMetaObject res;
            // we have an implicit conversion to char if the
            // string length == 1, but we can only represent
            // this is implicit via a rule.
            string     strVal  = self.Value as string;
            Expression strExpr = self.Expression;

            if (strVal == null)
            {
                Extensible <string> extstr = self.Value as Extensible <string>;
                if (extstr != null)
                {
                    strVal  = extstr.Value;
                    strExpr =
                        Ast.Property(
                            AstUtils.Convert(
                                strExpr,
                                typeof(Extensible <string>)
                                ),
                            typeof(Extensible <string>).GetProperty("Value")
                            );
                }
            }

            // we can only produce a conversion if we have a string value...
            if (strVal != null)
            {
                self = self.Restrict(self.GetRuntimeType());

                Expression getLen = Ast.Property(
                    AstUtils.Convert(
                        strExpr,
                        typeof(string)
                        ),
                    typeof(string).GetProperty("Length")
                    );

                if (strVal.Length == 1)
                {
                    res = new DynamicMetaObject(
                        Ast.Call(
                            AstUtils.Convert(strExpr, typeof(string)),
                            typeof(string).GetMethod("get_Chars"),
                            AstUtils.Constant(0)
                            ),
                        self.Restrictions.Merge(BindingRestrictions.GetExpressionRestriction(Ast.Equal(getLen, AstUtils.Constant(1))))
                        );
                }
                else
                {
                    res = new DynamicMetaObject(
                        this.Throw(
                            Ast.Call(
                                typeof(PythonOps).GetMethod(nameof(PythonOps.TypeError)),
                                AstUtils.Constant("expected string of length 1 when converting to char, got '{0}'"),
                                Ast.NewArrayInit(typeof(object), self.Expression)
                                ),
                            ReturnType
                            ),
                        self.Restrictions.Merge(BindingRestrictions.GetExpressionRestriction(Ast.NotEqual(getLen, AstUtils.Constant(1))))
                        );
                }
            }
            else
            {
                // let the base class produce the rule
                res = null;
            }

            return(res);
        }
Exemplo n.º 17
0
 static void TestWriteNull <T>() where T : IExtTest, IExtensible, new()
 {
     Extensible.AppendValue <string>(null, 1, "hi");
 }
Exemplo n.º 18
0
 static void TestReadNull <T>() where T : IExtTest, IExtensible, new()
 {
     string hi = Extensible.GetValue <string>(null, 1);
 }
Exemplo n.º 19
0
		private static Extensible CreateFullextensibleInfo(Guid g)
		{
			Extensible extensibleInfo = new Extensible();
			extensibleInfo.Guid = g;
			extensibleInfo = AddDates(extensibleInfo);
			return extensibleInfo;
		}
Exemplo n.º 20
0
		public void NewEntry_YesDefYesGloss_BothUnchanged()
		{
			Extensible extensibleInfo = new Extensible();
			LexEntry e = _builder.GetOrMakeEntry(extensibleInfo, 0);
			LexSense s = _builder.GetOrMakeSense(e, new Extensible(), string.Empty);
			_builder.MergeInGloss(s, new LiftMultiText("x", "x gloss"));
			_builder.MergeInDefinition(s, new LiftMultiText("x", "x def"));
			_builder.FinishEntry(e);
			Assert.AreEqual("x gloss", e.Senses[0].Gloss.GetExactAlternative("x"));
			Assert.AreEqual("x def", e.Senses[0].Definition.GetExactAlternative("x"));
		}
Exemplo n.º 21
0
		public void SenseGetsPictureNoCaption()
		{
			Extensible extensibleInfo = new Extensible();
			LexEntry e = MakeSimpleEntry();
			LexSense s = _builder.GetOrMakeSense(e, extensibleInfo, string.Empty);

			_builder.MergeInPicture(s, "testPicture.png", null);
			PictureRef pict = s.GetProperty<PictureRef>("Picture");
			Assert.AreEqual("testPicture.png", pict.Value);
			Assert.IsNull(pict.Caption);
		}
Exemplo n.º 22
0
		public void NewEntry_NoGlossNoDef_GetNeitherInTheSense()
		{
			Extensible extensibleInfo = new Extensible();
			LexEntry e = _builder.GetOrMakeEntry(extensibleInfo, 0);
			LexSense s = _builder.GetOrMakeSense(e, new Extensible(), string.Empty);
			_builder.FinishEntry(e);
			Assert.AreEqual(0,e.Senses[0].Gloss.Count);
			Assert.AreEqual(0, e.Senses[0].Definition.Count);
		}
Exemplo n.º 23
0
		public void GetOrMakeEntry_ReturnedLexEntryIsDirty()
		{
			Extensible extensibleInfo = new Extensible();
			LexEntry entry = _builder.GetOrMakeEntry(extensibleInfo, 0);
			Assert.IsTrue(entry.IsDirty);
		}
Exemplo n.º 24
0
		public void NewEntryWithTextIdIgnoresIt()
		{
			Extensible extensibleInfo = new Extensible();
			extensibleInfo.Id = "hello";
			LexEntry e = _builder.GetOrMakeEntry(extensibleInfo, 0);
			//no attempt is made to use that id
			Assert.IsNotNull(e.Guid);
			Assert.AreNotSame(Guid.Empty, e.Guid);
		}
Exemplo n.º 25
0
		public void NewEntryTakesGivenDates()
		{
			Extensible extensibleInfo = new Extensible();
			extensibleInfo = AddDates(extensibleInfo);

			LexEntry e = _builder.GetOrMakeEntry(extensibleInfo, 0);
			Assert.AreEqual(extensibleInfo.CreationTime, e.CreationTime);
			Assert.AreEqual(extensibleInfo.ModificationTime, e.ModificationTime);
		}
Exemplo n.º 26
0
		public void SenseGetsExample()
		{
			LexSense sense = new LexSense();
			Extensible x = new Extensible();
			LexExampleSentence ex = _builder.GetOrMakeExample(sense, x);
			Assert.IsNotNull(ex);
			_builder.MergeInExampleForm(ex, MakeBasicLiftMultiText());
			Assert.AreEqual(2, ex.Sentence.Forms.Length);
			Assert.AreEqual("dos", ex.Sentence["ws-two"]);
		}
Exemplo n.º 27
0
		private LexEntry MakeSimpleEntry()
		{
			Extensible extensibleInfo = new Extensible();
			return _builder.GetOrMakeEntry(extensibleInfo, 0);
		}
Exemplo n.º 28
0
		public void SenseGetsId()
		{
			Extensible extensibleInfo = new Extensible();
			extensibleInfo.Id = "foo";
			LexSense s = _builder.GetOrMakeSense(new LexEntry(), extensibleInfo, string.Empty);
			Assert.AreEqual(extensibleInfo.Id, s.Id);
		}
Exemplo n.º 29
0
 public static object __new__(CodeContext context, PythonType cls, Extensible<double> o) {
     object value;
     // always succeeds as float defines __int__
     PythonTypeOps.TryInvokeUnaryOperator(context, o, "__int__", out value);
     if (cls == TypeCache.Int32) {
         return (int)value;
     } else {
         return cls.CreateInstance(context, value);
     }
 }
Exemplo n.º 30
0
 public static int Compare(BigInteger x, [NotNull] Extensible <double> y)
 {
     return(-((int)DoubleOps.Compare(y.Value, x)));
 }