public Expr Parse(ParserContext pcon, object form) { int argCount = RT.count(form) - 1; if (argCount != 1) { IPersistentMap exData = new PersistentArrayMap(new Object[] { FormKey, form }); throw new ExceptionInfo("Wrong number of args (" + argCount + ") passed to quote", exData); } object v = RT.second(form); if (v == null) return Compiler.NilExprInstance; else if (v is Boolean) { if ((bool)v) return Compiler.TrueExprInstance; else return Compiler.FalseExprInstance; } else if (Util.IsNumeric(v)) return NumberExpr.Parse(v); else if (v is string) return new StringExpr((String)v); else if (v is IPersistentCollection && ((IPersistentCollection)v).count() == 0) return new EmptyExpr(v); else return new ConstantExpr(v); }
public void EqualsOnSimilarDictionaryReturnsTrue() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.equiv(d)); }
public void EntryAtReturnsNullOnMissingKey() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.entryAt(3)).To.Be.Null(); }
public void ValAt1ReturnsNullOnMissingKey() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.valAt(3), Null); }
public void ValAt2ReturnsDefaultOnMissingKey() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.valAt(3, 99), EqualTo(99)); }
public void IDictionary_Contains_does_not_find_existing_key() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IDictionary id = (IDictionary)PersistentArrayMap.create(d); Expect(id.Contains(3), False); }
public void ICollection_SyncRoot_fails() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; ICollection c = (ICollection)PersistentArrayMap.create(d); object s = c.SyncRoot; }
public void ContainsKeyNotConfusedByValue() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.containsKey("a"), False); }
public void ValAt2ReturnsValueforKey() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.valAt(1, 99), EqualTo("a")); }
public void AssocExFailsOnExistingKey() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m1 = PersistentArrayMap.create(d); m1.assocEx(2, "c"); }
public void IDictionary_IsReadOnly_is_true() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IDictionary id = (IDictionary)PersistentArrayMap.create(d); Expect(id.IsReadOnly); }
public void ICollection_Count_returns_count_of_items() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; ICollection c = (ICollection)PersistentArrayMap.create(d); Expect(c.Count, EqualTo(2)); }
public void ContainsKeyOnMissingKeyIsFalse() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.containsKey(3), False); }
public void IDictionary_Add_fails() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IDictionary id = (IDictionary)PersistentArrayMap.create(d); id.Add(1, "c"); }
public void IDictionary_Remove_fails() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IDictionary id = (IDictionary)PersistentArrayMap.create(d); id.Remove(1); }
public void ICollection_IsSynchronized_is_true() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; ICollection c = (ICollection)PersistentArrayMap.create(d); Expect(c.IsSynchronized); }
public void InvokeOn1ArgDoesValAt1() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IFn f = (IFn)PersistentArrayMap.create(d); Expect(f.invoke(1), EqualTo("a")); Expect(f.invoke(7), Null); }
public void ConsOnNon2IPVFails() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); IPersistentVector v = PersistentVector.create(2, "c", 3, "d"); IPersistentMap c = m.cons(v); }
public void IDictionary_index_acts_like_valAt() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IDictionary id = (IDictionary)PersistentArrayMap.create(d); Expect(id[2], EqualTo("b")); Expect(id[3], Null); }
public void InvokeOn2ArgsDoesValAt2() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IFn f = (IFn)PersistentArrayMap.create(d); Expect(f.invoke(1, 99), EqualTo("a")); Expect(f.invoke(7, 99), EqualTo(99)); }
public void EmptyReturnsEmpty() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); IPersistentCollection c = m.empty(); Expect(c.count(), EqualTo(0)); Expect(c.seq(), Null); }
public void Setup() { IPersistentMap meta = new DummyMeta(); Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "abc"; _objWithNullMeta = (IObj)PersistentArrayMap.create(d); _obj = _objWithNullMeta.withMeta(meta); _expectedType = typeof(PersistentArrayMap); }
public void ContainsKeyOnExistingKeyIsTrue() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.containsKey(1)); Expect(m.containsKey(2)); }
public void EqualsOnDictionaryWIthDifferntValueReturnsFalse() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); d[2] = "c"; Expect(m.Equals(d)).To.Be.False(); }
public void WithoutOnMissingKeyIsIdentity() { Dictionary <int, string> d = new Dictionary <int, string>(); d[3] = "a"; d[5] = "b"; d[7] = "c"; IPersistentMap m1 = PersistentArrayMap.create(d); IPersistentMap m2 = m1.without(4); Expect(m2, SameAs(m1)); }
public void EntryAtReturnsEntryforKey() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); IMapEntry me = m.entryAt(1); Expect(me.key(), EqualTo(1)); Expect(me.val(), EqualTo("a")); }
public void EqualsOnDictionaryWithExtraValueReturnsFalse() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); d[3] = "c"; Expect(m.Equals(d), False); }
public void ICollection_SyncRoot_fails() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; ICollection c = (ICollection)PersistentArrayMap.create(d); object s = c.SyncRoot; Expect(Object.ReferenceEquals(s, c)); }
public void HashCodeBasedOnValue() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m1 = PersistentArrayMap.create(d); d[3] = "c"; IPersistentMap m2 = PersistentArrayMap.create(d); Expect(m1.GetHashCode(), Not.EqualTo(m2.GetHashCode())); }
public void CreateOnDictionaryReturnsMap() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m = PersistentArrayMap.create(d); Expect(m.count(), EqualTo(2)); Expect(m.valAt(1), EqualTo("a")); Expect(m.valAt(2), EqualTo("b")); Expect(m.containsKey(3), False); }
public void AssocExModifiesOnNewKey() { Dictionary <int, string> d = new Dictionary <int, string>(); d[1] = "a"; d[2] = "b"; IPersistentMap m1 = PersistentArrayMap.create(d); IPersistentMap m2 = m1.assocEx(3, "c"); Expect(m1.count(), EqualTo(2)); Expect(m1.containsKey(3), False); Expect(m2.count(), EqualTo(3)); Expect(m2.valAt(3), EqualTo("c")); }