z801_useCase_DataRdr_tst.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. import gplx.core.stores.*;
  15. public class z801_useCase_DataRdr_tst {
  16. String raw;
  17. @Test public void Subs_byName() {
  18. raw = String_.Concat
  19. ( "_type:{"
  20. , " item {"
  21. , " point {"
  22. , " x;"
  23. , " y;"
  24. , " }"
  25. , " }"
  26. , "}"
  27. , "item:{"
  28. , " 1 2;"
  29. , "}"
  30. );
  31. rdr = GfmlDataRdr.raw_root_(raw);
  32. subRdr = rdr.Subs_byName_moveFirst("point");
  33. fx_rdr.tst_Atrs(subRdr, kv_("x", "1"), kv_("y", "2"));
  34. }
  35. // @Test
  36. public void Subs_byName3() {
  37. raw = String_.Concat
  38. ( "_type:{"
  39. , " item {"
  40. , " key"
  41. , " point {"
  42. , " x;"
  43. , " y;"
  44. , " }"
  45. , " }"
  46. , "}"
  47. , "abc point=(1 2);"
  48. );
  49. rdr = GfmlDataRdr.raw_root_(raw);
  50. subRdr = rdr.Subs_byName_moveFirst("point");
  51. fx_rdr.tst_Atrs(subRdr, kv_("x", "1"), kv_("y", "2"));
  52. }
  53. Keyval kv_(String key, Object val) {return Keyval_.new_(key, val);}
  54. DataRdr_Fxt fx_rdr = DataRdr_Fxt.Instance;
  55. DataRdr rdr, subRdr;
  56. }
  57. class DataRdr_Fxt {
  58. @gplx.Internal protected DataRdr run_Subs_at(DataRdr rdr, int i) {
  59. DataRdr rv = rdr.Subs();
  60. int count = -1;
  61. while (count++ < i) {
  62. rv.MoveNextPeer();
  63. }
  64. return rv;
  65. }
  66. @gplx.Internal protected void tst_Atrs(DataRdr rdr, Keyval... expdAry) {
  67. Keyval[] actlAry = new Keyval[rdr.FieldCount()];
  68. for (int i = 0; i < actlAry.length; i++)
  69. actlAry[i] = rdr.KeyValAt(i);
  70. Tfds.Eq_ary_str(expdAry, actlAry);
  71. }
  72. public static final DataRdr_Fxt Instance = new DataRdr_Fxt(); DataRdr_Fxt() {}
  73. }