z455_dflts_scope_tst.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. XOWA: the XOWA Offline Wiki Application
  3. Copyright (C) 2012-2017 gnosygnu@gmail.com
  4. XOWA is licensed under the terms of the General Public License (GPL) Version 3,
  5. or alternatively under the terms of the Apache License Version 2.0.
  6. You may use XOWA according to either of these licenses as is most appropriate
  7. for your project on a case-by-case basis.
  8. The terms of each license can be found in the source code repository:
  9. GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
  10. Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
  11. */
  12. package gplx.gfml; import gplx.*;
  13. import org.junit.*;
  14. public class z455_dflts_scope_tst {
  15. @Before public void setup() {
  16. regy = GfmlTypRegy.new_();
  17. GfmlTypeMakr makr = GfmlTypeMakr.new_();
  18. rootPos = GfmlDocPos_.Root.NewDown(0);
  19. GfmlType type = makr.MakeRootType("point", "point", "x", "y").DocPos_(rootPos);
  20. regy.Add(type);
  21. } GfmlDocPos rootPos, currPos; GfmlTypRegy regy;
  22. @Test public void Basic() {
  23. currPos = rootPos.NewDown(0);
  24. tst_FetchOrNullByPos(regy, "point", rootPos, "point", "x", "y");
  25. tst_FetchOrNullByPos(regy, "point", currPos, "point", "x", "y");
  26. List_adp list = List_adp_.New();
  27. list.Add(GfmlDefaultItem.new_("point", "z", GfmlTkn_.raw_("0")));
  28. GfmlDefaultPragma_bgnCmd.ExecList(regy, currPos, list);
  29. tst_FetchOrNullByPos(regy, "point", rootPos, "point", "x", "y");
  30. tst_FetchOrNullByPos(regy, "point", currPos, "point", "x", "y", "z");
  31. }
  32. GfmlType tst_FetchOrNullByPos(GfmlTypRegy regy, String key, GfmlDocPos docPos, String expdTypeKey, String... expdSubs) {
  33. GfmlType actl = regy.FetchOrNull(key, docPos);
  34. Tfds.Eq(expdTypeKey, actl.Key());
  35. String[] actlSubs = new String[actl.SubFlds().Count()];
  36. for (int i = 0; i < actlSubs.length; i++)
  37. actlSubs[i] = actl.SubFlds().Get_at(i).Name();
  38. Tfds.Eq_ary(expdSubs, actlSubs);
  39. return actl;
  40. }
  41. }