public void MergeFromFieldMask() { FieldMaskTree tree = new FieldMaskTree(); tree.MergeFromFieldMask(new FieldMask { Paths = { "foo", "bar.baz", "bar.quz" } }); RepeatedField <string> paths = tree.ToFieldMask().Paths; Assert.AreEqual(3, paths.Count); Assert.Contains("foo", paths); Assert.Contains("bar.baz", paths); Assert.Contains("bar.quz", paths); tree.MergeFromFieldMask(new FieldMask { Paths = { "foo.bar", "bar" } }); paths = tree.ToFieldMask().Paths; Assert.AreEqual(2, paths.Count); Assert.Contains("foo", paths); Assert.Contains("bar", paths); }
public void IntersectFieldPath() { FieldMaskTree tree = new FieldMaskTree(); FieldMaskTree result = new FieldMaskTree(); tree.MergeFromFieldMask(new FieldMask { Paths = { "foo", "bar.baz", "bar.quz" } }); // Empty path. tree.IntersectFieldPath("", result); RepeatedField <string> paths = result.ToFieldMask().Paths; Assert.AreEqual(0, paths.Count); // Non-exist path. tree.IntersectFieldPath("quz", result); paths = result.ToFieldMask().Paths; Assert.AreEqual(0, paths.Count); // Sub-path of an existing leaf. tree.IntersectFieldPath("foo.bar", result); paths = result.ToFieldMask().Paths; Assert.AreEqual(1, paths.Count); Assert.Contains("foo.bar", paths); // Match an existing leaf node. tree.IntersectFieldPath("foo", result); paths = result.ToFieldMask().Paths; Assert.AreEqual(1, paths.Count); Assert.Contains("foo", paths); // Non-exist path. tree.IntersectFieldPath("bar.foo", result); paths = result.ToFieldMask().Paths; Assert.AreEqual(1, paths.Count); Assert.Contains("foo", paths); // Match a non-leaf node. tree.IntersectFieldPath("bar", result); paths = result.ToFieldMask().Paths; Assert.AreEqual(3, paths.Count); Assert.Contains("foo", paths); Assert.Contains("bar.baz", paths); Assert.Contains("bar.quz", paths); }