public void GetHashCodeTest() { NativeString str = "Hola"; Assert.NotZero(str.GetHashCode()); str.Dispose(); Assert.Zero(str.GetHashCode()); }
//[Theory(Timeout = 1000 * 120)] //[ClassData(typeof(StringGenerator))] public void LoadTest(string[] data) { var hashMap = new HashSet <int>(); foreach (var s in data) { Assert.True(hashMap.Add(NativeString.GetHashCode(s))); } }
public void AllocateTest() { var str = "foo-bar"; var p = NativeString.Wrap(str); Assert.Equal(str.Length, p.GetLen()); Assert.Equal(Encoding.UTF8.GetByteCount(str), p.GetBuffer().Length); Assert.Equal(Encoding.UTF8, p.GetEncoding()); Assert.Equal(NativeString.GetHashCode(str), p.GetHashCode()); }
public unsafe void LoadMeta(byte[] meta) { using var steam = new MemoryStream(meta); while (steam.Position != steam.Length) { var template = MetaTemplate.FromBytes(steam.ReadBytes(sizeof(MetaTemplate))); if (template.type == TemplateType.STR) { var str = Encoding.UTF8.GetString(steam.ReadBytes(template.len)); if (!StringLiteralMap.Has(NativeString.GetHashCode(str))) { StringLiteralMap.InternString(NativeString.Wrap(str)); } } if (template.type == TemplateType.RND) { steam.ReadBytes(template.len); } } }