Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Output:
- * Soup Mutability: PASS (0 errors, 8 warnings)
- * * tag name is immutable
- * * tag value is immutable
- * * sub soup is mutable
- * * sub soup is mutable by old reference
- * * sub soup is mutable by new reference
- * * old reference is mutable by new reference
- * * new reference is mutable by old reference
- * * references are not equal
- class Test_LData_SoupMutability isclass LTest
- {
- string IsMutable(string subj, string comment, bool mutable)
- {
- if (mutable)
- return subj + " is mutable " + comment;
- return subj + " is immutable " + comment;
- }
- public void Run(LTestContext test)
- {
- Soup sp = Constructors.NewSoup();
- string tagName = "tagName";
- string tagValue = "tagValue";
- sp.SetNamedTag(tagName, tagValue);
- tagName[0] = 'T';
- tagValue[0] = 'T';
- test.Warn(IsMutable("tag name", "", LData.TryGetString(sp, "TagName")));
- test.Warn(IsMutable("tag value", "", LData.LastString() == "TagValue"));
- Soup subSoup = sp.GetNamedSoupAdd("soup");
- subSoup.SetNamedTag("1", 1);
- test.Warn(IsMutable("sub soup", "", sp.GetNamedSoup("soup").GetNamedTagAsInt("1", 0) == 1));
- Soup subSoup2 = sp.GetNamedSoup("soup");
- subSoup.SetNamedTag("2", 1);
- subSoup2.SetNamedTag("3", 1);
- test.Warn(IsMutable("sub soup", "by old reference", sp.GetNamedSoup("soup").GetNamedTagAsInt("2", 1) == 1));
- test.Warn(IsMutable("sub soup", "by new reference", sp.GetNamedSoup("soup").GetNamedTagAsInt("3", 1) == 1));
- test.Warn(IsMutable("old reference", "by new reference", subSoup.GetNamedTagAsInt("3", 1) == 1));
- test.Warn(IsMutable("new reference", "by old reference", subSoup2.GetNamedTagAsInt("2", 1) == 1));
- if (subSoup == subSoup2)
- test.Warn("references are equal");
- else
- test.Warn("references are not equal");
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement