Add test cases and fix a bug

Now optional & repeated data is tested better for one-level deep data.