public void ForString() { foreach (var s in someStrings) { Assert.Equal(s, Rope.ForString(s).ToString()); } }
public ConstantValueString(string value) { // we should have just one Null regardless string or object. LorettaDebug.Assert(value != null, "null strings should be represented as Null constant."); _value = Rope.ForString(value); _constantValueReference = new WeakReference <string>(value); }
public void Empty() { Rope r = Rope.Empty; Assert.Equal(0, r.Length); Assert.Equal(string.Empty, r.ToString()); Assert.Equal(r, Rope.ForString(string.Empty)); Assert.Equal(Rope.ForString(string.Empty), r); }
public void ForNullString() { Assert.Throws <ArgumentNullException>( () => { Rope.ForString(null); } ); }
public void Overflow() { Rope r = Rope.ForString("x"); Rope all = r; Assert.Equal(1, all.Length); for (int i = 1; i < 31; i++) { r = Rope.Concat(r, r); all = Rope.Concat(all, r); Assert.Equal(1 << i, r.Length); Assert.Equal((1 << (i + 1)) - 1, all.Length); } Assert.Equal(int.MaxValue, all.Length); var waferThinMint = Rope.ForString("y"); Assert.Throws <OverflowException>(() => Rope.Concat(all, waferThinMint)); Assert.Throws <OverflowException>(() => Rope.Concat(waferThinMint, all)); Assert.Throws <OverflowException>(() => Rope.Concat(all, all)); }
public void Concatenation() { foreach (var r1 in someRopes) { foreach (var r2 in someRopes) { foreach (var r3 in someRopes) { Rope c1 = Rope.Concat(r1, Rope.Concat(r2, r3)); Rope c2 = Rope.Concat(Rope.Concat(r1, r2), r3); Assert.Equal(c1, c2); // associative Assert.Equal(c1.GetHashCode(), c2.GetHashCode()); string s = r1.ToString() + r2.ToString() + r3.ToString(); Assert.Equal(c1.ToString(), s); Assert.Equal(c2.ToString(), s); Rope c3 = Rope.ForString(s); Assert.Equal(c1.GetHashCode(), c3.GetHashCode()); Assert.Equal(c1, c3); Assert.Equal(c2, c3); Assert.Equal(c3.ToString(), s); } } } }