public void BigStrings() { var st = new StringTable(0); var s1 = new string('x', StringTable.BytesPerBuffer - 1); var s2 = new string('y', StringTable.BytesPerBuffer); var s3 = new string('z', StringTable.BytesPerBuffer + 1); StringId id1 = st.AddString(s1); StringId id2 = st.AddString(s2); StringId id3 = st.AddString(s3); XAssert.AreEqual(s1.Length, st.GetLength(id1)); XAssert.AreEqual(s2.Length, st.GetLength(id2)); XAssert.AreEqual(s3.Length, st.GetLength(id3)); var buf = new char[StringTable.BytesPerBuffer + 1]; st.CopyString(id1, buf, 0); for (int j = 0; j < s1.Length; j++) { XAssert.AreEqual(s1[j], buf[j]); } st.CopyString(id2, buf, 0); for (int j = 0; j < s2.Length; j++) { XAssert.AreEqual(s2[j], buf[j]); } st.CopyString(id3, buf, 0); for (int j = 0; j < s3.Length; j++) { XAssert.AreEqual(s3[j], buf[j]); } XAssert.IsTrue(st.CaseInsensitiveEquals(id1, st.AddString(s1))); XAssert.IsTrue(st.CaseInsensitiveEquals(id2, st.AddString(s2))); XAssert.IsTrue(st.CaseInsensitiveEquals(id3, st.AddString(s3))); XAssert.IsTrue(st.Equals(s1, id1)); XAssert.IsTrue(st.Equals(s2, id2)); XAssert.IsTrue(st.Equals(s3, id3)); XAssert.IsFalse(st.CaseInsensitiveEquals(id1, st.AddString(s2))); XAssert.IsFalse(st.CaseInsensitiveEquals(id1, st.AddString(s3))); XAssert.IsFalse(st.CaseInsensitiveEquals(id2, st.AddString(s1))); XAssert.IsFalse(st.CaseInsensitiveEquals(id2, st.AddString(s3))); XAssert.IsFalse(st.CaseInsensitiveEquals(id3, st.AddString(s1))); XAssert.IsFalse(st.CaseInsensitiveEquals(id3, st.AddString(s2))); XAssert.IsFalse(st.Equals(s2, id1)); XAssert.IsFalse(st.Equals(s3, id1)); XAssert.IsFalse(st.Equals(s1, id2)); XAssert.IsFalse(st.Equals(s3, id2)); XAssert.IsFalse(st.Equals(s1, id3)); XAssert.IsFalse(st.Equals(s2, id3)); }
public void Match() { var st = new StringTable(0); StringId id1 = st.AddString("Hello"); StringId id2 = st.AddString("Goodbye"); StringId id3 = st.AddString("hello"); StringId id4 = st.AddString("goodBYE"); StringId id5 = st.AddString("HELLOX"); StringId id6 = st.AddString("HEL"); XAssert.AreNotEqual(id1, id3); XAssert.AreNotEqual(id1, id5); XAssert.AreNotEqual(id1, id6); XAssert.AreNotEqual(id5, id6); XAssert.AreNotEqual(id2, id4); // different length, different character sizes StringId ascii = st.AddString("abc"); XAssert.IsFalse(st.CaseInsensitiveEquals(ascii, st.AddString("\u1234\u1234"))); XAssert.IsTrue(st.CaseInsensitiveEquals(ascii, st.AddString("abc"))); XAssert.IsFalse(st.Equals("\u1234\u1234", ascii)); XAssert.IsTrue(st.Equals("abc", ascii)); // same length, different character sizes ascii = st.AddString("abc"); XAssert.IsFalse(st.CaseInsensitiveEquals(ascii, st.AddString("\u1234\u1234\u1234"))); XAssert.IsTrue(st.CaseInsensitiveEquals(ascii, st.AddString("abc"))); XAssert.IsFalse(st.Equals("\u1234\u1234\u1234", ascii)); XAssert.IsTrue(st.Equals("abc", ascii)); // different length, different character sizes StringId utf16 = st.AddString("\u1234\u1234"); XAssert.IsFalse(st.CaseInsensitiveEquals(utf16, st.AddString("abc"))); XAssert.IsTrue(st.CaseInsensitiveEquals(utf16, st.AddString("\u1234\u1234"))); XAssert.IsFalse(st.Equals("abc", utf16)); XAssert.IsTrue(st.Equals("\u1234\u1234", utf16)); // same length, different character sizes utf16 = st.AddString("\u1234\u1234"); XAssert.IsFalse(st.CaseInsensitiveEquals(utf16, st.AddString("ab"))); XAssert.IsTrue(st.CaseInsensitiveEquals(utf16, st.AddString("\u1234\u1234"))); XAssert.IsFalse(st.Equals("ab", utf16)); XAssert.IsTrue(st.Equals("\u1234\u1234", utf16)); }